blob: 9f38f2aa3d563029861830cfba561b7226c247c1 [file] [log] [blame]
Chris Lattner57ad3782011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner57ad3782011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattner57ad3782011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregor577f75a2009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall2d887082010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000024#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000025#include "clang/AST/ExprCXX.h"
26#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000027#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000030#include "clang/Sema/Ownership.h"
31#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000032#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000033#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000034#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000035#include <algorithm>
36
37namespace clang {
John McCall781472f2010-08-25 08:40:02 +000038using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000039
Douglas Gregor577f75a2009-08-04 16:50:30 +000040/// \brief A semantic tree transformation that allows one to transform one
41/// abstract syntax tree into another.
42///
Mike Stump1eb44332009-09-09 15:08:12 +000043/// A new tree transformation is defined by creating a new subclass \c X of
44/// \c TreeTransform<X> and then overriding certain operations to provide
45/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000046/// instantiation is implemented as a tree transformation where the
47/// transformation of TemplateTypeParmType nodes involves substituting the
48/// template arguments for their corresponding template parameters; a similar
49/// transformation is performed for non-type template parameters and
50/// template template parameters.
51///
52/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000053/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000054/// override any of the transformation or rebuild operators by providing an
55/// operation with the same signature as the default implementation. The
56/// overridding function should not be virtual.
57///
58/// Semantic tree transformations are split into two stages, either of which
59/// can be replaced by a subclass. The "transform" step transforms an AST node
60/// or the parts of an AST node using the various transformation functions,
61/// then passes the pieces on to the "rebuild" step, which constructs a new AST
62/// node of the appropriate kind from the pieces. The default transformation
63/// routines recursively transform the operands to composite AST nodes (e.g.,
64/// the pointee type of a PointerType node) and, if any of those operand nodes
65/// were changed by the transformation, invokes the rebuild operation to create
66/// a new AST node.
67///
Mike Stump1eb44332009-09-09 15:08:12 +000068/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000069/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000070/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000071/// TransformTemplateName(), or TransformTemplateArgument() with entirely
72/// new implementations.
73///
74/// For more fine-grained transformations, subclasses can replace any of the
75/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000076/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000077/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000078/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// parameters. Additionally, subclasses can override the \c RebuildXXX
80/// functions to control how AST nodes are rebuilt when their operands change.
81/// By default, \c TreeTransform will invoke semantic analysis to rebuild
82/// AST nodes. However, certain other tree transformations (e.g, cloning) may
83/// be able to use more efficient rebuild steps.
84///
85/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000086/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000087/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
88/// operands have not changed (\c AlwaysRebuild()), and customize the
89/// default locations and entity names used for type-checking
90/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000091template<typename Derived>
92class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000093 /// \brief Private RAII object that helps us forget and then re-remember
94 /// the template argument corresponding to a partially-substituted parameter
95 /// pack.
96 class ForgetPartiallySubstitutedPackRAII {
97 Derived &Self;
98 TemplateArgument Old;
99
100 public:
101 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
102 Old = Self.ForgetPartiallySubstitutedPack();
103 }
104
105 ~ForgetPartiallySubstitutedPackRAII() {
106 Self.RememberPartiallySubstitutedPack(Old);
107 }
108 };
109
Douglas Gregor577f75a2009-08-04 16:50:30 +0000110protected:
111 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000112
Mike Stump1eb44332009-09-09 15:08:12 +0000113public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000114 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000115 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000116
Douglas Gregor577f75a2009-08-04 16:50:30 +0000117 /// \brief Retrieves a reference to the derived class.
118 Derived &getDerived() { return static_cast<Derived&>(*this); }
119
120 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000121 const Derived &getDerived() const {
122 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000123 }
124
John McCall60d7b3a2010-08-24 06:29:42 +0000125 static inline ExprResult Owned(Expr *E) { return E; }
126 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000127
Douglas Gregor577f75a2009-08-04 16:50:30 +0000128 /// \brief Retrieves a reference to the semantic analysis object used for
129 /// this tree transform.
130 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000131
Douglas Gregor577f75a2009-08-04 16:50:30 +0000132 /// \brief Whether the transformation should always rebuild AST nodes, even
133 /// if none of the children have changed.
134 ///
135 /// Subclasses may override this function to specify when the transformation
136 /// should rebuild all AST nodes.
137 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000138
Douglas Gregor577f75a2009-08-04 16:50:30 +0000139 /// \brief Returns the location of the entity being transformed, if that
140 /// information was not available elsewhere in the AST.
141 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000142 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000143 /// provide an alternative implementation that provides better location
144 /// information.
145 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000146
Douglas Gregor577f75a2009-08-04 16:50:30 +0000147 /// \brief Returns the name of the entity being transformed, if that
148 /// information was not available elsewhere in the AST.
149 ///
150 /// By default, returns an empty name. Subclasses can provide an alternative
151 /// implementation with a more precise name.
152 DeclarationName getBaseEntity() { return DeclarationName(); }
153
Douglas Gregorb98b1992009-08-11 05:31:07 +0000154 /// \brief Sets the "base" location and entity when that
155 /// information is known based on another transformation.
156 ///
157 /// By default, the source location and entity are ignored. Subclasses can
158 /// override this function to provide a customized implementation.
159 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000160
Douglas Gregorb98b1992009-08-11 05:31:07 +0000161 /// \brief RAII object that temporarily sets the base location and entity
162 /// used for reporting diagnostics in types.
163 class TemporaryBase {
164 TreeTransform &Self;
165 SourceLocation OldLocation;
166 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000167
Douglas Gregorb98b1992009-08-11 05:31:07 +0000168 public:
169 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000170 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000171 OldLocation = Self.getDerived().getBaseLocation();
172 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregorae201f72011-01-25 17:51:48 +0000173
174 if (Location.isValid())
175 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000176 }
Mike Stump1eb44332009-09-09 15:08:12 +0000177
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 ~TemporaryBase() {
179 Self.getDerived().setBase(OldLocation, OldEntity);
180 }
181 };
Mike Stump1eb44332009-09-09 15:08:12 +0000182
183 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000184 /// transformed.
185 ///
186 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000187 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000188 /// not change. For example, template instantiation need not traverse
189 /// non-dependent types.
190 bool AlreadyTransformed(QualType T) {
191 return T.isNull();
192 }
193
Douglas Gregor6eef5192009-12-14 19:27:10 +0000194 /// \brief Determine whether the given call argument should be dropped, e.g.,
195 /// because it is a default argument.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine to
198 /// determine which kinds of call arguments get dropped. By default,
199 /// CXXDefaultArgument nodes are dropped (prior to transformation).
200 bool DropCallArgument(Expr *E) {
201 return E->isDefaultArgument();
202 }
Sean Huntc3021132010-05-05 15:23:54 +0000203
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000204 /// \brief Determine whether we should expand a pack expansion with the
205 /// given set of parameter packs into separate arguments by repeatedly
206 /// transforming the pattern.
207 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000208 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000209 /// Subclasses can override this routine to provide different behavior.
210 ///
211 /// \param EllipsisLoc The location of the ellipsis that identifies the
212 /// pack expansion.
213 ///
214 /// \param PatternRange The source range that covers the entire pattern of
215 /// the pack expansion.
216 ///
217 /// \param Unexpanded The set of unexpanded parameter packs within the
218 /// pattern.
219 ///
220 /// \param NumUnexpanded The number of unexpanded parameter packs in
221 /// \p Unexpanded.
222 ///
223 /// \param ShouldExpand Will be set to \c true if the transformer should
224 /// expand the corresponding pack expansions into separate arguments. When
225 /// set, \c NumExpansions must also be set.
226 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000227 /// \param RetainExpansion Whether the caller should add an unexpanded
228 /// pack expansion after all of the expanded arguments. This is used
229 /// when extending explicitly-specified template argument packs per
230 /// C++0x [temp.arg.explicit]p9.
231 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000232 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000233 /// the expanded form of the corresponding pack expansion. This is both an
234 /// input and an output parameter, which can be set by the caller if the
235 /// number of expansions is known a priori (e.g., due to a prior substitution)
236 /// and will be set by the callee when the number of expansions is known.
237 /// The callee must set this value when \c ShouldExpand is \c true; it may
238 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000239 ///
240 /// \returns true if an error occurred (e.g., because the parameter packs
241 /// are to be instantiated with arguments of different lengths), false
242 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
243 /// must be set.
244 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
245 SourceRange PatternRange,
246 const UnexpandedParameterPack *Unexpanded,
247 unsigned NumUnexpanded,
248 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000249 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000250 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000251 ShouldExpand = false;
252 return false;
253 }
254
Douglas Gregord3731192011-01-10 07:32:04 +0000255 /// \brief "Forget" about the partially-substituted pack template argument,
256 /// when performing an instantiation that must preserve the parameter pack
257 /// use.
258 ///
259 /// This routine is meant to be overridden by the template instantiator.
260 TemplateArgument ForgetPartiallySubstitutedPack() {
261 return TemplateArgument();
262 }
263
264 /// \brief "Remember" the partially-substituted pack template argument
265 /// after performing an instantiation that must preserve the parameter pack
266 /// use.
267 ///
268 /// This routine is meant to be overridden by the template instantiator.
269 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
270
Douglas Gregor12c9c002011-01-07 16:43:16 +0000271 /// \brief Note to the derived class when a function parameter pack is
272 /// being expanded.
273 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
274
Douglas Gregor577f75a2009-08-04 16:50:30 +0000275 /// \brief Transforms the given type into another type.
276 ///
John McCalla2becad2009-10-21 00:40:46 +0000277 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000278 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000279 /// function. This is expensive, but we don't mind, because
280 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000281 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000282 ///
283 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000284 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000285
John McCalla2becad2009-10-21 00:40:46 +0000286 /// \brief Transforms the given type-with-location into a new
287 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000288 ///
John McCalla2becad2009-10-21 00:40:46 +0000289 /// By default, this routine transforms a type by delegating to the
290 /// appropriate TransformXXXType to build a new type. Subclasses
291 /// may override this function (to take over all type
292 /// transformations) or some set of the TransformXXXType functions
293 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000294 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000295
296 /// \brief Transform the given type-with-location into a new
297 /// type, collecting location information in the given builder
298 /// as necessary.
299 ///
John McCall43fed0d2010-11-12 08:19:04 +0000300 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000301
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000302 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000303 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000304 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000305 /// appropriate TransformXXXStmt function to transform a specific kind of
306 /// statement or the TransformExpr() function to transform an expression.
307 /// Subclasses may override this function to transform statements using some
308 /// other mechanism.
309 ///
310 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000311 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000312
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000313 /// \brief Transform the given expression.
314 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000315 /// By default, this routine transforms an expression by delegating to the
316 /// appropriate TransformXXXExpr function to build a new expression.
317 /// Subclasses may override this function to transform expressions using some
318 /// other mechanism.
319 ///
320 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000321 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000322
Douglas Gregoraa165f82011-01-03 19:04:46 +0000323 /// \brief Transform the given list of expressions.
324 ///
325 /// This routine transforms a list of expressions by invoking
326 /// \c TransformExpr() for each subexpression. However, it also provides
327 /// support for variadic templates by expanding any pack expansions (if the
328 /// derived class permits such expansion) along the way. When pack expansions
329 /// are present, the number of outputs may not equal the number of inputs.
330 ///
331 /// \param Inputs The set of expressions to be transformed.
332 ///
333 /// \param NumInputs The number of expressions in \c Inputs.
334 ///
335 /// \param IsCall If \c true, then this transform is being performed on
336 /// function-call arguments, and any arguments that should be dropped, will
337 /// be.
338 ///
339 /// \param Outputs The transformed input expressions will be added to this
340 /// vector.
341 ///
342 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
343 /// due to transformation.
344 ///
345 /// \returns true if an error occurred, false otherwise.
346 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
347 llvm::SmallVectorImpl<Expr *> &Outputs,
348 bool *ArgChanged = 0);
349
Douglas Gregor577f75a2009-08-04 16:50:30 +0000350 /// \brief Transform the given declaration, which is referenced from a type
351 /// or expression.
352 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000353 /// By default, acts as the identity function on declarations. Subclasses
354 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000355 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000356
357 /// \brief Transform the definition of the given declaration.
358 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000359 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000360 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000361 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
362 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000363 }
Mike Stump1eb44332009-09-09 15:08:12 +0000364
Douglas Gregor6cd21982009-10-20 05:58:46 +0000365 /// \brief Transform the given declaration, which was the first part of a
366 /// nested-name-specifier in a member access expression.
367 ///
Sean Huntc3021132010-05-05 15:23:54 +0000368 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000369 /// identifier in a nested-name-specifier of a member access expression, e.g.,
370 /// the \c T in \c x->T::member
371 ///
372 /// By default, invokes TransformDecl() to transform the declaration.
373 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000374 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
375 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000376 }
Sean Huntc3021132010-05-05 15:23:54 +0000377
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000378 /// \brief Transform the given nested-name-specifier with source-location
379 /// information.
380 ///
381 /// By default, transforms all of the types and declarations within the
382 /// nested-name-specifier. Subclasses may override this function to provide
383 /// alternate behavior.
384 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
385 NestedNameSpecifierLoc NNS,
386 QualType ObjectType = QualType(),
387 NamedDecl *FirstQualifierInScope = 0);
388
Douglas Gregor81499bb2009-09-03 22:13:48 +0000389 /// \brief Transform the given declaration name.
390 ///
391 /// By default, transforms the types of conversion function, constructor,
392 /// and destructor names and then (if needed) rebuilds the declaration name.
393 /// Identifiers and selectors are returned unmodified. Sublcasses may
394 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000395 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000396 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000397
Douglas Gregor577f75a2009-08-04 16:50:30 +0000398 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000399 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000400 /// \param SS The nested-name-specifier that qualifies the template
401 /// name. This nested-name-specifier must already have been transformed.
402 ///
403 /// \param Name The template name to transform.
404 ///
405 /// \param NameLoc The source location of the template name.
406 ///
407 /// \param ObjectType If we're translating a template name within a member
408 /// access expression, this is the type of the object whose member template
409 /// is being referenced.
410 ///
411 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
412 /// also refers to a name within the current (lexical) scope, this is the
413 /// declaration it refers to.
414 ///
415 /// By default, transforms the template name by transforming the declarations
416 /// and nested-name-specifiers that occur within the template name.
417 /// Subclasses may override this function to provide alternate behavior.
418 TemplateName TransformTemplateName(CXXScopeSpec &SS,
419 TemplateName Name,
420 SourceLocation NameLoc,
421 QualType ObjectType = QualType(),
422 NamedDecl *FirstQualifierInScope = 0);
423
Douglas Gregor577f75a2009-08-04 16:50:30 +0000424 /// \brief Transform the given template argument.
425 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000426 /// By default, this operation transforms the type, expression, or
427 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000428 /// new template argument from the transformed result. Subclasses may
429 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000430 ///
431 /// Returns true if there was an error.
432 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
433 TemplateArgumentLoc &Output);
434
Douglas Gregorfcc12532010-12-20 17:31:10 +0000435 /// \brief Transform the given set of template arguments.
436 ///
437 /// By default, this operation transforms all of the template arguments
438 /// in the input set using \c TransformTemplateArgument(), and appends
439 /// the transformed arguments to the output list.
440 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000441 /// Note that this overload of \c TransformTemplateArguments() is merely
442 /// a convenience function. Subclasses that wish to override this behavior
443 /// should override the iterator-based member template version.
444 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000445 /// \param Inputs The set of template arguments to be transformed.
446 ///
447 /// \param NumInputs The number of template arguments in \p Inputs.
448 ///
449 /// \param Outputs The set of transformed template arguments output by this
450 /// routine.
451 ///
452 /// Returns true if an error occurred.
453 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
454 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000455 TemplateArgumentListInfo &Outputs) {
456 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
457 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000458
459 /// \brief Transform the given set of template arguments.
460 ///
461 /// By default, this operation transforms all of the template arguments
462 /// in the input set using \c TransformTemplateArgument(), and appends
463 /// the transformed arguments to the output list.
464 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000465 /// \param First An iterator to the first template argument.
466 ///
467 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000468 ///
469 /// \param Outputs The set of transformed template arguments output by this
470 /// routine.
471 ///
472 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000473 template<typename InputIterator>
474 bool TransformTemplateArguments(InputIterator First,
475 InputIterator Last,
476 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000477
John McCall833ca992009-10-29 08:12:44 +0000478 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
479 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
480 TemplateArgumentLoc &ArgLoc);
481
John McCalla93c9342009-12-07 02:54:59 +0000482 /// \brief Fakes up a TypeSourceInfo for a type.
483 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
484 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000485 getDerived().getBaseLocation());
486 }
Mike Stump1eb44332009-09-09 15:08:12 +0000487
John McCalla2becad2009-10-21 00:40:46 +0000488#define ABSTRACT_TYPELOC(CLASS, PARENT)
489#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000490 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000491#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000492
John Wiegley28bbe4b2011-04-28 01:08:34 +0000493 StmtResult
494 TransformSEHHandler(Stmt *Handler);
495
John McCall43fed0d2010-11-12 08:19:04 +0000496 QualType
497 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
498 TemplateSpecializationTypeLoc TL,
499 TemplateName Template);
500
501 QualType
502 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
503 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000504 TemplateName Template,
505 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000506
507 QualType
508 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000509 DependentTemplateSpecializationTypeLoc TL,
510 NestedNameSpecifierLoc QualifierLoc);
511
John McCall21ef0fa2010-03-11 09:03:00 +0000512 /// \brief Transforms the parameters of a function type into the
513 /// given vectors.
514 ///
515 /// The result vectors should be kept in sync; null entries in the
516 /// variables vector are acceptable.
517 ///
518 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000519 bool TransformFunctionTypeParams(SourceLocation Loc,
520 ParmVarDecl **Params, unsigned NumParams,
521 const QualType *ParamTypes,
John McCall21ef0fa2010-03-11 09:03:00 +0000522 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregora009b592011-01-07 00:20:55 +0000523 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000524
525 /// \brief Transforms a single function-type parameter. Return null
526 /// on error.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000527 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
528 llvm::Optional<unsigned> NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +0000529
John McCall43fed0d2010-11-12 08:19:04 +0000530 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000531
John McCall60d7b3a2010-08-24 06:29:42 +0000532 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
533 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000534
Douglas Gregor43959a92009-08-20 07:17:43 +0000535#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000536 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000537#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000538 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000539#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000540#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000541
Douglas Gregor577f75a2009-08-04 16:50:30 +0000542 /// \brief Build a new pointer type given its pointee type.
543 ///
544 /// By default, performs semantic analysis when building the pointer type.
545 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000546 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000547
548 /// \brief Build a new block pointer type given its pointee type.
549 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000550 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000551 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000552 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000553
John McCall85737a72009-10-30 00:06:24 +0000554 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000555 ///
John McCall85737a72009-10-30 00:06:24 +0000556 /// By default, performs semantic analysis when building the
557 /// reference type. Subclasses may override this routine to provide
558 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000559 ///
John McCall85737a72009-10-30 00:06:24 +0000560 /// \param LValue whether the type was written with an lvalue sigil
561 /// or an rvalue sigil.
562 QualType RebuildReferenceType(QualType ReferentType,
563 bool LValue,
564 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000565
Douglas Gregor577f75a2009-08-04 16:50:30 +0000566 /// \brief Build a new member pointer type given the pointee type and the
567 /// class type it refers into.
568 ///
569 /// By default, performs semantic analysis when building the member pointer
570 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000571 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
572 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000573
Douglas Gregor577f75a2009-08-04 16:50:30 +0000574 /// \brief Build a new array type given the element type, size
575 /// modifier, size of the array (if known), size expression, and index type
576 /// qualifiers.
577 ///
578 /// By default, performs semantic analysis when building the array type.
579 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000580 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000581 QualType RebuildArrayType(QualType ElementType,
582 ArrayType::ArraySizeModifier SizeMod,
583 const llvm::APInt *Size,
584 Expr *SizeExpr,
585 unsigned IndexTypeQuals,
586 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000587
Douglas Gregor577f75a2009-08-04 16:50:30 +0000588 /// \brief Build a new constant array type given the element type, size
589 /// modifier, (known) size of the array, 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 RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000594 ArrayType::ArraySizeModifier SizeMod,
595 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000596 unsigned IndexTypeQuals,
597 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000598
Douglas Gregor577f75a2009-08-04 16:50:30 +0000599 /// \brief Build a new incomplete array type given the element type, size
600 /// modifier, and index type qualifiers.
601 ///
602 /// By default, performs semantic analysis when building the array type.
603 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000604 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000605 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000606 unsigned IndexTypeQuals,
607 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000608
Mike Stump1eb44332009-09-09 15:08:12 +0000609 /// \brief Build a new variable-length 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 RebuildVariableArrayType(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
Mike Stump1eb44332009-09-09 15:08:12 +0000620 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621 /// size modifier, size expression, and index type qualifiers.
622 ///
623 /// By default, performs semantic analysis when building the array type.
624 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000625 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000626 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000627 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000628 unsigned IndexTypeQuals,
629 SourceRange BracketsRange);
630
631 /// \brief Build a new vector type given the element type and
632 /// number of elements.
633 ///
634 /// By default, performs semantic analysis when building the vector type.
635 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000636 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000637 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000638
Douglas Gregor577f75a2009-08-04 16:50:30 +0000639 /// \brief Build a new extended vector type given the element type and
640 /// number of elements.
641 ///
642 /// By default, performs semantic analysis when building the vector type.
643 /// Subclasses may override this routine to provide different behavior.
644 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
645 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000646
647 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000648 /// given the element type and number of elements.
649 ///
650 /// By default, performs semantic analysis when building the vector type.
651 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000652 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000653 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000655
Douglas Gregor577f75a2009-08-04 16:50:30 +0000656 /// \brief Build a new function type.
657 ///
658 /// By default, performs semantic analysis when building the function type.
659 /// Subclasses may override this routine to provide different behavior.
660 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000661 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000662 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000663 bool Variadic, unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000664 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000665 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000666
John McCalla2becad2009-10-21 00:40:46 +0000667 /// \brief Build a new unprototyped function type.
668 QualType RebuildFunctionNoProtoType(QualType ResultType);
669
John McCalled976492009-12-04 22:46:56 +0000670 /// \brief Rebuild an unresolved typename type, given the decl that
671 /// the UnresolvedUsingTypenameDecl was transformed to.
672 QualType RebuildUnresolvedUsingType(Decl *D);
673
Douglas Gregor577f75a2009-08-04 16:50:30 +0000674 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000675 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000676 return SemaRef.Context.getTypeDeclType(Typedef);
677 }
678
679 /// \brief Build a new class/struct/union type.
680 QualType RebuildRecordType(RecordDecl *Record) {
681 return SemaRef.Context.getTypeDeclType(Record);
682 }
683
684 /// \brief Build a new Enum type.
685 QualType RebuildEnumType(EnumDecl *Enum) {
686 return SemaRef.Context.getTypeDeclType(Enum);
687 }
John McCall7da24312009-09-05 00:15:47 +0000688
Mike Stump1eb44332009-09-09 15:08:12 +0000689 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000690 ///
691 /// By default, performs semantic analysis when building the typeof type.
692 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000693 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000694
Mike Stump1eb44332009-09-09 15:08:12 +0000695 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000696 ///
697 /// By default, builds a new TypeOfType with the given underlying type.
698 QualType RebuildTypeOfType(QualType Underlying);
699
Mike Stump1eb44332009-09-09 15:08:12 +0000700 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000701 ///
702 /// By default, performs semantic analysis when building the decltype type.
703 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000704 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000705
Richard Smith34b41d92011-02-20 03:19:35 +0000706 /// \brief Build a new C++0x auto type.
707 ///
708 /// By default, builds a new AutoType with the given deduced type.
709 QualType RebuildAutoType(QualType Deduced) {
710 return SemaRef.Context.getAutoType(Deduced);
711 }
712
Douglas Gregor577f75a2009-08-04 16:50:30 +0000713 /// \brief Build a new template specialization type.
714 ///
715 /// By default, performs semantic analysis when building the template
716 /// specialization type. Subclasses may override this routine to provide
717 /// different behavior.
718 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000719 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000720 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000721
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000722 /// \brief Build a new parenthesized type.
723 ///
724 /// By default, builds a new ParenType type from the inner type.
725 /// Subclasses may override this routine to provide different behavior.
726 QualType RebuildParenType(QualType InnerType) {
727 return SemaRef.Context.getParenType(InnerType);
728 }
729
Douglas Gregor577f75a2009-08-04 16:50:30 +0000730 /// \brief Build a new qualified name type.
731 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000732 /// By default, builds a new ElaboratedType type from the keyword,
733 /// the nested-name-specifier and the named type.
734 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000735 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
736 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000737 NestedNameSpecifierLoc QualifierLoc,
738 QualType Named) {
739 return SemaRef.Context.getElaboratedType(Keyword,
740 QualifierLoc.getNestedNameSpecifier(),
741 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000742 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000743
744 /// \brief Build a new typename type that refers to a template-id.
745 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000746 /// By default, builds a new DependentNameType type from the
747 /// nested-name-specifier and the given type. Subclasses may override
748 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000749 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000750 ElaboratedTypeKeyword Keyword,
751 NestedNameSpecifierLoc QualifierLoc,
752 const IdentifierInfo *Name,
753 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000754 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000755 // Rebuild the template name.
756 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000757 CXXScopeSpec SS;
758 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000759 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000760 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000761
762 if (InstName.isNull())
763 return QualType();
764
765 // If it's still dependent, make a dependent specialization.
766 if (InstName.getAsDependentTemplateName())
767 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
768 QualifierLoc.getNestedNameSpecifier(),
769 Name,
770 Args);
771
772 // Otherwise, make an elaborated type wrapping a non-dependent
773 // specialization.
774 QualType T =
775 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
776 if (T.isNull()) return QualType();
777
778 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
779 return T;
780
781 return SemaRef.Context.getElaboratedType(Keyword,
782 QualifierLoc.getNestedNameSpecifier(),
783 T);
784 }
785
Douglas Gregor577f75a2009-08-04 16:50:30 +0000786 /// \brief Build a new typename type that refers to an identifier.
787 ///
788 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000789 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000790 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000791 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000792 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000793 NestedNameSpecifierLoc QualifierLoc,
794 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000795 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000796 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000797 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000798
Douglas Gregor2494dd02011-03-01 01:34:45 +0000799 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000800 // If the name is still dependent, just build a new dependent name type.
801 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000802 return SemaRef.Context.getDependentNameType(Keyword,
803 QualifierLoc.getNestedNameSpecifier(),
804 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000805 }
806
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000807 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000808 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000809 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000810
811 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
812
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000813 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000814 // into a non-dependent elaborated-type-specifier. Find the tag we're
815 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000816 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000817 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
818 if (!DC)
819 return QualType();
820
John McCall56138762010-05-27 06:40:31 +0000821 if (SemaRef.RequireCompleteDeclContext(SS, DC))
822 return QualType();
823
Douglas Gregor40336422010-03-31 22:19:08 +0000824 TagDecl *Tag = 0;
825 SemaRef.LookupQualifiedName(Result, DC);
826 switch (Result.getResultKind()) {
827 case LookupResult::NotFound:
828 case LookupResult::NotFoundInCurrentInstantiation:
829 break;
Sean Huntc3021132010-05-05 15:23:54 +0000830
Douglas Gregor40336422010-03-31 22:19:08 +0000831 case LookupResult::Found:
832 Tag = Result.getAsSingle<TagDecl>();
833 break;
Sean Huntc3021132010-05-05 15:23:54 +0000834
Douglas Gregor40336422010-03-31 22:19:08 +0000835 case LookupResult::FoundOverloaded:
836 case LookupResult::FoundUnresolvedValue:
837 llvm_unreachable("Tag lookup cannot find non-tags");
838 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000839
Douglas Gregor40336422010-03-31 22:19:08 +0000840 case LookupResult::Ambiguous:
841 // Let the LookupResult structure handle ambiguities.
842 return QualType();
843 }
844
845 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000846 // Check where the name exists but isn't a tag type and use that to emit
847 // better diagnostics.
848 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
849 SemaRef.LookupQualifiedName(Result, DC);
850 switch (Result.getResultKind()) {
851 case LookupResult::Found:
852 case LookupResult::FoundOverloaded:
853 case LookupResult::FoundUnresolvedValue: {
854 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
855 unsigned Kind = 0;
856 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000857 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
858 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000859 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
860 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
861 break;
862 }
863 default:
864 // FIXME: Would be nice to highlight just the source range.
865 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
866 << Kind << Id << DC;
867 break;
868 }
Douglas Gregor40336422010-03-31 22:19:08 +0000869 return QualType();
870 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000871
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000872 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
873 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000874 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
875 return QualType();
876 }
877
878 // Build the elaborated-type-specifier type.
879 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000880 return SemaRef.Context.getElaboratedType(Keyword,
881 QualifierLoc.getNestedNameSpecifier(),
882 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000883 }
Mike Stump1eb44332009-09-09 15:08:12 +0000884
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000885 /// \brief Build a new pack expansion type.
886 ///
887 /// By default, builds a new PackExpansionType type from the given pattern.
888 /// Subclasses may override this routine to provide different behavior.
889 QualType RebuildPackExpansionType(QualType Pattern,
890 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000891 SourceLocation EllipsisLoc,
892 llvm::Optional<unsigned> NumExpansions) {
893 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
894 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000895 }
896
Douglas Gregord1067e52009-08-06 06:41:21 +0000897 /// \brief Build a new template name given a nested name specifier, a flag
898 /// indicating whether the "template" keyword was provided, and the template
899 /// that the template name refers to.
900 ///
901 /// By default, builds the new template name directly. Subclasses may override
902 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000903 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000904 bool TemplateKW,
905 TemplateDecl *Template);
906
Douglas Gregord1067e52009-08-06 06:41:21 +0000907 /// \brief Build a new template name given a nested name specifier and the
908 /// name that is referred to as a template.
909 ///
910 /// By default, performs semantic analysis to determine whether the name can
911 /// be resolved to a specific template, then builds the appropriate kind of
912 /// template name. Subclasses may override this routine to provide different
913 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000914 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
915 const IdentifierInfo &Name,
916 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000917 QualType ObjectType,
918 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000919
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000920 /// \brief Build a new template name given a nested name specifier and the
921 /// overloaded operator name that is referred to as a template.
922 ///
923 /// By default, performs semantic analysis to determine whether the name can
924 /// be resolved to a specific template, then builds the appropriate kind of
925 /// template name. Subclasses may override this routine to provide different
926 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000927 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000928 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000929 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000930 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000931
932 /// \brief Build a new template name given a template template parameter pack
933 /// and the
934 ///
935 /// By default, performs semantic analysis to determine whether the name can
936 /// be resolved to a specific template, then builds the appropriate kind of
937 /// template name. Subclasses may override this routine to provide different
938 /// behavior.
939 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
940 const TemplateArgument &ArgPack) {
941 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
942 }
943
Douglas Gregor43959a92009-08-20 07:17:43 +0000944 /// \brief Build a new compound statement.
945 ///
946 /// By default, performs semantic analysis to build the new statement.
947 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000948 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000949 MultiStmtArg Statements,
950 SourceLocation RBraceLoc,
951 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000952 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000953 IsStmtExpr);
954 }
955
956 /// \brief Build a new case statement.
957 ///
958 /// By default, performs semantic analysis to build the new statement.
959 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000960 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000961 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000962 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000963 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000964 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000965 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000966 ColonLoc);
967 }
Mike Stump1eb44332009-09-09 15:08:12 +0000968
Douglas Gregor43959a92009-08-20 07:17:43 +0000969 /// \brief Attach the body to a new case statement.
970 ///
971 /// By default, performs semantic analysis to build the new statement.
972 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000973 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000974 getSema().ActOnCaseStmtBody(S, Body);
975 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000976 }
Mike Stump1eb44332009-09-09 15:08:12 +0000977
Douglas Gregor43959a92009-08-20 07:17:43 +0000978 /// \brief Build a new default statement.
979 ///
980 /// By default, performs semantic analysis to build the new statement.
981 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000982 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000983 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000984 Stmt *SubStmt) {
985 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000986 /*CurScope=*/0);
987 }
Mike Stump1eb44332009-09-09 15:08:12 +0000988
Douglas Gregor43959a92009-08-20 07:17:43 +0000989 /// \brief Build a new label statement.
990 ///
991 /// By default, performs semantic analysis to build the new statement.
992 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +0000993 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
994 SourceLocation ColonLoc, Stmt *SubStmt) {
995 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
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 "if" 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 RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001003 VarDecl *CondVar, Stmt *Then,
1004 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001005 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001006 }
Mike Stump1eb44332009-09-09 15:08:12 +00001007
Douglas Gregor43959a92009-08-20 07:17:43 +00001008 /// \brief Start building a new switch statement.
1009 ///
1010 /// By default, performs semantic analysis to build the new statement.
1011 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001012 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001013 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001014 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001015 CondVar);
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 Attach the body to the switch 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 RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001023 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001024 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001025 }
1026
1027 /// \brief Build a new while statement.
1028 ///
1029 /// By default, performs semantic analysis to build the new statement.
1030 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001031 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1032 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001033 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001034 }
Mike Stump1eb44332009-09-09 15:08:12 +00001035
Douglas Gregor43959a92009-08-20 07:17:43 +00001036 /// \brief Build a new do-while statement.
1037 ///
1038 /// By default, performs semantic analysis to build the new statement.
1039 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001040 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001041 SourceLocation WhileLoc, SourceLocation LParenLoc,
1042 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001043 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1044 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001045 }
1046
1047 /// \brief Build a new for statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001051 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1052 Stmt *Init, Sema::FullExprArg Cond,
1053 VarDecl *CondVar, Sema::FullExprArg Inc,
1054 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001055 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001056 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001057 }
Mike Stump1eb44332009-09-09 15:08:12 +00001058
Douglas Gregor43959a92009-08-20 07:17:43 +00001059 /// \brief Build a new goto statement.
1060 ///
1061 /// By default, performs semantic analysis to build the new statement.
1062 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001063 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1064 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001065 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001066 }
1067
1068 /// \brief Build a new indirect goto statement.
1069 ///
1070 /// By default, performs semantic analysis to build the new statement.
1071 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001072 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001073 SourceLocation StarLoc,
1074 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001075 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001076 }
Mike Stump1eb44332009-09-09 15:08:12 +00001077
Douglas Gregor43959a92009-08-20 07:17:43 +00001078 /// \brief Build a new return statement.
1079 ///
1080 /// By default, performs semantic analysis to build the new statement.
1081 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001082 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001083 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001084 }
Mike Stump1eb44332009-09-09 15:08:12 +00001085
Douglas Gregor43959a92009-08-20 07:17:43 +00001086 /// \brief Build a new declaration statement.
1087 ///
1088 /// By default, performs semantic analysis to build the new statement.
1089 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001090 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001091 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001092 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001093 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1094 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001095 }
Mike Stump1eb44332009-09-09 15:08:12 +00001096
Anders Carlsson703e3942010-01-24 05:50:09 +00001097 /// \brief Build a new inline asm statement.
1098 ///
1099 /// By default, performs semantic analysis to build the new statement.
1100 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001101 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001102 bool IsSimple,
1103 bool IsVolatile,
1104 unsigned NumOutputs,
1105 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001106 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001107 MultiExprArg Constraints,
1108 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001109 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001110 MultiExprArg Clobbers,
1111 SourceLocation RParenLoc,
1112 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001113 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001114 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001115 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001116 RParenLoc, MSAsm);
1117 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001118
1119 /// \brief Build a new Objective-C @try statement.
1120 ///
1121 /// By default, performs semantic analysis to build the new statement.
1122 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001123 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001124 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001125 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001126 Stmt *Finally) {
1127 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1128 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001129 }
1130
Douglas Gregorbe270a02010-04-26 17:57:08 +00001131 /// \brief Rebuild an Objective-C exception declaration.
1132 ///
1133 /// By default, performs semantic analysis to build the new declaration.
1134 /// Subclasses may override this routine to provide different behavior.
1135 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1136 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001137 return getSema().BuildObjCExceptionDecl(TInfo, T,
1138 ExceptionDecl->getInnerLocStart(),
1139 ExceptionDecl->getLocation(),
1140 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001141 }
Sean Huntc3021132010-05-05 15:23:54 +00001142
Douglas Gregorbe270a02010-04-26 17:57:08 +00001143 /// \brief Build a new Objective-C @catch statement.
1144 ///
1145 /// By default, performs semantic analysis to build the new statement.
1146 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001147 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001148 SourceLocation RParenLoc,
1149 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001150 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001151 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001152 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001153 }
Sean Huntc3021132010-05-05 15:23:54 +00001154
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001155 /// \brief Build a new Objective-C @finally statement.
1156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001159 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001160 Stmt *Body) {
1161 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001162 }
Sean Huntc3021132010-05-05 15:23:54 +00001163
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001164 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001165 ///
1166 /// By default, performs semantic analysis to build the new statement.
1167 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001168 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001169 Expr *Operand) {
1170 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001171 }
Sean Huntc3021132010-05-05 15:23:54 +00001172
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001173 /// \brief Build a new Objective-C @synchronized statement.
1174 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001175 /// By default, performs semantic analysis to build the new statement.
1176 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001177 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001178 Expr *Object,
1179 Stmt *Body) {
1180 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1181 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001182 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001183
1184 /// \brief Build a new Objective-C fast enumeration statement.
1185 ///
1186 /// By default, performs semantic analysis to build the new statement.
1187 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001188 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001189 SourceLocation LParenLoc,
1190 Stmt *Element,
1191 Expr *Collection,
1192 SourceLocation RParenLoc,
1193 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001194 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001195 Element,
1196 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001197 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001198 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001199 }
Sean Huntc3021132010-05-05 15:23:54 +00001200
Douglas Gregor43959a92009-08-20 07:17:43 +00001201 /// \brief Build a new C++ exception declaration.
1202 ///
1203 /// By default, performs semantic analysis to build the new decaration.
1204 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001205 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001206 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001207 SourceLocation StartLoc,
1208 SourceLocation IdLoc,
1209 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001210 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1211 StartLoc, IdLoc, Id);
1212 if (Var)
1213 getSema().CurContext->addDecl(Var);
1214 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001215 }
1216
1217 /// \brief Build a new C++ catch statement.
1218 ///
1219 /// By default, performs semantic analysis to build the new statement.
1220 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001221 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001222 VarDecl *ExceptionDecl,
1223 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001224 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1225 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001226 }
Mike Stump1eb44332009-09-09 15:08:12 +00001227
Douglas Gregor43959a92009-08-20 07:17:43 +00001228 /// \brief Build a new C++ try statement.
1229 ///
1230 /// By default, performs semantic analysis to build the new statement.
1231 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001232 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001233 Stmt *TryBlock,
1234 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001235 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001236 }
Mike Stump1eb44332009-09-09 15:08:12 +00001237
Richard Smithad762fc2011-04-14 22:09:26 +00001238 /// \brief Build a new C++0x range-based for statement.
1239 ///
1240 /// By default, performs semantic analysis to build the new statement.
1241 /// Subclasses may override this routine to provide different behavior.
1242 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1243 SourceLocation ColonLoc,
1244 Stmt *Range, Stmt *BeginEnd,
1245 Expr *Cond, Expr *Inc,
1246 Stmt *LoopVar,
1247 SourceLocation RParenLoc) {
1248 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1249 Cond, Inc, LoopVar, RParenLoc);
1250 }
1251
1252 /// \brief Attach body to a C++0x range-based for statement.
1253 ///
1254 /// By default, performs semantic analysis to finish the new statement.
1255 /// Subclasses may override this routine to provide different behavior.
1256 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1257 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1258 }
1259
John Wiegley28bbe4b2011-04-28 01:08:34 +00001260 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1261 SourceLocation TryLoc,
1262 Stmt *TryBlock,
1263 Stmt *Handler) {
1264 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1265 }
1266
1267 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1268 Expr *FilterExpr,
1269 Stmt *Block) {
1270 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1271 }
1272
1273 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1274 Stmt *Block) {
1275 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1276 }
1277
Douglas Gregorb98b1992009-08-11 05:31:07 +00001278 /// \brief Build a new expression that references a declaration.
1279 ///
1280 /// By default, performs semantic analysis to build the new expression.
1281 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001282 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001283 LookupResult &R,
1284 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001285 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1286 }
1287
1288
1289 /// \brief Build a new expression that references a declaration.
1290 ///
1291 /// By default, performs semantic analysis to build the new expression.
1292 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001293 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001294 ValueDecl *VD,
1295 const DeclarationNameInfo &NameInfo,
1296 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001297 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001298 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001299
1300 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001301
1302 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001303 }
Mike Stump1eb44332009-09-09 15:08:12 +00001304
Douglas Gregorb98b1992009-08-11 05:31:07 +00001305 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001306 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001307 /// By default, performs semantic analysis to build the new expression.
1308 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001309 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001310 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001311 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001312 }
1313
Douglas Gregora71d8192009-09-04 17:36:40 +00001314 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001315 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001316 /// By default, performs semantic analysis to build the new expression.
1317 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001318 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001319 SourceLocation OperatorLoc,
1320 bool isArrow,
1321 CXXScopeSpec &SS,
1322 TypeSourceInfo *ScopeType,
1323 SourceLocation CCLoc,
1324 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001325 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001326
Douglas Gregorb98b1992009-08-11 05:31:07 +00001327 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001328 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001329 /// By default, performs semantic analysis to build the new expression.
1330 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001331 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001332 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001333 Expr *SubExpr) {
1334 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001335 }
Mike Stump1eb44332009-09-09 15:08:12 +00001336
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001337 /// \brief Build a new builtin offsetof expression.
1338 ///
1339 /// By default, performs semantic analysis to build the new expression.
1340 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001341 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001342 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001343 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001344 unsigned NumComponents,
1345 SourceLocation RParenLoc) {
1346 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1347 NumComponents, RParenLoc);
1348 }
Sean Huntc3021132010-05-05 15:23:54 +00001349
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001350 /// \brief Build a new sizeof, alignof or vec_step expression with a
1351 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001352 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001353 /// By default, performs semantic analysis to build the new expression.
1354 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001355 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1356 SourceLocation OpLoc,
1357 UnaryExprOrTypeTrait ExprKind,
1358 SourceRange R) {
1359 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001360 }
1361
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001362 /// \brief Build a new sizeof, alignof or vec step expression with an
1363 /// expression argument.
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.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001367 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1368 UnaryExprOrTypeTrait ExprKind,
1369 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001370 ExprResult Result
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001371 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001372 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001373 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001374
Douglas Gregorb98b1992009-08-11 05:31:07 +00001375 return move(Result);
1376 }
Mike Stump1eb44332009-09-09 15:08:12 +00001377
Douglas Gregorb98b1992009-08-11 05:31:07 +00001378 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001379 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001380 /// By default, performs semantic analysis to build the new expression.
1381 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001382 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001383 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001384 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001385 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001386 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1387 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001388 RBracketLoc);
1389 }
1390
1391 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001392 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001393 /// By default, performs semantic analysis to build the new expression.
1394 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001395 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001396 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001397 SourceLocation RParenLoc,
1398 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001399 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001400 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001401 }
1402
1403 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001404 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001405 /// By default, performs semantic analysis to build the new expression.
1406 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001407 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001408 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001409 NestedNameSpecifierLoc QualifierLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001410 const DeclarationNameInfo &MemberNameInfo,
1411 ValueDecl *Member,
1412 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001413 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001414 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001415 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001416 // We have a reference to an unnamed field. This is always the
1417 // base of an anonymous struct/union member access, i.e. the
1418 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001419 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001420 assert(Member->getType()->isRecordType() &&
1421 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001422
John Wiegley429bb272011-04-08 18:41:53 +00001423 ExprResult BaseResult =
1424 getSema().PerformObjectMemberConversion(Base,
1425 QualifierLoc.getNestedNameSpecifier(),
1426 FoundDecl, Member);
1427 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001428 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001429 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001430 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001431 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001432 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001433 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001434 cast<FieldDecl>(Member)->getType(),
1435 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001436 return getSema().Owned(ME);
1437 }
Mike Stump1eb44332009-09-09 15:08:12 +00001438
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001439 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001440 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001441
John Wiegley429bb272011-04-08 18:41:53 +00001442 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1443 if (BaseResult.isInvalid())
1444 return ExprError();
1445 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001446 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001447
John McCall6bb80172010-03-30 21:47:33 +00001448 // FIXME: this involves duplicating earlier analysis in a lot of
1449 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001450 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001451 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001452 R.resolveKind();
1453
John McCall9ae2f072010-08-23 23:25:46 +00001454 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001455 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001456 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001457 }
Mike Stump1eb44332009-09-09 15:08:12 +00001458
Douglas Gregorb98b1992009-08-11 05:31:07 +00001459 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001460 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001461 /// By default, performs semantic analysis to build the new expression.
1462 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001463 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001464 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001465 Expr *LHS, Expr *RHS) {
1466 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001467 }
1468
1469 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001470 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001471 /// By default, performs semantic analysis to build the new expression.
1472 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001473 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001474 SourceLocation QuestionLoc,
1475 Expr *LHS,
1476 SourceLocation ColonLoc,
1477 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001478 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1479 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 }
1481
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001483 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001484 /// By default, performs semantic analysis to build the new expression.
1485 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001486 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001487 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001488 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001489 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001490 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001491 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 }
Mike Stump1eb44332009-09-09 15:08:12 +00001493
Douglas Gregorb98b1992009-08-11 05:31:07 +00001494 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001495 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001496 /// By default, performs semantic analysis to build the new expression.
1497 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001498 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001499 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001501 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001502 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001503 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 }
Mike Stump1eb44332009-09-09 15:08:12 +00001505
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001507 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001508 /// By default, performs semantic analysis to build the new expression.
1509 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001510 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001511 SourceLocation OpLoc,
1512 SourceLocation AccessorLoc,
1513 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001514
John McCall129e2df2009-11-30 22:42:35 +00001515 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001516 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001517 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001518 OpLoc, /*IsArrow*/ false,
1519 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001520 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001521 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001522 }
Mike Stump1eb44332009-09-09 15:08:12 +00001523
Douglas Gregorb98b1992009-08-11 05:31:07 +00001524 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001525 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001526 /// By default, performs semantic analysis to build the new expression.
1527 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001528 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001529 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001530 SourceLocation RBraceLoc,
1531 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001532 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001533 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1534 if (Result.isInvalid() || ResultTy->isDependentType())
1535 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001536
Douglas Gregore48319a2009-11-09 17:16:50 +00001537 // Patch in the result type we were given, which may have been computed
1538 // when the initial InitListExpr was built.
1539 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1540 ILE->setType(ResultTy);
1541 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001542 }
Mike Stump1eb44332009-09-09 15:08:12 +00001543
Douglas Gregorb98b1992009-08-11 05:31:07 +00001544 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001545 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001546 /// By default, performs semantic analysis to build the new expression.
1547 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001548 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001549 MultiExprArg ArrayExprs,
1550 SourceLocation EqualOrColonLoc,
1551 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001552 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001553 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001554 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001555 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001556 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001557 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001558
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 ArrayExprs.release();
1560 return move(Result);
1561 }
Mike Stump1eb44332009-09-09 15:08:12 +00001562
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001564 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 /// By default, builds the implicit value initialization without performing
1566 /// any semantic analysis. Subclasses may override this routine to provide
1567 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001568 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1570 }
Mike Stump1eb44332009-09-09 15:08:12 +00001571
Douglas Gregorb98b1992009-08-11 05:31:07 +00001572 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001573 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001574 /// By default, performs semantic analysis to build the new expression.
1575 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001576 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001577 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001578 SourceLocation RParenLoc) {
1579 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001580 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001581 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 }
1583
1584 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001585 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 /// By default, performs semantic analysis to build the new expression.
1587 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001588 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 MultiExprArg SubExprs,
1590 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001591 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001592 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 }
Mike Stump1eb44332009-09-09 15:08:12 +00001594
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001596 ///
1597 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001598 /// rather than attempting to map the label statement itself.
1599 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001600 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001601 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001602 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 }
Mike Stump1eb44332009-09-09 15:08:12 +00001604
Douglas Gregorb98b1992009-08-11 05:31:07 +00001605 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001606 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 /// By default, performs semantic analysis to build the new expression.
1608 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001609 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001610 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001611 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001612 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001613 }
Mike Stump1eb44332009-09-09 15:08:12 +00001614
Douglas Gregorb98b1992009-08-11 05:31:07 +00001615 /// \brief Build a new __builtin_choose_expr expression.
1616 ///
1617 /// By default, performs semantic analysis to build the new expression.
1618 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001619 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001620 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001621 SourceLocation RParenLoc) {
1622 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001623 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 RParenLoc);
1625 }
Mike Stump1eb44332009-09-09 15:08:12 +00001626
Peter Collingbournef111d932011-04-15 00:35:48 +00001627 /// \brief Build a new generic selection expression.
1628 ///
1629 /// By default, performs semantic analysis to build the new expression.
1630 /// Subclasses may override this routine to provide different behavior.
1631 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1632 SourceLocation DefaultLoc,
1633 SourceLocation RParenLoc,
1634 Expr *ControllingExpr,
1635 TypeSourceInfo **Types,
1636 Expr **Exprs,
1637 unsigned NumAssocs) {
1638 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1639 ControllingExpr, Types, Exprs,
1640 NumAssocs);
1641 }
1642
Douglas Gregorb98b1992009-08-11 05:31:07 +00001643 /// \brief Build a new overloaded operator call expression.
1644 ///
1645 /// By default, performs semantic analysis to build the new expression.
1646 /// The semantic analysis provides the behavior of template instantiation,
1647 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001648 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 /// argument-dependent lookup, etc. Subclasses may override this routine to
1650 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001651 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001653 Expr *Callee,
1654 Expr *First,
1655 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001656
1657 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 /// reinterpret_cast.
1659 ///
1660 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001661 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001663 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 Stmt::StmtClass Class,
1665 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001666 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 SourceLocation RAngleLoc,
1668 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001669 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 SourceLocation RParenLoc) {
1671 switch (Class) {
1672 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001673 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001674 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001675 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676
1677 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001678 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001679 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001680 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001681
Douglas Gregorb98b1992009-08-11 05:31:07 +00001682 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001683 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001684 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001685 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001687
Douglas Gregorb98b1992009-08-11 05:31:07 +00001688 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001689 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001690 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001691 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001692
Douglas Gregorb98b1992009-08-11 05:31:07 +00001693 default:
1694 assert(false && "Invalid C++ named cast");
1695 break;
1696 }
Mike Stump1eb44332009-09-09 15:08:12 +00001697
John McCallf312b1e2010-08-26 23:41:50 +00001698 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001699 }
Mike Stump1eb44332009-09-09 15:08:12 +00001700
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 /// \brief Build a new C++ static_cast expression.
1702 ///
1703 /// By default, performs semantic analysis to build the new expression.
1704 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001705 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001707 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 SourceLocation RAngleLoc,
1709 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001710 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001712 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001713 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001714 SourceRange(LAngleLoc, RAngleLoc),
1715 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 }
1717
1718 /// \brief Build a new C++ dynamic_cast expression.
1719 ///
1720 /// By default, performs semantic analysis to build the new expression.
1721 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001722 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001724 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 SourceLocation RAngleLoc,
1726 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001727 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001728 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001729 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001730 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001731 SourceRange(LAngleLoc, RAngleLoc),
1732 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001733 }
1734
1735 /// \brief Build a new C++ reinterpret_cast 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 RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001740 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001741 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 SourceLocation RAngleLoc,
1743 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001744 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001746 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001747 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001748 SourceRange(LAngleLoc, RAngleLoc),
1749 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 }
1751
1752 /// \brief Build a new C++ const_cast expression.
1753 ///
1754 /// By default, performs semantic analysis to build the new expression.
1755 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001756 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001757 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001758 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 SourceLocation RAngleLoc,
1760 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001761 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001763 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001764 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001765 SourceRange(LAngleLoc, RAngleLoc),
1766 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 }
Mike Stump1eb44332009-09-09 15:08:12 +00001768
Douglas Gregorb98b1992009-08-11 05:31:07 +00001769 /// \brief Build a new C++ functional-style cast expression.
1770 ///
1771 /// By default, performs semantic analysis to build the new expression.
1772 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001773 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1774 SourceLocation LParenLoc,
1775 Expr *Sub,
1776 SourceLocation RParenLoc) {
1777 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001778 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779 RParenLoc);
1780 }
Mike Stump1eb44332009-09-09 15:08:12 +00001781
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 /// \brief Build a new C++ typeid(type) expression.
1783 ///
1784 /// By default, performs semantic analysis to build the new expression.
1785 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001786 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001787 SourceLocation TypeidLoc,
1788 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001790 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001791 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 }
Mike Stump1eb44332009-09-09 15:08:12 +00001793
Francois Pichet01b7c302010-09-08 12:20:18 +00001794
Douglas Gregorb98b1992009-08-11 05:31:07 +00001795 /// \brief Build a new C++ typeid(expr) expression.
1796 ///
1797 /// By default, performs semantic analysis to build the new expression.
1798 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001799 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001800 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001801 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001802 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001803 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001804 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001805 }
1806
Francois Pichet01b7c302010-09-08 12:20:18 +00001807 /// \brief Build a new C++ __uuidof(type) expression.
1808 ///
1809 /// By default, performs semantic analysis to build the new expression.
1810 /// Subclasses may override this routine to provide different behavior.
1811 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1812 SourceLocation TypeidLoc,
1813 TypeSourceInfo *Operand,
1814 SourceLocation RParenLoc) {
1815 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1816 RParenLoc);
1817 }
1818
1819 /// \brief Build a new C++ __uuidof(expr) expression.
1820 ///
1821 /// By default, performs semantic analysis to build the new expression.
1822 /// Subclasses may override this routine to provide different behavior.
1823 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1824 SourceLocation TypeidLoc,
1825 Expr *Operand,
1826 SourceLocation RParenLoc) {
1827 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1828 RParenLoc);
1829 }
1830
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 /// \brief Build a new C++ "this" expression.
1832 ///
1833 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001834 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001835 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001836 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001837 QualType ThisType,
1838 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001839 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001840 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1841 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001842 }
1843
1844 /// \brief Build a new C++ throw expression.
1845 ///
1846 /// By default, performs semantic analysis to build the new expression.
1847 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001848 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001849 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 }
1851
1852 /// \brief Build a new C++ default-argument expression.
1853 ///
1854 /// By default, builds a new default-argument expression, which does not
1855 /// require any semantic analysis. Subclasses may override this routine to
1856 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001857 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001858 ParmVarDecl *Param) {
1859 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1860 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001861 }
1862
1863 /// \brief Build a new C++ zero-initialization expression.
1864 ///
1865 /// By default, performs semantic analysis to build the new expression.
1866 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001867 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1868 SourceLocation LParenLoc,
1869 SourceLocation RParenLoc) {
1870 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001871 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001872 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001873 }
Mike Stump1eb44332009-09-09 15:08:12 +00001874
Douglas Gregorb98b1992009-08-11 05:31:07 +00001875 /// \brief Build a new C++ "new" expression.
1876 ///
1877 /// By default, performs semantic analysis to build the new expression.
1878 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001879 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001880 bool UseGlobal,
1881 SourceLocation PlacementLParen,
1882 MultiExprArg PlacementArgs,
1883 SourceLocation PlacementRParen,
1884 SourceRange TypeIdParens,
1885 QualType AllocatedType,
1886 TypeSourceInfo *AllocatedTypeInfo,
1887 Expr *ArraySize,
1888 SourceLocation ConstructorLParen,
1889 MultiExprArg ConstructorArgs,
1890 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001891 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001892 PlacementLParen,
1893 move(PlacementArgs),
1894 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001895 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001896 AllocatedType,
1897 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001898 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 ConstructorLParen,
1900 move(ConstructorArgs),
1901 ConstructorRParen);
1902 }
Mike Stump1eb44332009-09-09 15:08:12 +00001903
Douglas Gregorb98b1992009-08-11 05:31:07 +00001904 /// \brief Build a new C++ "delete" expression.
1905 ///
1906 /// By default, performs semantic analysis to build the new expression.
1907 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001908 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 bool IsGlobalDelete,
1910 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001911 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001912 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001913 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001914 }
Mike Stump1eb44332009-09-09 15:08:12 +00001915
Douglas Gregorb98b1992009-08-11 05:31:07 +00001916 /// \brief Build a new unary type trait expression.
1917 ///
1918 /// By default, performs semantic analysis to build the new expression.
1919 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001920 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001921 SourceLocation StartLoc,
1922 TypeSourceInfo *T,
1923 SourceLocation RParenLoc) {
1924 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001925 }
1926
Francois Pichet6ad6f282010-12-07 00:08:36 +00001927 /// \brief Build a new binary type trait expression.
1928 ///
1929 /// By default, performs semantic analysis to build the new expression.
1930 /// Subclasses may override this routine to provide different behavior.
1931 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1932 SourceLocation StartLoc,
1933 TypeSourceInfo *LhsT,
1934 TypeSourceInfo *RhsT,
1935 SourceLocation RParenLoc) {
1936 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1937 }
1938
John Wiegley21ff2e52011-04-28 00:16:57 +00001939 /// \brief Build a new array type trait expression.
1940 ///
1941 /// By default, performs semantic analysis to build the new expression.
1942 /// Subclasses may override this routine to provide different behavior.
1943 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1944 SourceLocation StartLoc,
1945 TypeSourceInfo *TSInfo,
1946 Expr *DimExpr,
1947 SourceLocation RParenLoc) {
1948 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1949 }
1950
John Wiegley55262202011-04-25 06:54:41 +00001951 /// \brief Build a new expression trait expression.
1952 ///
1953 /// By default, performs semantic analysis to build the new expression.
1954 /// Subclasses may override this routine to provide different behavior.
1955 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1956 SourceLocation StartLoc,
1957 Expr *Queried,
1958 SourceLocation RParenLoc) {
1959 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1960 }
1961
Mike Stump1eb44332009-09-09 15:08:12 +00001962 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001963 /// expression.
1964 ///
1965 /// By default, performs semantic analysis to build the new expression.
1966 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001967 ExprResult RebuildDependentScopeDeclRefExpr(
1968 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001969 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001970 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001971 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001972 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00001973
1974 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001975 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001976 *TemplateArgs);
1977
Abramo Bagnara25777432010-08-11 22:01:17 +00001978 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001979 }
1980
1981 /// \brief Build a new template-id expression.
1982 ///
1983 /// By default, performs semantic analysis to build the new expression.
1984 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001985 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001986 LookupResult &R,
1987 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001988 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001989 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001990 }
1991
1992 /// \brief Build a new object-construction expression.
1993 ///
1994 /// By default, performs semantic analysis to build the new expression.
1995 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001996 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001997 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001998 CXXConstructorDecl *Constructor,
1999 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002000 MultiExprArg Args,
2001 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002002 CXXConstructExpr::ConstructionKind ConstructKind,
2003 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002004 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002005 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002006 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002007 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002008
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002009 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002010 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00002011 RequiresZeroInit, ConstructKind,
2012 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002013 }
2014
2015 /// \brief Build a new object-construction expression.
2016 ///
2017 /// By default, performs semantic analysis to build the new expression.
2018 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002019 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2020 SourceLocation LParenLoc,
2021 MultiExprArg Args,
2022 SourceLocation RParenLoc) {
2023 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002024 LParenLoc,
2025 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002026 RParenLoc);
2027 }
2028
2029 /// \brief Build a new object-construction expression.
2030 ///
2031 /// By default, performs semantic analysis to build the new expression.
2032 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002033 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2034 SourceLocation LParenLoc,
2035 MultiExprArg Args,
2036 SourceLocation RParenLoc) {
2037 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002038 LParenLoc,
2039 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002040 RParenLoc);
2041 }
Mike Stump1eb44332009-09-09 15:08:12 +00002042
Douglas Gregorb98b1992009-08-11 05:31:07 +00002043 /// \brief Build a new member reference expression.
2044 ///
2045 /// By default, performs semantic analysis to build the new expression.
2046 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002047 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002048 QualType BaseType,
2049 bool IsArrow,
2050 SourceLocation OperatorLoc,
2051 NestedNameSpecifierLoc QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00002052 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002053 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002054 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002055 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002056 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002057
John McCall9ae2f072010-08-23 23:25:46 +00002058 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002059 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00002060 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002061 MemberNameInfo,
2062 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002063 }
2064
John McCall129e2df2009-11-30 22:42:35 +00002065 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002066 ///
2067 /// By default, performs semantic analysis to build the new expression.
2068 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002069 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00002070 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00002071 SourceLocation OperatorLoc,
2072 bool IsArrow,
Douglas Gregor4c9be892011-02-28 20:01:57 +00002073 NestedNameSpecifierLoc QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00002074 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00002075 LookupResult &R,
2076 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002077 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002078 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002079
John McCall9ae2f072010-08-23 23:25:46 +00002080 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002081 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00002082 SS, FirstQualifierInScope,
2083 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002084 }
Mike Stump1eb44332009-09-09 15:08:12 +00002085
Sebastian Redl2e156222010-09-10 20:55:43 +00002086 /// \brief Build a new noexcept expression.
2087 ///
2088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
2090 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2091 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2092 }
2093
Douglas Gregoree8aff02011-01-04 17:33:58 +00002094 /// \brief Build a new expression to compute the length of a parameter pack.
2095 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2096 SourceLocation PackLoc,
2097 SourceLocation RParenLoc,
2098 unsigned Length) {
2099 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2100 OperatorLoc, Pack, PackLoc,
2101 RParenLoc, Length);
2102 }
2103
Douglas Gregorb98b1992009-08-11 05:31:07 +00002104 /// \brief Build a new Objective-C @encode expression.
2105 ///
2106 /// By default, performs semantic analysis to build the new expression.
2107 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002108 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002109 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002110 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002111 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002112 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002113 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002114
Douglas Gregor92e986e2010-04-22 16:44:27 +00002115 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002116 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002117 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002118 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002119 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002120 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002121 MultiExprArg Args,
2122 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002123 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2124 ReceiverTypeInfo->getType(),
2125 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002126 Sel, Method, LBracLoc, SelectorLoc,
2127 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002128 }
2129
2130 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002131 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002132 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002133 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002134 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002135 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002136 MultiExprArg Args,
2137 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002138 return SemaRef.BuildInstanceMessage(Receiver,
2139 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002140 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002141 Sel, Method, LBracLoc, SelectorLoc,
2142 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002143 }
2144
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002145 /// \brief Build a new Objective-C ivar reference expression.
2146 ///
2147 /// By default, performs semantic analysis to build the new expression.
2148 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002149 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002150 SourceLocation IvarLoc,
2151 bool IsArrow, bool IsFreeIvar) {
2152 // FIXME: We lose track of the IsFreeIvar bit.
2153 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002154 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002155 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2156 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002157 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002158 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002159 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002160 false);
John Wiegley429bb272011-04-08 18:41:53 +00002161 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002162 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002163
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002164 if (Result.get())
2165 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002166
John Wiegley429bb272011-04-08 18:41:53 +00002167 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002168 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002169 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002170 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002171 /*TemplateArgs=*/0);
2172 }
Douglas Gregore3303542010-04-26 20:47:02 +00002173
2174 /// \brief Build a new Objective-C property reference expression.
2175 ///
2176 /// By default, performs semantic analysis to build the new expression.
2177 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002178 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002179 ObjCPropertyDecl *Property,
2180 SourceLocation PropertyLoc) {
2181 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002182 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002183 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2184 Sema::LookupMemberName);
2185 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002186 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002187 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002188 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002189 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002190 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002191
Douglas Gregore3303542010-04-26 20:47:02 +00002192 if (Result.get())
2193 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002194
John Wiegley429bb272011-04-08 18:41:53 +00002195 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002196 /*FIXME:*/PropertyLoc, IsArrow,
2197 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002198 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002199 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002200 /*TemplateArgs=*/0);
2201 }
Sean Huntc3021132010-05-05 15:23:54 +00002202
John McCall12f78a62010-12-02 01:19:52 +00002203 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002204 ///
2205 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002206 /// Subclasses may override this routine to provide different behavior.
2207 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2208 ObjCMethodDecl *Getter,
2209 ObjCMethodDecl *Setter,
2210 SourceLocation PropertyLoc) {
2211 // Since these expressions can only be value-dependent, we do not
2212 // need to perform semantic analysis again.
2213 return Owned(
2214 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2215 VK_LValue, OK_ObjCProperty,
2216 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002217 }
2218
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002219 /// \brief Build a new Objective-C "isa" expression.
2220 ///
2221 /// By default, performs semantic analysis to build the new expression.
2222 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002223 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002224 bool IsArrow) {
2225 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002226 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002227 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2228 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002229 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002230 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002231 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002232 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002233 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002234
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002235 if (Result.get())
2236 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002237
John Wiegley429bb272011-04-08 18:41:53 +00002238 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002239 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002240 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002241 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002242 /*TemplateArgs=*/0);
2243 }
Sean Huntc3021132010-05-05 15:23:54 +00002244
Douglas Gregorb98b1992009-08-11 05:31:07 +00002245 /// \brief Build a new shuffle vector expression.
2246 ///
2247 /// By default, performs semantic analysis to build the new expression.
2248 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002249 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002250 MultiExprArg SubExprs,
2251 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002252 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002253 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002254 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2255 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2256 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2257 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002258
Douglas Gregorb98b1992009-08-11 05:31:07 +00002259 // Build a reference to the __builtin_shufflevector builtin
2260 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002261 ExprResult Callee
2262 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2263 VK_LValue, BuiltinLoc));
2264 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2265 if (Callee.isInvalid())
2266 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002267
2268 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002269 unsigned NumSubExprs = SubExprs.size();
2270 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002271 ExprResult TheCall = SemaRef.Owned(
2272 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002273 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002274 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002275 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002276 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002277
Douglas Gregorb98b1992009-08-11 05:31:07 +00002278 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002279 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002280 }
John McCall43fed0d2010-11-12 08:19:04 +00002281
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002282 /// \brief Build a new template argument pack expansion.
2283 ///
2284 /// By default, performs semantic analysis to build a new pack expansion
2285 /// for a template argument. Subclasses may override this routine to provide
2286 /// different behavior.
2287 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002288 SourceLocation EllipsisLoc,
2289 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002290 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002291 case TemplateArgument::Expression: {
2292 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002293 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2294 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002295 if (Result.isInvalid())
2296 return TemplateArgumentLoc();
2297
2298 return TemplateArgumentLoc(Result.get(), Result.get());
2299 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002300
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002301 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002302 return TemplateArgumentLoc(TemplateArgument(
2303 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002304 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002305 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002306 Pattern.getTemplateNameLoc(),
2307 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002308
2309 case TemplateArgument::Null:
2310 case TemplateArgument::Integral:
2311 case TemplateArgument::Declaration:
2312 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002313 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002314 llvm_unreachable("Pack expansion pattern has no parameter packs");
2315
2316 case TemplateArgument::Type:
2317 if (TypeSourceInfo *Expansion
2318 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002319 EllipsisLoc,
2320 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002321 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2322 Expansion);
2323 break;
2324 }
2325
2326 return TemplateArgumentLoc();
2327 }
2328
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002329 /// \brief Build a new expression pack expansion.
2330 ///
2331 /// By default, performs semantic analysis to build a new pack expansion
2332 /// for an expression. Subclasses may override this routine to provide
2333 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002334 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2335 llvm::Optional<unsigned> NumExpansions) {
2336 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002337 }
2338
John McCall43fed0d2010-11-12 08:19:04 +00002339private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002340 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2341 QualType ObjectType,
2342 NamedDecl *FirstQualifierInScope,
2343 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002344
2345 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2346 QualType ObjectType,
2347 NamedDecl *FirstQualifierInScope,
2348 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002349};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002350
Douglas Gregor43959a92009-08-20 07:17:43 +00002351template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002352StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002353 if (!S)
2354 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002355
Douglas Gregor43959a92009-08-20 07:17:43 +00002356 switch (S->getStmtClass()) {
2357 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002358
Douglas Gregor43959a92009-08-20 07:17:43 +00002359 // Transform individual statement nodes
2360#define STMT(Node, Parent) \
2361 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002362#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002363#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002364#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002365
Douglas Gregor43959a92009-08-20 07:17:43 +00002366 // Transform expressions by calling TransformExpr.
2367#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002368#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002369#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002370#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002371 {
John McCall60d7b3a2010-08-24 06:29:42 +00002372 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002373 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002374 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002375
John McCall9ae2f072010-08-23 23:25:46 +00002376 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002377 }
Mike Stump1eb44332009-09-09 15:08:12 +00002378 }
2379
John McCall3fa5cae2010-10-26 07:05:15 +00002380 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002381}
Mike Stump1eb44332009-09-09 15:08:12 +00002382
2383
Douglas Gregor670444e2009-08-04 22:27:00 +00002384template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002385ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002386 if (!E)
2387 return SemaRef.Owned(E);
2388
2389 switch (E->getStmtClass()) {
2390 case Stmt::NoStmtClass: break;
2391#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002392#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002393#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002394 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002395#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002396 }
2397
John McCall3fa5cae2010-10-26 07:05:15 +00002398 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002399}
2400
2401template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002402bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2403 unsigned NumInputs,
2404 bool IsCall,
2405 llvm::SmallVectorImpl<Expr *> &Outputs,
2406 bool *ArgChanged) {
2407 for (unsigned I = 0; I != NumInputs; ++I) {
2408 // If requested, drop call arguments that need to be dropped.
2409 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2410 if (ArgChanged)
2411 *ArgChanged = true;
2412
2413 break;
2414 }
2415
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002416 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2417 Expr *Pattern = Expansion->getPattern();
2418
2419 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2420 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2421 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2422
2423 // Determine whether the set of unexpanded parameter packs can and should
2424 // be expanded.
2425 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002426 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002427 llvm::Optional<unsigned> OrigNumExpansions
2428 = Expansion->getNumExpansions();
2429 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002430 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2431 Pattern->getSourceRange(),
2432 Unexpanded.data(),
2433 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002434 Expand, RetainExpansion,
2435 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002436 return true;
2437
2438 if (!Expand) {
2439 // The transform has determined that we should perform a simple
2440 // transformation on the pack expansion, producing another pack
2441 // expansion.
2442 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2443 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2444 if (OutPattern.isInvalid())
2445 return true;
2446
2447 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002448 Expansion->getEllipsisLoc(),
2449 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002450 if (Out.isInvalid())
2451 return true;
2452
2453 if (ArgChanged)
2454 *ArgChanged = true;
2455 Outputs.push_back(Out.get());
2456 continue;
2457 }
2458
2459 // The transform has determined that we should perform an elementwise
2460 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002461 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002462 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2463 ExprResult Out = getDerived().TransformExpr(Pattern);
2464 if (Out.isInvalid())
2465 return true;
2466
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002467 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002468 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2469 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002470 if (Out.isInvalid())
2471 return true;
2472 }
2473
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002474 if (ArgChanged)
2475 *ArgChanged = true;
2476 Outputs.push_back(Out.get());
2477 }
2478
2479 continue;
2480 }
2481
Douglas Gregoraa165f82011-01-03 19:04:46 +00002482 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2483 if (Result.isInvalid())
2484 return true;
2485
2486 if (Result.get() != Inputs[I] && ArgChanged)
2487 *ArgChanged = true;
2488
2489 Outputs.push_back(Result.get());
2490 }
2491
2492 return false;
2493}
2494
2495template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002496NestedNameSpecifierLoc
2497TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2498 NestedNameSpecifierLoc NNS,
2499 QualType ObjectType,
2500 NamedDecl *FirstQualifierInScope) {
2501 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2502 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2503 Qualifier = Qualifier.getPrefix())
2504 Qualifiers.push_back(Qualifier);
2505
2506 CXXScopeSpec SS;
2507 while (!Qualifiers.empty()) {
2508 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2509 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2510
2511 switch (QNNS->getKind()) {
2512 case NestedNameSpecifier::Identifier:
2513 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2514 *QNNS->getAsIdentifier(),
2515 Q.getLocalBeginLoc(),
2516 Q.getLocalEndLoc(),
2517 ObjectType, false, SS,
2518 FirstQualifierInScope, false))
2519 return NestedNameSpecifierLoc();
2520
2521 break;
2522
2523 case NestedNameSpecifier::Namespace: {
2524 NamespaceDecl *NS
2525 = cast_or_null<NamespaceDecl>(
2526 getDerived().TransformDecl(
2527 Q.getLocalBeginLoc(),
2528 QNNS->getAsNamespace()));
2529 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2530 break;
2531 }
2532
2533 case NestedNameSpecifier::NamespaceAlias: {
2534 NamespaceAliasDecl *Alias
2535 = cast_or_null<NamespaceAliasDecl>(
2536 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2537 QNNS->getAsNamespaceAlias()));
2538 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2539 Q.getLocalEndLoc());
2540 break;
2541 }
2542
2543 case NestedNameSpecifier::Global:
2544 // There is no meaningful transformation that one could perform on the
2545 // global scope.
2546 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2547 break;
2548
2549 case NestedNameSpecifier::TypeSpecWithTemplate:
2550 case NestedNameSpecifier::TypeSpec: {
2551 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2552 FirstQualifierInScope, SS);
2553
2554 if (!TL)
2555 return NestedNameSpecifierLoc();
2556
2557 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2558 (SemaRef.getLangOptions().CPlusPlus0x &&
2559 TL.getType()->isEnumeralType())) {
2560 assert(!TL.getType().hasLocalQualifiers() &&
2561 "Can't get cv-qualifiers here");
2562 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2563 Q.getLocalEndLoc());
2564 break;
2565 }
2566
2567 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2568 << TL.getType() << SS.getRange();
2569 return NestedNameSpecifierLoc();
2570 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002571 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002572
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002573 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002574 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002575 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002576 }
2577
2578 // Don't rebuild the nested-name-specifier if we don't have to.
2579 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2580 !getDerived().AlwaysRebuild())
2581 return NNS;
2582
2583 // If we can re-use the source-location data from the original
2584 // nested-name-specifier, do so.
2585 if (SS.location_size() == NNS.getDataLength() &&
2586 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2587 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2588
2589 // Allocate new nested-name-specifier location information.
2590 return SS.getWithLocInContext(SemaRef.Context);
2591}
2592
2593template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002594DeclarationNameInfo
2595TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002596::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002597 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002598 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002599 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002600
2601 switch (Name.getNameKind()) {
2602 case DeclarationName::Identifier:
2603 case DeclarationName::ObjCZeroArgSelector:
2604 case DeclarationName::ObjCOneArgSelector:
2605 case DeclarationName::ObjCMultiArgSelector:
2606 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002607 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002608 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002609 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002610
Douglas Gregor81499bb2009-09-03 22:13:48 +00002611 case DeclarationName::CXXConstructorName:
2612 case DeclarationName::CXXDestructorName:
2613 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002614 TypeSourceInfo *NewTInfo;
2615 CanQualType NewCanTy;
2616 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002617 NewTInfo = getDerived().TransformType(OldTInfo);
2618 if (!NewTInfo)
2619 return DeclarationNameInfo();
2620 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002621 }
2622 else {
2623 NewTInfo = 0;
2624 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002625 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002626 if (NewT.isNull())
2627 return DeclarationNameInfo();
2628 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2629 }
Mike Stump1eb44332009-09-09 15:08:12 +00002630
Abramo Bagnara25777432010-08-11 22:01:17 +00002631 DeclarationName NewName
2632 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2633 NewCanTy);
2634 DeclarationNameInfo NewNameInfo(NameInfo);
2635 NewNameInfo.setName(NewName);
2636 NewNameInfo.setNamedTypeInfo(NewTInfo);
2637 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002638 }
Mike Stump1eb44332009-09-09 15:08:12 +00002639 }
2640
Abramo Bagnara25777432010-08-11 22:01:17 +00002641 assert(0 && "Unknown name kind.");
2642 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002643}
2644
2645template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002646TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002647TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2648 TemplateName Name,
2649 SourceLocation NameLoc,
2650 QualType ObjectType,
2651 NamedDecl *FirstQualifierInScope) {
2652 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2653 TemplateDecl *Template = QTN->getTemplateDecl();
2654 assert(Template && "qualified template name must refer to a template");
2655
2656 TemplateDecl *TransTemplate
2657 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2658 Template));
2659 if (!TransTemplate)
2660 return TemplateName();
2661
2662 if (!getDerived().AlwaysRebuild() &&
2663 SS.getScopeRep() == QTN->getQualifier() &&
2664 TransTemplate == Template)
2665 return Name;
2666
2667 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2668 TransTemplate);
2669 }
2670
2671 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2672 if (SS.getScopeRep()) {
2673 // These apply to the scope specifier, not the template.
2674 ObjectType = QualType();
2675 FirstQualifierInScope = 0;
2676 }
2677
2678 if (!getDerived().AlwaysRebuild() &&
2679 SS.getScopeRep() == DTN->getQualifier() &&
2680 ObjectType.isNull())
2681 return Name;
2682
2683 if (DTN->isIdentifier()) {
2684 return getDerived().RebuildTemplateName(SS,
2685 *DTN->getIdentifier(),
2686 NameLoc,
2687 ObjectType,
2688 FirstQualifierInScope);
2689 }
2690
2691 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2692 ObjectType);
2693 }
2694
2695 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2696 TemplateDecl *TransTemplate
2697 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2698 Template));
2699 if (!TransTemplate)
2700 return TemplateName();
2701
2702 if (!getDerived().AlwaysRebuild() &&
2703 TransTemplate == Template)
2704 return Name;
2705
2706 return TemplateName(TransTemplate);
2707 }
2708
2709 if (SubstTemplateTemplateParmPackStorage *SubstPack
2710 = Name.getAsSubstTemplateTemplateParmPack()) {
2711 TemplateTemplateParmDecl *TransParam
2712 = cast_or_null<TemplateTemplateParmDecl>(
2713 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2714 if (!TransParam)
2715 return TemplateName();
2716
2717 if (!getDerived().AlwaysRebuild() &&
2718 TransParam == SubstPack->getParameterPack())
2719 return Name;
2720
2721 return getDerived().RebuildTemplateName(TransParam,
2722 SubstPack->getArgumentPack());
2723 }
2724
2725 // These should be getting filtered out before they reach the AST.
2726 llvm_unreachable("overloaded function decl survived to here");
2727 return TemplateName();
2728}
2729
2730template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002731void TreeTransform<Derived>::InventTemplateArgumentLoc(
2732 const TemplateArgument &Arg,
2733 TemplateArgumentLoc &Output) {
2734 SourceLocation Loc = getDerived().getBaseLocation();
2735 switch (Arg.getKind()) {
2736 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002737 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002738 break;
2739
2740 case TemplateArgument::Type:
2741 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002742 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002743
John McCall833ca992009-10-29 08:12:44 +00002744 break;
2745
Douglas Gregor788cd062009-11-11 01:00:40 +00002746 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002747 case TemplateArgument::TemplateExpansion: {
2748 NestedNameSpecifierLocBuilder Builder;
2749 TemplateName Template = Arg.getAsTemplate();
2750 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2751 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2752 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2753 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2754
2755 if (Arg.getKind() == TemplateArgument::Template)
2756 Output = TemplateArgumentLoc(Arg,
2757 Builder.getWithLocInContext(SemaRef.Context),
2758 Loc);
2759 else
2760 Output = TemplateArgumentLoc(Arg,
2761 Builder.getWithLocInContext(SemaRef.Context),
2762 Loc, Loc);
2763
Douglas Gregor788cd062009-11-11 01:00:40 +00002764 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002765 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002766
John McCall833ca992009-10-29 08:12:44 +00002767 case TemplateArgument::Expression:
2768 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2769 break;
2770
2771 case TemplateArgument::Declaration:
2772 case TemplateArgument::Integral:
2773 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002774 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002775 break;
2776 }
2777}
2778
2779template<typename Derived>
2780bool TreeTransform<Derived>::TransformTemplateArgument(
2781 const TemplateArgumentLoc &Input,
2782 TemplateArgumentLoc &Output) {
2783 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002784 switch (Arg.getKind()) {
2785 case TemplateArgument::Null:
2786 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002787 Output = Input;
2788 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002789
Douglas Gregor670444e2009-08-04 22:27:00 +00002790 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002791 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002792 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002793 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002794
2795 DI = getDerived().TransformType(DI);
2796 if (!DI) return true;
2797
2798 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2799 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002800 }
Mike Stump1eb44332009-09-09 15:08:12 +00002801
Douglas Gregor670444e2009-08-04 22:27:00 +00002802 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002803 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002804 DeclarationName Name;
2805 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2806 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002807 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002808 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002809 if (!D) return true;
2810
John McCall828bff22009-10-29 18:45:58 +00002811 Expr *SourceExpr = Input.getSourceDeclExpression();
2812 if (SourceExpr) {
2813 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002814 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002815 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002816 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002817 }
2818
2819 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002820 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002821 }
Mike Stump1eb44332009-09-09 15:08:12 +00002822
Douglas Gregor788cd062009-11-11 01:00:40 +00002823 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002824 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2825 if (QualifierLoc) {
2826 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2827 if (!QualifierLoc)
2828 return true;
2829 }
2830
Douglas Gregor1d752d72011-03-02 18:46:51 +00002831 CXXScopeSpec SS;
2832 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002833 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002834 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2835 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002836 if (Template.isNull())
2837 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002838
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002839 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002840 Input.getTemplateNameLoc());
2841 return false;
2842 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002843
2844 case TemplateArgument::TemplateExpansion:
2845 llvm_unreachable("Caller should expand pack expansions");
2846
Douglas Gregor670444e2009-08-04 22:27:00 +00002847 case TemplateArgument::Expression: {
2848 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002849 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002850 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002851
John McCall833ca992009-10-29 08:12:44 +00002852 Expr *InputExpr = Input.getSourceExpression();
2853 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2854
Chris Lattner223de242011-04-25 20:37:58 +00002855 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall833ca992009-10-29 08:12:44 +00002856 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002857 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002858 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002859 }
Mike Stump1eb44332009-09-09 15:08:12 +00002860
Douglas Gregor670444e2009-08-04 22:27:00 +00002861 case TemplateArgument::Pack: {
2862 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2863 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002864 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002865 AEnd = Arg.pack_end();
2866 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002867
John McCall833ca992009-10-29 08:12:44 +00002868 // FIXME: preserve source information here when we start
2869 // caring about parameter packs.
2870
John McCall828bff22009-10-29 18:45:58 +00002871 TemplateArgumentLoc InputArg;
2872 TemplateArgumentLoc OutputArg;
2873 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2874 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002875 return true;
2876
John McCall828bff22009-10-29 18:45:58 +00002877 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002878 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002879
2880 TemplateArgument *TransformedArgsPtr
2881 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2882 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2883 TransformedArgsPtr);
2884 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2885 TransformedArgs.size()),
2886 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002887 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002888 }
2889 }
Mike Stump1eb44332009-09-09 15:08:12 +00002890
Douglas Gregor670444e2009-08-04 22:27:00 +00002891 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002892 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002893}
2894
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002895/// \brief Iterator adaptor that invents template argument location information
2896/// for each of the template arguments in its underlying iterator.
2897template<typename Derived, typename InputIterator>
2898class TemplateArgumentLocInventIterator {
2899 TreeTransform<Derived> &Self;
2900 InputIterator Iter;
2901
2902public:
2903 typedef TemplateArgumentLoc value_type;
2904 typedef TemplateArgumentLoc reference;
2905 typedef typename std::iterator_traits<InputIterator>::difference_type
2906 difference_type;
2907 typedef std::input_iterator_tag iterator_category;
2908
2909 class pointer {
2910 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002911
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002912 public:
2913 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2914
2915 const TemplateArgumentLoc *operator->() const { return &Arg; }
2916 };
2917
2918 TemplateArgumentLocInventIterator() { }
2919
2920 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2921 InputIterator Iter)
2922 : Self(Self), Iter(Iter) { }
2923
2924 TemplateArgumentLocInventIterator &operator++() {
2925 ++Iter;
2926 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002927 }
2928
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002929 TemplateArgumentLocInventIterator operator++(int) {
2930 TemplateArgumentLocInventIterator Old(*this);
2931 ++(*this);
2932 return Old;
2933 }
2934
2935 reference operator*() const {
2936 TemplateArgumentLoc Result;
2937 Self.InventTemplateArgumentLoc(*Iter, Result);
2938 return Result;
2939 }
2940
2941 pointer operator->() const { return pointer(**this); }
2942
2943 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2944 const TemplateArgumentLocInventIterator &Y) {
2945 return X.Iter == Y.Iter;
2946 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002947
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002948 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2949 const TemplateArgumentLocInventIterator &Y) {
2950 return X.Iter != Y.Iter;
2951 }
2952};
2953
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002954template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002955template<typename InputIterator>
2956bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2957 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002958 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002959 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002960 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002961 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002962
2963 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2964 // Unpack argument packs, which we translate them into separate
2965 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002966 // FIXME: We could do much better if we could guarantee that the
2967 // TemplateArgumentLocInfo for the pack expansion would be usable for
2968 // all of the template arguments in the argument pack.
2969 typedef TemplateArgumentLocInventIterator<Derived,
2970 TemplateArgument::pack_iterator>
2971 PackLocIterator;
2972 if (TransformTemplateArguments(PackLocIterator(*this,
2973 In.getArgument().pack_begin()),
2974 PackLocIterator(*this,
2975 In.getArgument().pack_end()),
2976 Outputs))
2977 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002978
2979 continue;
2980 }
2981
2982 if (In.getArgument().isPackExpansion()) {
2983 // We have a pack expansion, for which we will be substituting into
2984 // the pattern.
2985 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00002986 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002987 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00002988 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
2989 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002990
2991 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2992 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2993 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2994
2995 // Determine whether the set of unexpanded parameter packs can and should
2996 // be expanded.
2997 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002998 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00002999 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003000 if (getDerived().TryExpandParameterPacks(Ellipsis,
3001 Pattern.getSourceRange(),
3002 Unexpanded.data(),
3003 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003004 Expand,
3005 RetainExpansion,
3006 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003007 return true;
3008
3009 if (!Expand) {
3010 // The transform has determined that we should perform a simple
3011 // transformation on the pack expansion, producing another pack
3012 // expansion.
3013 TemplateArgumentLoc OutPattern;
3014 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3015 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3016 return true;
3017
Douglas Gregorcded4f62011-01-14 17:04:44 +00003018 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3019 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003020 if (Out.getArgument().isNull())
3021 return true;
3022
3023 Outputs.addArgument(Out);
3024 continue;
3025 }
3026
3027 // The transform has determined that we should perform an elementwise
3028 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003029 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003030 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3031
3032 if (getDerived().TransformTemplateArgument(Pattern, Out))
3033 return true;
3034
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003035 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003036 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3037 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003038 if (Out.getArgument().isNull())
3039 return true;
3040 }
3041
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003042 Outputs.addArgument(Out);
3043 }
3044
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003045 // If we're supposed to retain a pack expansion, do so by temporarily
3046 // forgetting the partially-substituted parameter pack.
3047 if (RetainExpansion) {
3048 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3049
3050 if (getDerived().TransformTemplateArgument(Pattern, Out))
3051 return true;
3052
Douglas Gregorcded4f62011-01-14 17:04:44 +00003053 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3054 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003055 if (Out.getArgument().isNull())
3056 return true;
3057
3058 Outputs.addArgument(Out);
3059 }
Douglas Gregord3731192011-01-10 07:32:04 +00003060
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003061 continue;
3062 }
3063
3064 // The simple case:
3065 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003066 return true;
3067
3068 Outputs.addArgument(Out);
3069 }
3070
3071 return false;
3072
3073}
3074
Douglas Gregor577f75a2009-08-04 16:50:30 +00003075//===----------------------------------------------------------------------===//
3076// Type transformation
3077//===----------------------------------------------------------------------===//
3078
3079template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003080QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003081 if (getDerived().AlreadyTransformed(T))
3082 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003083
John McCalla2becad2009-10-21 00:40:46 +00003084 // Temporary workaround. All of these transformations should
3085 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003086 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3087 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003088
John McCall43fed0d2010-11-12 08:19:04 +00003089 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003090
John McCalla2becad2009-10-21 00:40:46 +00003091 if (!NewDI)
3092 return QualType();
3093
3094 return NewDI->getType();
3095}
3096
3097template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003098TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00003099 if (getDerived().AlreadyTransformed(DI->getType()))
3100 return DI;
3101
3102 TypeLocBuilder TLB;
3103
3104 TypeLoc TL = DI->getTypeLoc();
3105 TLB.reserve(TL.getFullDataSize());
3106
John McCall43fed0d2010-11-12 08:19:04 +00003107 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003108 if (Result.isNull())
3109 return 0;
3110
John McCalla93c9342009-12-07 02:54:59 +00003111 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003112}
3113
3114template<typename Derived>
3115QualType
John McCall43fed0d2010-11-12 08:19:04 +00003116TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003117 switch (T.getTypeLocClass()) {
3118#define ABSTRACT_TYPELOC(CLASS, PARENT)
3119#define TYPELOC(CLASS, PARENT) \
3120 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003121 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003122#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003123 }
Mike Stump1eb44332009-09-09 15:08:12 +00003124
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003125 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003126 return QualType();
3127}
3128
3129/// FIXME: By default, this routine adds type qualifiers only to types
3130/// that can have qualifiers, and silently suppresses those qualifiers
3131/// that are not permitted (e.g., qualifiers on reference or function
3132/// types). This is the right thing for template instantiation, but
3133/// probably not for other clients.
3134template<typename Derived>
3135QualType
3136TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003137 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003138 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003139
John McCall43fed0d2010-11-12 08:19:04 +00003140 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003141 if (Result.isNull())
3142 return QualType();
3143
3144 // Silently suppress qualifiers if the result type can't be qualified.
3145 // FIXME: this is the right thing for template instantiation, but
3146 // probably not for other clients.
3147 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003148 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003149
John McCall28654742010-06-05 06:41:15 +00003150 if (!Quals.empty()) {
3151 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3152 TLB.push<QualifiedTypeLoc>(Result);
3153 // No location information to preserve.
3154 }
John McCalla2becad2009-10-21 00:40:46 +00003155
3156 return Result;
3157}
3158
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003159template<typename Derived>
3160TypeLoc
3161TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3162 QualType ObjectType,
3163 NamedDecl *UnqualLookup,
3164 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003165 QualType T = TL.getType();
3166 if (getDerived().AlreadyTransformed(T))
3167 return TL;
3168
3169 TypeLocBuilder TLB;
3170 QualType Result;
3171
3172 if (isa<TemplateSpecializationType>(T)) {
3173 TemplateSpecializationTypeLoc SpecTL
3174 = cast<TemplateSpecializationTypeLoc>(TL);
3175
3176 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003177 getDerived().TransformTemplateName(SS,
3178 SpecTL.getTypePtr()->getTemplateName(),
3179 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003180 ObjectType, UnqualLookup);
3181 if (Template.isNull())
3182 return TypeLoc();
3183
3184 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3185 Template);
3186 } else if (isa<DependentTemplateSpecializationType>(T)) {
3187 DependentTemplateSpecializationTypeLoc SpecTL
3188 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3189
Douglas Gregora88f09f2011-02-28 17:23:35 +00003190 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003191 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003192 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003193 SpecTL.getNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003194 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003195 if (Template.isNull())
3196 return TypeLoc();
3197
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003198 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003199 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003200 Template,
3201 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003202 } else {
3203 // Nothing special needs to be done for these.
3204 Result = getDerived().TransformType(TLB, TL);
3205 }
3206
3207 if (Result.isNull())
3208 return TypeLoc();
3209
3210 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3211}
3212
Douglas Gregorb71d8212011-03-02 18:32:08 +00003213template<typename Derived>
3214TypeSourceInfo *
3215TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3216 QualType ObjectType,
3217 NamedDecl *UnqualLookup,
3218 CXXScopeSpec &SS) {
3219 // FIXME: Painfully copy-paste from the above!
3220
3221 QualType T = TSInfo->getType();
3222 if (getDerived().AlreadyTransformed(T))
3223 return TSInfo;
3224
3225 TypeLocBuilder TLB;
3226 QualType Result;
3227
3228 TypeLoc TL = TSInfo->getTypeLoc();
3229 if (isa<TemplateSpecializationType>(T)) {
3230 TemplateSpecializationTypeLoc SpecTL
3231 = cast<TemplateSpecializationTypeLoc>(TL);
3232
3233 TemplateName Template
3234 = getDerived().TransformTemplateName(SS,
3235 SpecTL.getTypePtr()->getTemplateName(),
3236 SpecTL.getTemplateNameLoc(),
3237 ObjectType, UnqualLookup);
3238 if (Template.isNull())
3239 return 0;
3240
3241 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3242 Template);
3243 } else if (isa<DependentTemplateSpecializationType>(T)) {
3244 DependentTemplateSpecializationTypeLoc SpecTL
3245 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3246
3247 TemplateName Template
3248 = getDerived().RebuildTemplateName(SS,
3249 *SpecTL.getTypePtr()->getIdentifier(),
3250 SpecTL.getNameLoc(),
3251 ObjectType, UnqualLookup);
3252 if (Template.isNull())
3253 return 0;
3254
3255 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3256 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003257 Template,
3258 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003259 } else {
3260 // Nothing special needs to be done for these.
3261 Result = getDerived().TransformType(TLB, TL);
3262 }
3263
3264 if (Result.isNull())
3265 return 0;
3266
3267 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3268}
3269
John McCalla2becad2009-10-21 00:40:46 +00003270template <class TyLoc> static inline
3271QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3272 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3273 NewT.setNameLoc(T.getNameLoc());
3274 return T.getType();
3275}
3276
John McCalla2becad2009-10-21 00:40:46 +00003277template<typename Derived>
3278QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003279 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003280 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3281 NewT.setBuiltinLoc(T.getBuiltinLoc());
3282 if (T.needsExtraLocalData())
3283 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3284 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003285}
Mike Stump1eb44332009-09-09 15:08:12 +00003286
Douglas Gregor577f75a2009-08-04 16:50:30 +00003287template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003288QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003289 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003290 // FIXME: recurse?
3291 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003292}
Mike Stump1eb44332009-09-09 15:08:12 +00003293
Douglas Gregor577f75a2009-08-04 16:50:30 +00003294template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003295QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003296 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003297 QualType PointeeType
3298 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003299 if (PointeeType.isNull())
3300 return QualType();
3301
3302 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003303 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003304 // A dependent pointer type 'T *' has is being transformed such
3305 // that an Objective-C class type is being replaced for 'T'. The
3306 // resulting pointer type is an ObjCObjectPointerType, not a
3307 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003308 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003309
John McCallc12c5bb2010-05-15 11:32:37 +00003310 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3311 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003312 return Result;
3313 }
John McCall43fed0d2010-11-12 08:19:04 +00003314
Douglas Gregor92e986e2010-04-22 16:44:27 +00003315 if (getDerived().AlwaysRebuild() ||
3316 PointeeType != TL.getPointeeLoc().getType()) {
3317 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3318 if (Result.isNull())
3319 return QualType();
3320 }
Sean Huntc3021132010-05-05 15:23:54 +00003321
Douglas Gregor92e986e2010-04-22 16:44:27 +00003322 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3323 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003324 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003325}
Mike Stump1eb44332009-09-09 15:08:12 +00003326
3327template<typename Derived>
3328QualType
John McCalla2becad2009-10-21 00:40:46 +00003329TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003330 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003331 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003332 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3333 if (PointeeType.isNull())
3334 return QualType();
3335
3336 QualType Result = TL.getType();
3337 if (getDerived().AlwaysRebuild() ||
3338 PointeeType != TL.getPointeeLoc().getType()) {
3339 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003340 TL.getSigilLoc());
3341 if (Result.isNull())
3342 return QualType();
3343 }
3344
Douglas Gregor39968ad2010-04-22 16:50:51 +00003345 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003346 NewT.setSigilLoc(TL.getSigilLoc());
3347 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003348}
3349
John McCall85737a72009-10-30 00:06:24 +00003350/// Transforms a reference type. Note that somewhat paradoxically we
3351/// don't care whether the type itself is an l-value type or an r-value
3352/// type; we only care if the type was *written* as an l-value type
3353/// or an r-value type.
3354template<typename Derived>
3355QualType
3356TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003357 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003358 const ReferenceType *T = TL.getTypePtr();
3359
3360 // Note that this works with the pointee-as-written.
3361 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3362 if (PointeeType.isNull())
3363 return QualType();
3364
3365 QualType Result = TL.getType();
3366 if (getDerived().AlwaysRebuild() ||
3367 PointeeType != T->getPointeeTypeAsWritten()) {
3368 Result = getDerived().RebuildReferenceType(PointeeType,
3369 T->isSpelledAsLValue(),
3370 TL.getSigilLoc());
3371 if (Result.isNull())
3372 return QualType();
3373 }
3374
3375 // r-value references can be rebuilt as l-value references.
3376 ReferenceTypeLoc NewTL;
3377 if (isa<LValueReferenceType>(Result))
3378 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3379 else
3380 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3381 NewTL.setSigilLoc(TL.getSigilLoc());
3382
3383 return Result;
3384}
3385
Mike Stump1eb44332009-09-09 15:08:12 +00003386template<typename Derived>
3387QualType
John McCalla2becad2009-10-21 00:40:46 +00003388TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003389 LValueReferenceTypeLoc TL) {
3390 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003391}
3392
Mike Stump1eb44332009-09-09 15:08:12 +00003393template<typename Derived>
3394QualType
John McCalla2becad2009-10-21 00:40:46 +00003395TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003396 RValueReferenceTypeLoc TL) {
3397 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003398}
Mike Stump1eb44332009-09-09 15:08:12 +00003399
Douglas Gregor577f75a2009-08-04 16:50:30 +00003400template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003401QualType
John McCalla2becad2009-10-21 00:40:46 +00003402TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003403 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003404 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003405 if (PointeeType.isNull())
3406 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003407
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003408 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3409 TypeSourceInfo* NewClsTInfo = 0;
3410 if (OldClsTInfo) {
3411 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3412 if (!NewClsTInfo)
3413 return QualType();
3414 }
3415
3416 const MemberPointerType *T = TL.getTypePtr();
3417 QualType OldClsType = QualType(T->getClass(), 0);
3418 QualType NewClsType;
3419 if (NewClsTInfo)
3420 NewClsType = NewClsTInfo->getType();
3421 else {
3422 NewClsType = getDerived().TransformType(OldClsType);
3423 if (NewClsType.isNull())
3424 return QualType();
3425 }
Mike Stump1eb44332009-09-09 15:08:12 +00003426
John McCalla2becad2009-10-21 00:40:46 +00003427 QualType Result = TL.getType();
3428 if (getDerived().AlwaysRebuild() ||
3429 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003430 NewClsType != OldClsType) {
3431 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003432 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003433 if (Result.isNull())
3434 return QualType();
3435 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003436
John McCalla2becad2009-10-21 00:40:46 +00003437 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3438 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003439 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003440
3441 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003442}
3443
Mike Stump1eb44332009-09-09 15:08:12 +00003444template<typename Derived>
3445QualType
John McCalla2becad2009-10-21 00:40:46 +00003446TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003447 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003448 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003449 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003450 if (ElementType.isNull())
3451 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003452
John McCalla2becad2009-10-21 00:40:46 +00003453 QualType Result = TL.getType();
3454 if (getDerived().AlwaysRebuild() ||
3455 ElementType != T->getElementType()) {
3456 Result = getDerived().RebuildConstantArrayType(ElementType,
3457 T->getSizeModifier(),
3458 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003459 T->getIndexTypeCVRQualifiers(),
3460 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003461 if (Result.isNull())
3462 return QualType();
3463 }
Sean Huntc3021132010-05-05 15:23:54 +00003464
John McCalla2becad2009-10-21 00:40:46 +00003465 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3466 NewTL.setLBracketLoc(TL.getLBracketLoc());
3467 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003468
John McCalla2becad2009-10-21 00:40:46 +00003469 Expr *Size = TL.getSizeExpr();
3470 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003471 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003472 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3473 }
3474 NewTL.setSizeExpr(Size);
3475
3476 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003477}
Mike Stump1eb44332009-09-09 15:08:12 +00003478
Douglas Gregor577f75a2009-08-04 16:50:30 +00003479template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003480QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003481 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003482 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003483 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003484 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003485 if (ElementType.isNull())
3486 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003487
John McCalla2becad2009-10-21 00:40:46 +00003488 QualType Result = TL.getType();
3489 if (getDerived().AlwaysRebuild() ||
3490 ElementType != T->getElementType()) {
3491 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003492 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003493 T->getIndexTypeCVRQualifiers(),
3494 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003495 if (Result.isNull())
3496 return QualType();
3497 }
Sean Huntc3021132010-05-05 15:23:54 +00003498
John McCalla2becad2009-10-21 00:40:46 +00003499 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3500 NewTL.setLBracketLoc(TL.getLBracketLoc());
3501 NewTL.setRBracketLoc(TL.getRBracketLoc());
3502 NewTL.setSizeExpr(0);
3503
3504 return Result;
3505}
3506
3507template<typename Derived>
3508QualType
3509TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003510 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003511 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003512 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3513 if (ElementType.isNull())
3514 return QualType();
3515
3516 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003517 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003518
John McCall60d7b3a2010-08-24 06:29:42 +00003519 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003520 = getDerived().TransformExpr(T->getSizeExpr());
3521 if (SizeResult.isInvalid())
3522 return QualType();
3523
John McCall9ae2f072010-08-23 23:25:46 +00003524 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003525
3526 QualType Result = TL.getType();
3527 if (getDerived().AlwaysRebuild() ||
3528 ElementType != T->getElementType() ||
3529 Size != T->getSizeExpr()) {
3530 Result = getDerived().RebuildVariableArrayType(ElementType,
3531 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003532 Size,
John McCalla2becad2009-10-21 00:40:46 +00003533 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003534 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003535 if (Result.isNull())
3536 return QualType();
3537 }
Sean Huntc3021132010-05-05 15:23:54 +00003538
John McCalla2becad2009-10-21 00:40:46 +00003539 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3540 NewTL.setLBracketLoc(TL.getLBracketLoc());
3541 NewTL.setRBracketLoc(TL.getRBracketLoc());
3542 NewTL.setSizeExpr(Size);
3543
3544 return Result;
3545}
3546
3547template<typename Derived>
3548QualType
3549TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003550 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003551 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003552 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3553 if (ElementType.isNull())
3554 return QualType();
3555
3556 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003557 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003558
John McCall3b657512011-01-19 10:06:00 +00003559 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3560 Expr *origSize = TL.getSizeExpr();
3561 if (!origSize) origSize = T->getSizeExpr();
3562
3563 ExprResult sizeResult
3564 = getDerived().TransformExpr(origSize);
3565 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003566 return QualType();
3567
John McCall3b657512011-01-19 10:06:00 +00003568 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003569
3570 QualType Result = TL.getType();
3571 if (getDerived().AlwaysRebuild() ||
3572 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003573 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003574 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3575 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003576 size,
John McCalla2becad2009-10-21 00:40:46 +00003577 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003578 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003579 if (Result.isNull())
3580 return QualType();
3581 }
John McCalla2becad2009-10-21 00:40:46 +00003582
3583 // We might have any sort of array type now, but fortunately they
3584 // all have the same location layout.
3585 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3586 NewTL.setLBracketLoc(TL.getLBracketLoc());
3587 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003588 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003589
3590 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003591}
Mike Stump1eb44332009-09-09 15:08:12 +00003592
3593template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003594QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003595 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003596 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003597 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003598
3599 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003600 QualType ElementType = getDerived().TransformType(T->getElementType());
3601 if (ElementType.isNull())
3602 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003603
Douglas Gregor670444e2009-08-04 22:27:00 +00003604 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003605 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003606
John McCall60d7b3a2010-08-24 06:29:42 +00003607 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003608 if (Size.isInvalid())
3609 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003610
John McCalla2becad2009-10-21 00:40:46 +00003611 QualType Result = TL.getType();
3612 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003613 ElementType != T->getElementType() ||
3614 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003615 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003616 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003617 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003618 if (Result.isNull())
3619 return QualType();
3620 }
John McCalla2becad2009-10-21 00:40:46 +00003621
3622 // Result might be dependent or not.
3623 if (isa<DependentSizedExtVectorType>(Result)) {
3624 DependentSizedExtVectorTypeLoc NewTL
3625 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3626 NewTL.setNameLoc(TL.getNameLoc());
3627 } else {
3628 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3629 NewTL.setNameLoc(TL.getNameLoc());
3630 }
3631
3632 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003633}
Mike Stump1eb44332009-09-09 15:08:12 +00003634
3635template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003636QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003637 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003638 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003639 QualType ElementType = getDerived().TransformType(T->getElementType());
3640 if (ElementType.isNull())
3641 return QualType();
3642
John McCalla2becad2009-10-21 00:40:46 +00003643 QualType Result = TL.getType();
3644 if (getDerived().AlwaysRebuild() ||
3645 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003646 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003647 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003648 if (Result.isNull())
3649 return QualType();
3650 }
Sean Huntc3021132010-05-05 15:23:54 +00003651
John McCalla2becad2009-10-21 00:40:46 +00003652 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3653 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003654
John McCalla2becad2009-10-21 00:40:46 +00003655 return Result;
3656}
3657
3658template<typename Derived>
3659QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003660 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003661 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003662 QualType ElementType = getDerived().TransformType(T->getElementType());
3663 if (ElementType.isNull())
3664 return QualType();
3665
3666 QualType Result = TL.getType();
3667 if (getDerived().AlwaysRebuild() ||
3668 ElementType != T->getElementType()) {
3669 Result = getDerived().RebuildExtVectorType(ElementType,
3670 T->getNumElements(),
3671 /*FIXME*/ SourceLocation());
3672 if (Result.isNull())
3673 return QualType();
3674 }
Sean Huntc3021132010-05-05 15:23:54 +00003675
John McCalla2becad2009-10-21 00:40:46 +00003676 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3677 NewTL.setNameLoc(TL.getNameLoc());
3678
3679 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003680}
Mike Stump1eb44332009-09-09 15:08:12 +00003681
3682template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003683ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003684TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3685 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003686 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003687 TypeSourceInfo *NewDI = 0;
3688
3689 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3690 // If we're substituting into a pack expansion type and we know the
3691 TypeLoc OldTL = OldDI->getTypeLoc();
3692 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3693
3694 TypeLocBuilder TLB;
3695 TypeLoc NewTL = OldDI->getTypeLoc();
3696 TLB.reserve(NewTL.getFullDataSize());
3697
3698 QualType Result = getDerived().TransformType(TLB,
3699 OldExpansionTL.getPatternLoc());
3700 if (Result.isNull())
3701 return 0;
3702
3703 Result = RebuildPackExpansionType(Result,
3704 OldExpansionTL.getPatternLoc().getSourceRange(),
3705 OldExpansionTL.getEllipsisLoc(),
3706 NumExpansions);
3707 if (Result.isNull())
3708 return 0;
3709
3710 PackExpansionTypeLoc NewExpansionTL
3711 = TLB.push<PackExpansionTypeLoc>(Result);
3712 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3713 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3714 } else
3715 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003716 if (!NewDI)
3717 return 0;
3718
3719 if (NewDI == OldDI)
3720 return OldParm;
3721 else
3722 return ParmVarDecl::Create(SemaRef.Context,
3723 OldParm->getDeclContext(),
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00003724 OldParm->getInnerLocStart(),
John McCall21ef0fa2010-03-11 09:03:00 +00003725 OldParm->getLocation(),
3726 OldParm->getIdentifier(),
3727 NewDI->getType(),
3728 NewDI,
3729 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00003730 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00003731 /* DefArg */ NULL);
3732}
3733
3734template<typename Derived>
3735bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003736 TransformFunctionTypeParams(SourceLocation Loc,
3737 ParmVarDecl **Params, unsigned NumParams,
3738 const QualType *ParamTypes,
3739 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3740 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3741 for (unsigned i = 0; i != NumParams; ++i) {
3742 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003743 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003744 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003745 if (OldParm->isParameterPack()) {
3746 // We have a function parameter pack that may need to be expanded.
3747 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003748
Douglas Gregor603cfb42011-01-05 23:12:31 +00003749 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003750 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3751 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3752 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3753 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003754 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3755
Douglas Gregor603cfb42011-01-05 23:12:31 +00003756 // Determine whether we should expand the parameter packs.
3757 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003758 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003759 llvm::Optional<unsigned> OrigNumExpansions
3760 = ExpansionTL.getTypePtr()->getNumExpansions();
3761 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003762 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3763 Pattern.getSourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003764 Unexpanded.data(),
3765 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003766 ShouldExpand,
3767 RetainExpansion,
3768 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003769 return true;
3770 }
3771
3772 if (ShouldExpand) {
3773 // Expand the function parameter pack into multiple, separate
3774 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003775 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003776 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003777 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3778 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003779 = getDerived().TransformFunctionTypeParam(OldParm,
3780 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003781 if (!NewParm)
3782 return true;
3783
Douglas Gregora009b592011-01-07 00:20:55 +00003784 OutParamTypes.push_back(NewParm->getType());
3785 if (PVars)
3786 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003787 }
Douglas Gregord3731192011-01-10 07:32:04 +00003788
3789 // If we're supposed to retain a pack expansion, do so by temporarily
3790 // forgetting the partially-substituted parameter pack.
3791 if (RetainExpansion) {
3792 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3793 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003794 = getDerived().TransformFunctionTypeParam(OldParm,
3795 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003796 if (!NewParm)
3797 return true;
3798
3799 OutParamTypes.push_back(NewParm->getType());
3800 if (PVars)
3801 PVars->push_back(NewParm);
3802 }
3803
Douglas Gregor603cfb42011-01-05 23:12:31 +00003804 // We're done with the pack expansion.
3805 continue;
3806 }
3807
3808 // We'll substitute the parameter now without expanding the pack
3809 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003810 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3811 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3812 NumExpansions);
3813 } else {
3814 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3815 llvm::Optional<unsigned>());
Douglas Gregor603cfb42011-01-05 23:12:31 +00003816 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003817
John McCall21ef0fa2010-03-11 09:03:00 +00003818 if (!NewParm)
3819 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003820
Douglas Gregora009b592011-01-07 00:20:55 +00003821 OutParamTypes.push_back(NewParm->getType());
3822 if (PVars)
3823 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003824 continue;
3825 }
John McCall21ef0fa2010-03-11 09:03:00 +00003826
3827 // Deal with the possibility that we don't have a parameter
3828 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003829 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003830 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003831 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003832 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003833 if (const PackExpansionType *Expansion
3834 = dyn_cast<PackExpansionType>(OldType)) {
3835 // We have a function parameter pack that may need to be expanded.
3836 QualType Pattern = Expansion->getPattern();
3837 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3838 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3839
3840 // Determine whether we should expand the parameter packs.
3841 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003842 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003843 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003844 Unexpanded.data(),
3845 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003846 ShouldExpand,
3847 RetainExpansion,
3848 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003849 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003850 }
3851
3852 if (ShouldExpand) {
3853 // Expand the function parameter pack into multiple, separate
3854 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003855 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003856 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3857 QualType NewType = getDerived().TransformType(Pattern);
3858 if (NewType.isNull())
3859 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003860
Douglas Gregora009b592011-01-07 00:20:55 +00003861 OutParamTypes.push_back(NewType);
3862 if (PVars)
3863 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003864 }
3865
3866 // We're done with the pack expansion.
3867 continue;
3868 }
3869
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003870 // If we're supposed to retain a pack expansion, do so by temporarily
3871 // forgetting the partially-substituted parameter pack.
3872 if (RetainExpansion) {
3873 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3874 QualType NewType = getDerived().TransformType(Pattern);
3875 if (NewType.isNull())
3876 return true;
3877
3878 OutParamTypes.push_back(NewType);
3879 if (PVars)
3880 PVars->push_back(0);
3881 }
Douglas Gregord3731192011-01-10 07:32:04 +00003882
Douglas Gregor603cfb42011-01-05 23:12:31 +00003883 // We'll substitute the parameter now without expanding the pack
3884 // expansion.
3885 OldType = Expansion->getPattern();
3886 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003887 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3888 NewType = getDerived().TransformType(OldType);
3889 } else {
3890 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003891 }
3892
Douglas Gregor603cfb42011-01-05 23:12:31 +00003893 if (NewType.isNull())
3894 return true;
3895
3896 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00003897 NewType = getSema().Context.getPackExpansionType(NewType,
3898 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003899
Douglas Gregora009b592011-01-07 00:20:55 +00003900 OutParamTypes.push_back(NewType);
3901 if (PVars)
3902 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00003903 }
3904
3905 return false;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003906 }
John McCall21ef0fa2010-03-11 09:03:00 +00003907
3908template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003909QualType
John McCalla2becad2009-10-21 00:40:46 +00003910TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003911 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003912 // Transform the parameters and return type.
3913 //
3914 // We instantiate in source order, with the return type first followed by
3915 // the parameters, because users tend to expect this (even if they shouldn't
3916 // rely on it!).
3917 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003918 // When the function has a trailing return type, we instantiate the
3919 // parameters before the return type, since the return type can then refer
3920 // to the parameters themselves (via decltype, sizeof, etc.).
3921 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003922 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003923 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00003924 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003925
Douglas Gregordab60ad2010-10-01 18:44:50 +00003926 QualType ResultType;
3927
3928 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00003929 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3930 TL.getParmArray(),
3931 TL.getNumArgs(),
3932 TL.getTypePtr()->arg_type_begin(),
3933 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003934 return QualType();
3935
3936 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3937 if (ResultType.isNull())
3938 return QualType();
3939 }
3940 else {
3941 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3942 if (ResultType.isNull())
3943 return QualType();
3944
Douglas Gregora009b592011-01-07 00:20:55 +00003945 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3946 TL.getParmArray(),
3947 TL.getNumArgs(),
3948 TL.getTypePtr()->arg_type_begin(),
3949 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003950 return QualType();
3951 }
3952
John McCalla2becad2009-10-21 00:40:46 +00003953 QualType Result = TL.getType();
3954 if (getDerived().AlwaysRebuild() ||
3955 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00003956 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00003957 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3958 Result = getDerived().RebuildFunctionProtoType(ResultType,
3959 ParamTypes.data(),
3960 ParamTypes.size(),
3961 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003962 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00003963 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003964 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00003965 if (Result.isNull())
3966 return QualType();
3967 }
Mike Stump1eb44332009-09-09 15:08:12 +00003968
John McCalla2becad2009-10-21 00:40:46 +00003969 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00003970 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
3971 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003972 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00003973 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3974 NewTL.setArg(i, ParamDecls[i]);
3975
3976 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003977}
Mike Stump1eb44332009-09-09 15:08:12 +00003978
Douglas Gregor577f75a2009-08-04 16:50:30 +00003979template<typename Derived>
3980QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00003981 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003982 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003983 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003984 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3985 if (ResultType.isNull())
3986 return QualType();
3987
3988 QualType Result = TL.getType();
3989 if (getDerived().AlwaysRebuild() ||
3990 ResultType != T->getResultType())
3991 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3992
3993 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00003994 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
3995 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003996 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003997
3998 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003999}
Mike Stump1eb44332009-09-09 15:08:12 +00004000
John McCalled976492009-12-04 22:46:56 +00004001template<typename Derived> QualType
4002TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004003 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004004 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004005 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004006 if (!D)
4007 return QualType();
4008
4009 QualType Result = TL.getType();
4010 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4011 Result = getDerived().RebuildUnresolvedUsingType(D);
4012 if (Result.isNull())
4013 return QualType();
4014 }
4015
4016 // We might get an arbitrary type spec type back. We should at
4017 // least always get a type spec type, though.
4018 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4019 NewTL.setNameLoc(TL.getNameLoc());
4020
4021 return Result;
4022}
4023
Douglas Gregor577f75a2009-08-04 16:50:30 +00004024template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004025QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004026 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004027 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004028 TypedefNameDecl *Typedef
4029 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4030 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004031 if (!Typedef)
4032 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004033
John McCalla2becad2009-10-21 00:40:46 +00004034 QualType Result = TL.getType();
4035 if (getDerived().AlwaysRebuild() ||
4036 Typedef != T->getDecl()) {
4037 Result = getDerived().RebuildTypedefType(Typedef);
4038 if (Result.isNull())
4039 return QualType();
4040 }
Mike Stump1eb44332009-09-09 15:08:12 +00004041
John McCalla2becad2009-10-21 00:40:46 +00004042 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4043 NewTL.setNameLoc(TL.getNameLoc());
4044
4045 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004046}
Mike Stump1eb44332009-09-09 15:08:12 +00004047
Douglas Gregor577f75a2009-08-04 16:50:30 +00004048template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004049QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004050 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004051 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004052 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004053
John McCall60d7b3a2010-08-24 06:29:42 +00004054 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004055 if (E.isInvalid())
4056 return QualType();
4057
John McCalla2becad2009-10-21 00:40:46 +00004058 QualType Result = TL.getType();
4059 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004060 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004061 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004062 if (Result.isNull())
4063 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004064 }
John McCalla2becad2009-10-21 00:40:46 +00004065 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004066
John McCalla2becad2009-10-21 00:40:46 +00004067 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004068 NewTL.setTypeofLoc(TL.getTypeofLoc());
4069 NewTL.setLParenLoc(TL.getLParenLoc());
4070 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004071
4072 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004073}
Mike Stump1eb44332009-09-09 15:08:12 +00004074
4075template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004076QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004077 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004078 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4079 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4080 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004081 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004082
John McCalla2becad2009-10-21 00:40:46 +00004083 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004084 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4085 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004086 if (Result.isNull())
4087 return QualType();
4088 }
Mike Stump1eb44332009-09-09 15:08:12 +00004089
John McCalla2becad2009-10-21 00:40:46 +00004090 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004091 NewTL.setTypeofLoc(TL.getTypeofLoc());
4092 NewTL.setLParenLoc(TL.getLParenLoc());
4093 NewTL.setRParenLoc(TL.getRParenLoc());
4094 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004095
4096 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004097}
Mike Stump1eb44332009-09-09 15:08:12 +00004098
4099template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004100QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004101 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004102 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004103
Douglas Gregor670444e2009-08-04 22:27:00 +00004104 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004105 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004106
John McCall60d7b3a2010-08-24 06:29:42 +00004107 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004108 if (E.isInvalid())
4109 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004110
John McCalla2becad2009-10-21 00:40:46 +00004111 QualType Result = TL.getType();
4112 if (getDerived().AlwaysRebuild() ||
4113 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004114 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004115 if (Result.isNull())
4116 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004117 }
John McCalla2becad2009-10-21 00:40:46 +00004118 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004119
John McCalla2becad2009-10-21 00:40:46 +00004120 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4121 NewTL.setNameLoc(TL.getNameLoc());
4122
4123 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004124}
4125
4126template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004127QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4128 AutoTypeLoc TL) {
4129 const AutoType *T = TL.getTypePtr();
4130 QualType OldDeduced = T->getDeducedType();
4131 QualType NewDeduced;
4132 if (!OldDeduced.isNull()) {
4133 NewDeduced = getDerived().TransformType(OldDeduced);
4134 if (NewDeduced.isNull())
4135 return QualType();
4136 }
4137
4138 QualType Result = TL.getType();
4139 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4140 Result = getDerived().RebuildAutoType(NewDeduced);
4141 if (Result.isNull())
4142 return QualType();
4143 }
4144
4145 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4146 NewTL.setNameLoc(TL.getNameLoc());
4147
4148 return Result;
4149}
4150
4151template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004152QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004153 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004154 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004155 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004156 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4157 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004158 if (!Record)
4159 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004160
John McCalla2becad2009-10-21 00:40:46 +00004161 QualType Result = TL.getType();
4162 if (getDerived().AlwaysRebuild() ||
4163 Record != T->getDecl()) {
4164 Result = getDerived().RebuildRecordType(Record);
4165 if (Result.isNull())
4166 return QualType();
4167 }
Mike Stump1eb44332009-09-09 15:08:12 +00004168
John McCalla2becad2009-10-21 00:40:46 +00004169 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4170 NewTL.setNameLoc(TL.getNameLoc());
4171
4172 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004173}
Mike Stump1eb44332009-09-09 15:08:12 +00004174
4175template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004176QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004177 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004178 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004179 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004180 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4181 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004182 if (!Enum)
4183 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004184
John McCalla2becad2009-10-21 00:40:46 +00004185 QualType Result = TL.getType();
4186 if (getDerived().AlwaysRebuild() ||
4187 Enum != T->getDecl()) {
4188 Result = getDerived().RebuildEnumType(Enum);
4189 if (Result.isNull())
4190 return QualType();
4191 }
Mike Stump1eb44332009-09-09 15:08:12 +00004192
John McCalla2becad2009-10-21 00:40:46 +00004193 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4194 NewTL.setNameLoc(TL.getNameLoc());
4195
4196 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004197}
John McCall7da24312009-09-05 00:15:47 +00004198
John McCall3cb0ebd2010-03-10 03:28:59 +00004199template<typename Derived>
4200QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4201 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004202 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004203 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4204 TL.getTypePtr()->getDecl());
4205 if (!D) return QualType();
4206
4207 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4208 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4209 return T;
4210}
4211
Douglas Gregor577f75a2009-08-04 16:50:30 +00004212template<typename Derived>
4213QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004214 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004215 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004216 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004217}
4218
Mike Stump1eb44332009-09-09 15:08:12 +00004219template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004220QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004221 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004222 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004223 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4224
4225 // Substitute into the replacement type, which itself might involve something
4226 // that needs to be transformed. This only tends to occur with default
4227 // template arguments of template template parameters.
4228 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4229 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4230 if (Replacement.isNull())
4231 return QualType();
4232
4233 // Always canonicalize the replacement type.
4234 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4235 QualType Result
4236 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4237 Replacement);
4238
4239 // Propagate type-source information.
4240 SubstTemplateTypeParmTypeLoc NewTL
4241 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4242 NewTL.setNameLoc(TL.getNameLoc());
4243 return Result;
4244
John McCall49a832b2009-10-18 09:09:24 +00004245}
4246
4247template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004248QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4249 TypeLocBuilder &TLB,
4250 SubstTemplateTypeParmPackTypeLoc TL) {
4251 return TransformTypeSpecType(TLB, TL);
4252}
4253
4254template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004255QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004256 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004257 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004258 const TemplateSpecializationType *T = TL.getTypePtr();
4259
Douglas Gregor1d752d72011-03-02 18:46:51 +00004260 // The nested-name-specifier never matters in a TemplateSpecializationType,
4261 // because we can't have a dependent nested-name-specifier anyway.
4262 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004263 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004264 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4265 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004266 if (Template.isNull())
4267 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004268
John McCall43fed0d2010-11-12 08:19:04 +00004269 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4270}
4271
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004272namespace {
4273 /// \brief Simple iterator that traverses the template arguments in a
4274 /// container that provides a \c getArgLoc() member function.
4275 ///
4276 /// This iterator is intended to be used with the iterator form of
4277 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4278 template<typename ArgLocContainer>
4279 class TemplateArgumentLocContainerIterator {
4280 ArgLocContainer *Container;
4281 unsigned Index;
4282
4283 public:
4284 typedef TemplateArgumentLoc value_type;
4285 typedef TemplateArgumentLoc reference;
4286 typedef int difference_type;
4287 typedef std::input_iterator_tag iterator_category;
4288
4289 class pointer {
4290 TemplateArgumentLoc Arg;
4291
4292 public:
4293 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4294
4295 const TemplateArgumentLoc *operator->() const {
4296 return &Arg;
4297 }
4298 };
4299
4300
4301 TemplateArgumentLocContainerIterator() {}
4302
4303 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4304 unsigned Index)
4305 : Container(&Container), Index(Index) { }
4306
4307 TemplateArgumentLocContainerIterator &operator++() {
4308 ++Index;
4309 return *this;
4310 }
4311
4312 TemplateArgumentLocContainerIterator operator++(int) {
4313 TemplateArgumentLocContainerIterator Old(*this);
4314 ++(*this);
4315 return Old;
4316 }
4317
4318 TemplateArgumentLoc operator*() const {
4319 return Container->getArgLoc(Index);
4320 }
4321
4322 pointer operator->() const {
4323 return pointer(Container->getArgLoc(Index));
4324 }
4325
4326 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004327 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004328 return X.Container == Y.Container && X.Index == Y.Index;
4329 }
4330
4331 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004332 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004333 return !(X == Y);
4334 }
4335 };
4336}
4337
4338
John McCall43fed0d2010-11-12 08:19:04 +00004339template <typename Derived>
4340QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4341 TypeLocBuilder &TLB,
4342 TemplateSpecializationTypeLoc TL,
4343 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004344 TemplateArgumentListInfo NewTemplateArgs;
4345 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4346 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004347 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4348 ArgIterator;
4349 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4350 ArgIterator(TL, TL.getNumArgs()),
4351 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004352 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004353
John McCall833ca992009-10-29 08:12:44 +00004354 // FIXME: maybe don't rebuild if all the template arguments are the same.
4355
4356 QualType Result =
4357 getDerived().RebuildTemplateSpecializationType(Template,
4358 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004359 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004360
4361 if (!Result.isNull()) {
4362 TemplateSpecializationTypeLoc NewTL
4363 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4364 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4365 NewTL.setLAngleLoc(TL.getLAngleLoc());
4366 NewTL.setRAngleLoc(TL.getRAngleLoc());
4367 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4368 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004369 }
Mike Stump1eb44332009-09-09 15:08:12 +00004370
John McCall833ca992009-10-29 08:12:44 +00004371 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004372}
Mike Stump1eb44332009-09-09 15:08:12 +00004373
Douglas Gregora88f09f2011-02-28 17:23:35 +00004374template <typename Derived>
4375QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4376 TypeLocBuilder &TLB,
4377 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004378 TemplateName Template,
4379 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004380 TemplateArgumentListInfo NewTemplateArgs;
4381 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4382 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4383 typedef TemplateArgumentLocContainerIterator<
4384 DependentTemplateSpecializationTypeLoc> ArgIterator;
4385 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4386 ArgIterator(TL, TL.getNumArgs()),
4387 NewTemplateArgs))
4388 return QualType();
4389
4390 // FIXME: maybe don't rebuild if all the template arguments are the same.
4391
4392 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4393 QualType Result
4394 = getSema().Context.getDependentTemplateSpecializationType(
4395 TL.getTypePtr()->getKeyword(),
4396 DTN->getQualifier(),
4397 DTN->getIdentifier(),
4398 NewTemplateArgs);
4399
4400 DependentTemplateSpecializationTypeLoc NewTL
4401 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4402 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004403
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004404 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregora88f09f2011-02-28 17:23:35 +00004405 NewTL.setNameLoc(TL.getNameLoc());
4406 NewTL.setLAngleLoc(TL.getLAngleLoc());
4407 NewTL.setRAngleLoc(TL.getRAngleLoc());
4408 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4409 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4410 return Result;
4411 }
4412
4413 QualType Result
4414 = getDerived().RebuildTemplateSpecializationType(Template,
4415 TL.getNameLoc(),
4416 NewTemplateArgs);
4417
4418 if (!Result.isNull()) {
4419 /// FIXME: Wrap this in an elaborated-type-specifier?
4420 TemplateSpecializationTypeLoc NewTL
4421 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4422 NewTL.setTemplateNameLoc(TL.getNameLoc());
4423 NewTL.setLAngleLoc(TL.getLAngleLoc());
4424 NewTL.setRAngleLoc(TL.getRAngleLoc());
4425 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4426 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4427 }
4428
4429 return Result;
4430}
4431
Mike Stump1eb44332009-09-09 15:08:12 +00004432template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004433QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004434TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004435 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004436 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004437
Douglas Gregor9e876872011-03-01 18:12:44 +00004438 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004439 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004440 if (TL.getQualifierLoc()) {
4441 QualifierLoc
4442 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4443 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004444 return QualType();
4445 }
Mike Stump1eb44332009-09-09 15:08:12 +00004446
John McCall43fed0d2010-11-12 08:19:04 +00004447 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4448 if (NamedT.isNull())
4449 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004450
John McCalla2becad2009-10-21 00:40:46 +00004451 QualType Result = TL.getType();
4452 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004453 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004454 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004455 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004456 T->getKeyword(),
4457 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004458 if (Result.isNull())
4459 return QualType();
4460 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004461
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004462 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004463 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004464 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004465 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004466}
Mike Stump1eb44332009-09-09 15:08:12 +00004467
4468template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004469QualType TreeTransform<Derived>::TransformAttributedType(
4470 TypeLocBuilder &TLB,
4471 AttributedTypeLoc TL) {
4472 const AttributedType *oldType = TL.getTypePtr();
4473 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4474 if (modifiedType.isNull())
4475 return QualType();
4476
4477 QualType result = TL.getType();
4478
4479 // FIXME: dependent operand expressions?
4480 if (getDerived().AlwaysRebuild() ||
4481 modifiedType != oldType->getModifiedType()) {
4482 // TODO: this is really lame; we should really be rebuilding the
4483 // equivalent type from first principles.
4484 QualType equivalentType
4485 = getDerived().TransformType(oldType->getEquivalentType());
4486 if (equivalentType.isNull())
4487 return QualType();
4488 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4489 modifiedType,
4490 equivalentType);
4491 }
4492
4493 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4494 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4495 if (TL.hasAttrOperand())
4496 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4497 if (TL.hasAttrExprOperand())
4498 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4499 else if (TL.hasAttrEnumOperand())
4500 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4501
4502 return result;
4503}
4504
4505template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004506QualType
4507TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4508 ParenTypeLoc TL) {
4509 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4510 if (Inner.isNull())
4511 return QualType();
4512
4513 QualType Result = TL.getType();
4514 if (getDerived().AlwaysRebuild() ||
4515 Inner != TL.getInnerLoc().getType()) {
4516 Result = getDerived().RebuildParenType(Inner);
4517 if (Result.isNull())
4518 return QualType();
4519 }
4520
4521 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4522 NewTL.setLParenLoc(TL.getLParenLoc());
4523 NewTL.setRParenLoc(TL.getRParenLoc());
4524 return Result;
4525}
4526
4527template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004528QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004529 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004530 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004531
Douglas Gregor2494dd02011-03-01 01:34:45 +00004532 NestedNameSpecifierLoc QualifierLoc
4533 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4534 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004535 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004536
John McCall33500952010-06-11 00:33:02 +00004537 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004538 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCall33500952010-06-11 00:33:02 +00004539 TL.getKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004540 QualifierLoc,
4541 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004542 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004543 if (Result.isNull())
4544 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004545
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004546 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4547 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004548 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4549
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004550 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4551 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004552 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004553 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004554 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4555 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004556 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004557 NewTL.setNameLoc(TL.getNameLoc());
4558 }
John McCalla2becad2009-10-21 00:40:46 +00004559 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004560}
Mike Stump1eb44332009-09-09 15:08:12 +00004561
Douglas Gregor577f75a2009-08-04 16:50:30 +00004562template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004563QualType TreeTransform<Derived>::
4564 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004565 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004566 NestedNameSpecifierLoc QualifierLoc;
4567 if (TL.getQualifierLoc()) {
4568 QualifierLoc
4569 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4570 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004571 return QualType();
4572 }
4573
John McCall43fed0d2010-11-12 08:19:04 +00004574 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004575 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004576}
4577
4578template<typename Derived>
4579QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004580TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4581 DependentTemplateSpecializationTypeLoc TL,
4582 NestedNameSpecifierLoc QualifierLoc) {
4583 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4584
4585 TemplateArgumentListInfo NewTemplateArgs;
4586 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4587 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4588
4589 typedef TemplateArgumentLocContainerIterator<
4590 DependentTemplateSpecializationTypeLoc> ArgIterator;
4591 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4592 ArgIterator(TL, TL.getNumArgs()),
4593 NewTemplateArgs))
4594 return QualType();
4595
4596 QualType Result
4597 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4598 QualifierLoc,
4599 T->getIdentifier(),
4600 TL.getNameLoc(),
4601 NewTemplateArgs);
4602 if (Result.isNull())
4603 return QualType();
4604
4605 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4606 QualType NamedT = ElabT->getNamedType();
4607
4608 // Copy information relevant to the template specialization.
4609 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004610 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004611 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004612 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4613 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004614 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004615 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004616
4617 // Copy information relevant to the elaborated type.
4618 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4619 NewTL.setKeywordLoc(TL.getKeywordLoc());
4620 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004621 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4622 DependentTemplateSpecializationTypeLoc SpecTL
4623 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor944cdae2011-03-07 15:13:34 +00004624 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004625 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004626 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004627 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4628 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004629 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004630 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004631 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004632 TemplateSpecializationTypeLoc SpecTL
4633 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004634 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004635 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4636 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004637 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004638 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004639 }
4640 return Result;
4641}
4642
4643template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004644QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4645 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004646 QualType Pattern
4647 = getDerived().TransformType(TLB, TL.getPatternLoc());
4648 if (Pattern.isNull())
4649 return QualType();
4650
4651 QualType Result = TL.getType();
4652 if (getDerived().AlwaysRebuild() ||
4653 Pattern != TL.getPatternLoc().getType()) {
4654 Result = getDerived().RebuildPackExpansionType(Pattern,
4655 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004656 TL.getEllipsisLoc(),
4657 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004658 if (Result.isNull())
4659 return QualType();
4660 }
4661
4662 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4663 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4664 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004665}
4666
4667template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004668QualType
4669TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004670 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004671 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004672 TLB.pushFullCopy(TL);
4673 return TL.getType();
4674}
4675
4676template<typename Derived>
4677QualType
4678TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004679 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004680 // ObjCObjectType is never dependent.
4681 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004682 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004683}
Mike Stump1eb44332009-09-09 15:08:12 +00004684
4685template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004686QualType
4687TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004688 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004689 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004690 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004691 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004692}
4693
Douglas Gregor577f75a2009-08-04 16:50:30 +00004694//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004695// Statement transformation
4696//===----------------------------------------------------------------------===//
4697template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004698StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004699TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004700 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004701}
4702
4703template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004704StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004705TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4706 return getDerived().TransformCompoundStmt(S, false);
4707}
4708
4709template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004710StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004711TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004712 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004713 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004714 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004715 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004716 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4717 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004718 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004719 if (Result.isInvalid()) {
4720 // Immediately fail if this was a DeclStmt, since it's very
4721 // likely that this will cause problems for future statements.
4722 if (isa<DeclStmt>(*B))
4723 return StmtError();
4724
4725 // Otherwise, just keep processing substatements and fail later.
4726 SubStmtInvalid = true;
4727 continue;
4728 }
Mike Stump1eb44332009-09-09 15:08:12 +00004729
Douglas Gregor43959a92009-08-20 07:17:43 +00004730 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4731 Statements.push_back(Result.takeAs<Stmt>());
4732 }
Mike Stump1eb44332009-09-09 15:08:12 +00004733
John McCall7114cba2010-08-27 19:56:05 +00004734 if (SubStmtInvalid)
4735 return StmtError();
4736
Douglas Gregor43959a92009-08-20 07:17:43 +00004737 if (!getDerived().AlwaysRebuild() &&
4738 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004739 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004740
4741 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4742 move_arg(Statements),
4743 S->getRBracLoc(),
4744 IsStmtExpr);
4745}
Mike Stump1eb44332009-09-09 15:08:12 +00004746
Douglas Gregor43959a92009-08-20 07:17:43 +00004747template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004748StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004749TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004750 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004751 {
4752 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004753 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004754
Eli Friedman264c1f82009-11-19 03:14:00 +00004755 // Transform the left-hand case value.
4756 LHS = getDerived().TransformExpr(S->getLHS());
4757 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004758 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004759
Eli Friedman264c1f82009-11-19 03:14:00 +00004760 // Transform the right-hand case value (for the GNU case-range extension).
4761 RHS = getDerived().TransformExpr(S->getRHS());
4762 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004763 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004764 }
Mike Stump1eb44332009-09-09 15:08:12 +00004765
Douglas Gregor43959a92009-08-20 07:17:43 +00004766 // Build the case statement.
4767 // Case statements are always rebuilt so that they will attached to their
4768 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004769 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004770 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004771 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004772 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004773 S->getColonLoc());
4774 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004775 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004776
Douglas Gregor43959a92009-08-20 07:17:43 +00004777 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004778 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004779 if (SubStmt.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 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004783 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004784}
4785
4786template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004787StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004788TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004789 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00004790 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004791 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004792 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004793
Douglas Gregor43959a92009-08-20 07:17:43 +00004794 // Default statements are always rebuilt
4795 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004796 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004797}
Mike Stump1eb44332009-09-09 15:08:12 +00004798
Douglas Gregor43959a92009-08-20 07:17:43 +00004799template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004800StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004801TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004802 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004803 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004804 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004805
Chris Lattner57ad3782011-02-17 20:34:02 +00004806 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4807 S->getDecl());
4808 if (!LD)
4809 return StmtError();
4810
4811
Douglas Gregor43959a92009-08-20 07:17:43 +00004812 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00004813 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00004814 cast<LabelDecl>(LD), SourceLocation(),
4815 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004816}
Mike Stump1eb44332009-09-09 15:08:12 +00004817
Douglas Gregor43959a92009-08-20 07:17:43 +00004818template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004819StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004820TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004821 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004822 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004823 VarDecl *ConditionVar = 0;
4824 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004825 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004826 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004827 getDerived().TransformDefinition(
4828 S->getConditionVariable()->getLocation(),
4829 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004830 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004831 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004832 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004833 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004834
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004835 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004836 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004837
4838 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004839 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004840 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4841 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004842 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004843 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004844
John McCall9ae2f072010-08-23 23:25:46 +00004845 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004846 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004847 }
Sean Huntc3021132010-05-05 15:23:54 +00004848
John McCall9ae2f072010-08-23 23:25:46 +00004849 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4850 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004851 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004852
Douglas Gregor43959a92009-08-20 07:17:43 +00004853 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004854 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00004855 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004856 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004857
Douglas Gregor43959a92009-08-20 07:17:43 +00004858 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004859 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00004860 if (Else.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 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004864 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004865 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004866 Then.get() == S->getThen() &&
4867 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00004868 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004869
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004870 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00004871 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00004872 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004873}
4874
4875template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004876StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004877TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004878 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00004879 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00004880 VarDecl *ConditionVar = 0;
4881 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004882 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00004883 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004884 getDerived().TransformDefinition(
4885 S->getConditionVariable()->getLocation(),
4886 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00004887 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004888 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004889 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00004890 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004891
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004892 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004893 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004894 }
Mike Stump1eb44332009-09-09 15:08:12 +00004895
Douglas Gregor43959a92009-08-20 07:17:43 +00004896 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004897 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00004898 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00004899 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00004900 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004901 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004902
Douglas Gregor43959a92009-08-20 07:17:43 +00004903 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004904 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004905 if (Body.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 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00004909 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4910 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004911}
Mike Stump1eb44332009-09-09 15:08:12 +00004912
Douglas Gregor43959a92009-08-20 07:17:43 +00004913template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004914StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004915TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004916 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004917 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00004918 VarDecl *ConditionVar = 0;
4919 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004920 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00004921 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004922 getDerived().TransformDefinition(
4923 S->getConditionVariable()->getLocation(),
4924 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00004925 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004926 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004927 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00004928 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004929
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004930 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004931 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004932
4933 if (S->getCond()) {
4934 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004935 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4936 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004937 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004938 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00004939 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004940 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004941 }
Mike Stump1eb44332009-09-09 15:08:12 +00004942
John McCall9ae2f072010-08-23 23:25:46 +00004943 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4944 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004945 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004946
Douglas Gregor43959a92009-08-20 07:17:43 +00004947 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004948 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004949 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004950 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004951
Douglas Gregor43959a92009-08-20 07:17:43 +00004952 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004953 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004954 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004955 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00004956 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004957
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004958 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00004959 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004960}
Mike Stump1eb44332009-09-09 15:08:12 +00004961
Douglas Gregor43959a92009-08-20 07:17:43 +00004962template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004963StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004964TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004965 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004966 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004967 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004968 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004969
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004970 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004971 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004972 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004973 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004974
Douglas Gregor43959a92009-08-20 07:17:43 +00004975 if (!getDerived().AlwaysRebuild() &&
4976 Cond.get() == S->getCond() &&
4977 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004978 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004979
John McCall9ae2f072010-08-23 23:25:46 +00004980 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4981 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004982 S->getRParenLoc());
4983}
Mike Stump1eb44332009-09-09 15:08:12 +00004984
Douglas Gregor43959a92009-08-20 07:17:43 +00004985template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004986StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004987TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004988 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00004989 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00004990 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004991 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004992
Douglas Gregor43959a92009-08-20 07:17:43 +00004993 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004994 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004995 VarDecl *ConditionVar = 0;
4996 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004997 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004998 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004999 getDerived().TransformDefinition(
5000 S->getConditionVariable()->getLocation(),
5001 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005002 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005003 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005004 } else {
5005 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005006
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005007 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005008 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005009
5010 if (S->getCond()) {
5011 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005012 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5013 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005014 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005015 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005016
John McCall9ae2f072010-08-23 23:25:46 +00005017 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005018 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005019 }
Mike Stump1eb44332009-09-09 15:08:12 +00005020
John McCall9ae2f072010-08-23 23:25:46 +00005021 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5022 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005023 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005024
Douglas Gregor43959a92009-08-20 07:17:43 +00005025 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005026 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005027 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005028 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005029
John McCall9ae2f072010-08-23 23:25:46 +00005030 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5031 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005032 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005033
Douglas Gregor43959a92009-08-20 07:17:43 +00005034 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005035 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005036 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005037 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005038
Douglas Gregor43959a92009-08-20 07:17:43 +00005039 if (!getDerived().AlwaysRebuild() &&
5040 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005041 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005042 Inc.get() == S->getInc() &&
5043 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005044 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005045
Douglas Gregor43959a92009-08-20 07:17:43 +00005046 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005047 Init.get(), FullCond, ConditionVar,
5048 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005049}
5050
5051template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005052StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005053TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005054 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5055 S->getLabel());
5056 if (!LD)
5057 return StmtError();
5058
Douglas Gregor43959a92009-08-20 07:17:43 +00005059 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005060 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005061 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005062}
5063
5064template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005065StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005066TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005067 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005068 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005069 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005070
Douglas Gregor43959a92009-08-20 07:17:43 +00005071 if (!getDerived().AlwaysRebuild() &&
5072 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005073 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005074
5075 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005076 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005077}
5078
5079template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005080StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005081TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005082 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005083}
Mike Stump1eb44332009-09-09 15:08:12 +00005084
Douglas Gregor43959a92009-08-20 07:17:43 +00005085template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005086StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005087TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005088 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005089}
Mike Stump1eb44332009-09-09 15:08:12 +00005090
Douglas Gregor43959a92009-08-20 07:17:43 +00005091template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005092StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005093TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005094 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005095 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005096 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005097
Mike Stump1eb44332009-09-09 15:08:12 +00005098 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005099 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005100 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005101}
Mike Stump1eb44332009-09-09 15:08:12 +00005102
Douglas Gregor43959a92009-08-20 07:17:43 +00005103template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005104StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005105TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005106 bool DeclChanged = false;
5107 llvm::SmallVector<Decl *, 4> Decls;
5108 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5109 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005110 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5111 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005112 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005113 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005114
Douglas Gregor43959a92009-08-20 07:17:43 +00005115 if (Transformed != *D)
5116 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005117
Douglas Gregor43959a92009-08-20 07:17:43 +00005118 Decls.push_back(Transformed);
5119 }
Mike Stump1eb44332009-09-09 15:08:12 +00005120
Douglas Gregor43959a92009-08-20 07:17:43 +00005121 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005122 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005123
5124 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005125 S->getStartLoc(), S->getEndLoc());
5126}
Mike Stump1eb44332009-09-09 15:08:12 +00005127
Douglas Gregor43959a92009-08-20 07:17:43 +00005128template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005129StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005130TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005131
John McCallca0408f2010-08-23 06:44:23 +00005132 ASTOwningVector<Expr*> Constraints(getSema());
5133 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005134 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005135
John McCall60d7b3a2010-08-24 06:29:42 +00005136 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005137 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005138
5139 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005140
Anders Carlsson703e3942010-01-24 05:50:09 +00005141 // Go through the outputs.
5142 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005143 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005144
Anders Carlsson703e3942010-01-24 05:50:09 +00005145 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005146 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005147
Anders Carlsson703e3942010-01-24 05:50:09 +00005148 // Transform the output expr.
5149 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005150 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005151 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005152 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005153
Anders Carlsson703e3942010-01-24 05:50:09 +00005154 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005155
John McCall9ae2f072010-08-23 23:25:46 +00005156 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005157 }
Sean Huntc3021132010-05-05 15:23:54 +00005158
Anders Carlsson703e3942010-01-24 05:50:09 +00005159 // Go through the inputs.
5160 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005161 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005162
Anders Carlsson703e3942010-01-24 05:50:09 +00005163 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005164 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005165
Anders Carlsson703e3942010-01-24 05:50:09 +00005166 // Transform the input expr.
5167 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005168 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005169 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005170 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005171
Anders Carlsson703e3942010-01-24 05:50:09 +00005172 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005173
John McCall9ae2f072010-08-23 23:25:46 +00005174 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005175 }
Sean Huntc3021132010-05-05 15:23:54 +00005176
Anders Carlsson703e3942010-01-24 05:50:09 +00005177 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005178 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005179
5180 // Go through the clobbers.
5181 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005182 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005183
5184 // No need to transform the asm string literal.
5185 AsmString = SemaRef.Owned(S->getAsmString());
5186
5187 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5188 S->isSimple(),
5189 S->isVolatile(),
5190 S->getNumOutputs(),
5191 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005192 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005193 move_arg(Constraints),
5194 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005195 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005196 move_arg(Clobbers),
5197 S->getRParenLoc(),
5198 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005199}
5200
5201
5202template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005203StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005204TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005205 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005206 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005207 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005208 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005209
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005210 // Transform the @catch statements (if present).
5211 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005212 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005213 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005214 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005215 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005216 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005217 if (Catch.get() != S->getCatchStmt(I))
5218 AnyCatchChanged = true;
5219 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005220 }
Sean Huntc3021132010-05-05 15:23:54 +00005221
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005222 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005223 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005224 if (S->getFinallyStmt()) {
5225 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5226 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005227 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005228 }
5229
5230 // If nothing changed, just retain this statement.
5231 if (!getDerived().AlwaysRebuild() &&
5232 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005233 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005234 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005235 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005236
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005237 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005238 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5239 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005240}
Mike Stump1eb44332009-09-09 15:08:12 +00005241
Douglas Gregor43959a92009-08-20 07:17:43 +00005242template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005243StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005244TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005245 // Transform the @catch parameter, if there is one.
5246 VarDecl *Var = 0;
5247 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5248 TypeSourceInfo *TSInfo = 0;
5249 if (FromVar->getTypeSourceInfo()) {
5250 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5251 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005252 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005253 }
Sean Huntc3021132010-05-05 15:23:54 +00005254
Douglas Gregorbe270a02010-04-26 17:57:08 +00005255 QualType T;
5256 if (TSInfo)
5257 T = TSInfo->getType();
5258 else {
5259 T = getDerived().TransformType(FromVar->getType());
5260 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005261 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005262 }
Sean Huntc3021132010-05-05 15:23:54 +00005263
Douglas Gregorbe270a02010-04-26 17:57:08 +00005264 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5265 if (!Var)
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
John McCall60d7b3a2010-08-24 06:29:42 +00005269 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005270 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005271 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005272
5273 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005274 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005275 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005276}
Mike Stump1eb44332009-09-09 15:08:12 +00005277
Douglas Gregor43959a92009-08-20 07:17:43 +00005278template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005279StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005280TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005281 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005282 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005283 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005284 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005285
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005286 // If nothing changed, just retain this statement.
5287 if (!getDerived().AlwaysRebuild() &&
5288 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005289 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005290
5291 // Build a new statement.
5292 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005293 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005294}
Mike Stump1eb44332009-09-09 15:08:12 +00005295
Douglas Gregor43959a92009-08-20 07:17:43 +00005296template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005297StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005298TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005299 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005300 if (S->getThrowExpr()) {
5301 Operand = getDerived().TransformExpr(S->getThrowExpr());
5302 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005303 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005304 }
Sean Huntc3021132010-05-05 15:23:54 +00005305
Douglas Gregord1377b22010-04-22 21:44:01 +00005306 if (!getDerived().AlwaysRebuild() &&
5307 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005308 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005309
John McCall9ae2f072010-08-23 23:25:46 +00005310 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005311}
Mike Stump1eb44332009-09-09 15:08:12 +00005312
Douglas Gregor43959a92009-08-20 07:17:43 +00005313template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005314StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005315TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005316 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005317 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005318 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005319 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005320 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005321
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005322 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005323 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005324 if (Body.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 // If nothing change, just retain the current statement.
5328 if (!getDerived().AlwaysRebuild() &&
5329 Object.get() == S->getSynchExpr() &&
5330 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005331 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005332
5333 // Build a new statement.
5334 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005335 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005336}
5337
5338template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005339StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005340TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005341 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005342 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005343 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005344 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005345 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005346
Douglas Gregorc3203e72010-04-22 23:10:45 +00005347 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005348 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005349 if (Collection.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 body.
John McCall60d7b3a2010-08-24 06:29:42 +00005353 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005354 if (Body.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 // If nothing changed, just retain this statement.
5358 if (!getDerived().AlwaysRebuild() &&
5359 Element.get() == S->getElement() &&
5360 Collection.get() == S->getCollection() &&
5361 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005362 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005363
Douglas Gregorc3203e72010-04-22 23:10:45 +00005364 // Build a new statement.
5365 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5366 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005367 Element.get(),
5368 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005369 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005370 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005371}
5372
5373
5374template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005375StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005376TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5377 // Transform the exception declaration, if any.
5378 VarDecl *Var = 0;
5379 if (S->getExceptionDecl()) {
5380 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005381 TypeSourceInfo *T = getDerived().TransformType(
5382 ExceptionDecl->getTypeSourceInfo());
5383 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005384 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005385
Douglas Gregor83cb9422010-09-09 17:09:21 +00005386 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005387 ExceptionDecl->getInnerLocStart(),
5388 ExceptionDecl->getLocation(),
5389 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005390 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005391 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005392 }
Mike Stump1eb44332009-09-09 15:08:12 +00005393
Douglas Gregor43959a92009-08-20 07:17:43 +00005394 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005395 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005396 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005397 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005398
Douglas Gregor43959a92009-08-20 07:17:43 +00005399 if (!getDerived().AlwaysRebuild() &&
5400 !Var &&
5401 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005402 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005403
5404 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5405 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005406 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005407}
Mike Stump1eb44332009-09-09 15:08:12 +00005408
Douglas Gregor43959a92009-08-20 07:17:43 +00005409template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005410StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005411TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5412 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005413 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005414 = getDerived().TransformCompoundStmt(S->getTryBlock());
5415 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005416 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005417
Douglas Gregor43959a92009-08-20 07:17:43 +00005418 // Transform the handlers.
5419 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005420 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005421 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005422 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005423 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5424 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005425 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005426
Douglas Gregor43959a92009-08-20 07:17:43 +00005427 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5428 Handlers.push_back(Handler.takeAs<Stmt>());
5429 }
Mike Stump1eb44332009-09-09 15:08:12 +00005430
Douglas Gregor43959a92009-08-20 07:17:43 +00005431 if (!getDerived().AlwaysRebuild() &&
5432 TryBlock.get() == S->getTryBlock() &&
5433 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005434 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005435
John McCall9ae2f072010-08-23 23:25:46 +00005436 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005437 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005438}
Mike Stump1eb44332009-09-09 15:08:12 +00005439
Richard Smithad762fc2011-04-14 22:09:26 +00005440template<typename Derived>
5441StmtResult
5442TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5443 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5444 if (Range.isInvalid())
5445 return StmtError();
5446
5447 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5448 if (BeginEnd.isInvalid())
5449 return StmtError();
5450
5451 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5452 if (Cond.isInvalid())
5453 return StmtError();
5454
5455 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5456 if (Inc.isInvalid())
5457 return StmtError();
5458
5459 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5460 if (LoopVar.isInvalid())
5461 return StmtError();
5462
5463 StmtResult NewStmt = S;
5464 if (getDerived().AlwaysRebuild() ||
5465 Range.get() != S->getRangeStmt() ||
5466 BeginEnd.get() != S->getBeginEndStmt() ||
5467 Cond.get() != S->getCond() ||
5468 Inc.get() != S->getInc() ||
5469 LoopVar.get() != S->getLoopVarStmt())
5470 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5471 S->getColonLoc(), Range.get(),
5472 BeginEnd.get(), Cond.get(),
5473 Inc.get(), LoopVar.get(),
5474 S->getRParenLoc());
5475
5476 StmtResult Body = getDerived().TransformStmt(S->getBody());
5477 if (Body.isInvalid())
5478 return StmtError();
5479
5480 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5481 // it now so we have a new statement to attach the body to.
5482 if (Body.get() != S->getBody() && NewStmt.get() == S)
5483 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5484 S->getColonLoc(), Range.get(),
5485 BeginEnd.get(), Cond.get(),
5486 Inc.get(), LoopVar.get(),
5487 S->getRParenLoc());
5488
5489 if (NewStmt.get() == S)
5490 return SemaRef.Owned(S);
5491
5492 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5493}
5494
John Wiegley28bbe4b2011-04-28 01:08:34 +00005495template<typename Derived>
5496StmtResult
5497TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5498 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5499 if(TryBlock.isInvalid()) return StmtError();
5500
5501 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5502 if(!getDerived().AlwaysRebuild() &&
5503 TryBlock.get() == S->getTryBlock() &&
5504 Handler.get() == S->getHandler())
5505 return SemaRef.Owned(S);
5506
5507 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5508 S->getTryLoc(),
5509 TryBlock.take(),
5510 Handler.take());
5511}
5512
5513template<typename Derived>
5514StmtResult
5515TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5516 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5517 if(Block.isInvalid()) return StmtError();
5518
5519 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5520 Block.take());
5521}
5522
5523template<typename Derived>
5524StmtResult
5525TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5526 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5527 if(FilterExpr.isInvalid()) return StmtError();
5528
5529 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5530 if(Block.isInvalid()) return StmtError();
5531
5532 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5533 FilterExpr.take(),
5534 Block.take());
5535}
5536
5537template<typename Derived>
5538StmtResult
5539TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5540 if(isa<SEHFinallyStmt>(Handler))
5541 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5542 else
5543 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5544}
5545
Douglas Gregor43959a92009-08-20 07:17:43 +00005546//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005547// Expression transformation
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>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005552 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005553}
Mike Stump1eb44332009-09-09 15:08:12 +00005554
5555template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005556ExprResult
John McCall454feb92009-12-08 09:21:05 +00005557TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005558 NestedNameSpecifierLoc QualifierLoc;
5559 if (E->getQualifierLoc()) {
5560 QualifierLoc
5561 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5562 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005563 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005564 }
John McCalldbd872f2009-12-08 09:08:17 +00005565
5566 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005567 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5568 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005569 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005570 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005571
John McCallec8045d2010-08-17 21:27:17 +00005572 DeclarationNameInfo NameInfo = E->getNameInfo();
5573 if (NameInfo.getName()) {
5574 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5575 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005576 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005577 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005578
5579 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005580 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005581 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005582 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005583 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005584
5585 // Mark it referenced in the new context regardless.
5586 // FIXME: this is a bit instantiation-specific.
5587 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5588
John McCall3fa5cae2010-10-26 07:05:15 +00005589 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005590 }
John McCalldbd872f2009-12-08 09:08:17 +00005591
5592 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005593 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005594 TemplateArgs = &TransArgs;
5595 TransArgs.setLAngleLoc(E->getLAngleLoc());
5596 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005597 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5598 E->getNumTemplateArgs(),
5599 TransArgs))
5600 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005601 }
5602
Douglas Gregor40d96a62011-02-28 21:54:11 +00005603 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5604 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005605}
Mike Stump1eb44332009-09-09 15:08:12 +00005606
Douglas Gregorb98b1992009-08-11 05:31:07 +00005607template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005608ExprResult
John McCall454feb92009-12-08 09:21:05 +00005609TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005610 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005611}
Mike Stump1eb44332009-09-09 15:08:12 +00005612
Douglas Gregorb98b1992009-08-11 05:31:07 +00005613template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005614ExprResult
John McCall454feb92009-12-08 09:21:05 +00005615TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005616 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005617}
Mike Stump1eb44332009-09-09 15:08:12 +00005618
Douglas Gregorb98b1992009-08-11 05:31:07 +00005619template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005620ExprResult
John McCall454feb92009-12-08 09:21:05 +00005621TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005622 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005623}
Mike Stump1eb44332009-09-09 15:08:12 +00005624
Douglas Gregorb98b1992009-08-11 05:31:07 +00005625template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005626ExprResult
John McCall454feb92009-12-08 09:21:05 +00005627TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005628 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005629}
Mike Stump1eb44332009-09-09 15:08:12 +00005630
Douglas Gregorb98b1992009-08-11 05:31:07 +00005631template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005632ExprResult
John McCall454feb92009-12-08 09:21:05 +00005633TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005634 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005635}
5636
5637template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005638ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00005639TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5640 ExprResult ControllingExpr =
5641 getDerived().TransformExpr(E->getControllingExpr());
5642 if (ControllingExpr.isInvalid())
5643 return ExprError();
5644
5645 llvm::SmallVector<Expr *, 4> AssocExprs;
5646 llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5647 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5648 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5649 if (TS) {
5650 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5651 if (!AssocType)
5652 return ExprError();
5653 AssocTypes.push_back(AssocType);
5654 } else {
5655 AssocTypes.push_back(0);
5656 }
5657
5658 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5659 if (AssocExpr.isInvalid())
5660 return ExprError();
5661 AssocExprs.push_back(AssocExpr.release());
5662 }
5663
5664 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5665 E->getDefaultLoc(),
5666 E->getRParenLoc(),
5667 ControllingExpr.release(),
5668 AssocTypes.data(),
5669 AssocExprs.data(),
5670 E->getNumAssocs());
5671}
5672
5673template<typename Derived>
5674ExprResult
John McCall454feb92009-12-08 09:21:05 +00005675TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005676 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005677 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005678 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005679
Douglas Gregorb98b1992009-08-11 05:31:07 +00005680 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005681 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005682
John McCall9ae2f072010-08-23 23:25:46 +00005683 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005684 E->getRParen());
5685}
5686
Mike Stump1eb44332009-09-09 15:08:12 +00005687template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005688ExprResult
John McCall454feb92009-12-08 09:21:05 +00005689TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005690 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005691 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005692 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005693
Douglas Gregorb98b1992009-08-11 05:31:07 +00005694 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005695 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005696
Douglas Gregorb98b1992009-08-11 05:31:07 +00005697 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5698 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005699 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005700}
Mike Stump1eb44332009-09-09 15:08:12 +00005701
Douglas Gregorb98b1992009-08-11 05:31:07 +00005702template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005703ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005704TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5705 // Transform the type.
5706 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5707 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005708 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005709
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005710 // Transform all of the components into components similar to what the
5711 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005712 // FIXME: It would be slightly more efficient in the non-dependent case to
5713 // just map FieldDecls, rather than requiring the rebuilder to look for
5714 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005715 // template code that we don't care.
5716 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005717 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005718 typedef OffsetOfExpr::OffsetOfNode Node;
5719 llvm::SmallVector<Component, 4> Components;
5720 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5721 const Node &ON = E->getComponent(I);
5722 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005723 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00005724 Comp.LocStart = ON.getSourceRange().getBegin();
5725 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005726 switch (ON.getKind()) {
5727 case Node::Array: {
5728 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005729 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005730 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005731 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005732
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005733 ExprChanged = ExprChanged || Index.get() != FromIndex;
5734 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005735 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005736 break;
5737 }
Sean Huntc3021132010-05-05 15:23:54 +00005738
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005739 case Node::Field:
5740 case Node::Identifier:
5741 Comp.isBrackets = false;
5742 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005743 if (!Comp.U.IdentInfo)
5744 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005745
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005746 break;
Sean Huntc3021132010-05-05 15:23:54 +00005747
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005748 case Node::Base:
5749 // Will be recomputed during the rebuild.
5750 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005751 }
Sean Huntc3021132010-05-05 15:23:54 +00005752
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005753 Components.push_back(Comp);
5754 }
Sean Huntc3021132010-05-05 15:23:54 +00005755
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005756 // If nothing changed, retain the existing expression.
5757 if (!getDerived().AlwaysRebuild() &&
5758 Type == E->getTypeSourceInfo() &&
5759 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005760 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00005761
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005762 // Build a new offsetof expression.
5763 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5764 Components.data(), Components.size(),
5765 E->getRParenLoc());
5766}
5767
5768template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005769ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00005770TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5771 assert(getDerived().AlreadyTransformed(E->getType()) &&
5772 "opaque value expression requires transformation");
5773 return SemaRef.Owned(E);
5774}
5775
5776template<typename Derived>
5777ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005778TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5779 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005780 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00005781 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00005782
John McCalla93c9342009-12-07 02:54:59 +00005783 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00005784 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005785 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005786
John McCall5ab75172009-11-04 07:28:41 +00005787 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00005788 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005789
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005790 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5791 E->getKind(),
5792 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005793 }
Mike Stump1eb44332009-09-09 15:08:12 +00005794
John McCall60d7b3a2010-08-24 06:29:42 +00005795 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00005796 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005797 // C++0x [expr.sizeof]p1:
5798 // The operand is either an expression, which is an unevaluated operand
5799 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00005800 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005801
Douglas Gregorb98b1992009-08-11 05:31:07 +00005802 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5803 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005804 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005805
Douglas Gregorb98b1992009-08-11 05:31:07 +00005806 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005807 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005808 }
Mike Stump1eb44332009-09-09 15:08:12 +00005809
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005810 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5811 E->getOperatorLoc(),
5812 E->getKind(),
5813 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005814}
Mike Stump1eb44332009-09-09 15:08:12 +00005815
Douglas Gregorb98b1992009-08-11 05:31:07 +00005816template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005817ExprResult
John McCall454feb92009-12-08 09:21:05 +00005818TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005819 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005820 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005821 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005822
John McCall60d7b3a2010-08-24 06:29:42 +00005823 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005824 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005825 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005826
5827
Douglas Gregorb98b1992009-08-11 05:31:07 +00005828 if (!getDerived().AlwaysRebuild() &&
5829 LHS.get() == E->getLHS() &&
5830 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005831 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005832
John McCall9ae2f072010-08-23 23:25:46 +00005833 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005834 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005835 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005836 E->getRBracketLoc());
5837}
Mike Stump1eb44332009-09-09 15:08:12 +00005838
5839template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005840ExprResult
John McCall454feb92009-12-08 09:21:05 +00005841TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005842 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00005843 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005844 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005845 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005846
5847 // Transform arguments.
5848 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005849 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005850 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5851 &ArgChanged))
5852 return ExprError();
5853
Douglas Gregorb98b1992009-08-11 05:31:07 +00005854 if (!getDerived().AlwaysRebuild() &&
5855 Callee.get() == E->getCallee() &&
5856 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005857 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005858
Douglas Gregorb98b1992009-08-11 05:31:07 +00005859 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00005860 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005861 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00005862 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005863 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005864 E->getRParenLoc());
5865}
Mike Stump1eb44332009-09-09 15:08:12 +00005866
5867template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005868ExprResult
John McCall454feb92009-12-08 09:21:05 +00005869TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005870 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005871 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005872 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005873
Douglas Gregor40d96a62011-02-28 21:54:11 +00005874 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005875 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005876 QualifierLoc
5877 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5878
5879 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005880 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005881 }
Mike Stump1eb44332009-09-09 15:08:12 +00005882
Eli Friedmanf595cc42009-12-04 06:40:45 +00005883 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005884 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5885 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005886 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00005887 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005888
John McCall6bb80172010-03-30 21:47:33 +00005889 NamedDecl *FoundDecl = E->getFoundDecl();
5890 if (FoundDecl == E->getMemberDecl()) {
5891 FoundDecl = Member;
5892 } else {
5893 FoundDecl = cast_or_null<NamedDecl>(
5894 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5895 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00005896 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00005897 }
5898
Douglas Gregorb98b1992009-08-11 05:31:07 +00005899 if (!getDerived().AlwaysRebuild() &&
5900 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005901 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005902 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00005903 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00005904 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00005905
Anders Carlsson1f240322009-12-22 05:24:09 +00005906 // Mark it referenced in the new context regardless.
5907 // FIXME: this is a bit instantiation-specific.
5908 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00005909 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00005910 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005911
John McCalld5532b62009-11-23 01:53:49 +00005912 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00005913 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00005914 TransArgs.setLAngleLoc(E->getLAngleLoc());
5915 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005916 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5917 E->getNumTemplateArgs(),
5918 TransArgs))
5919 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005920 }
Sean Huntc3021132010-05-05 15:23:54 +00005921
Douglas Gregorb98b1992009-08-11 05:31:07 +00005922 // FIXME: Bogus source location for the operator
5923 SourceLocation FakeOperatorLoc
5924 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5925
John McCallc2233c52010-01-15 08:34:02 +00005926 // FIXME: to do this check properly, we will need to preserve the
5927 // first-qualifier-in-scope here, just in case we had a dependent
5928 // base (and therefore couldn't do the check) and a
5929 // nested-name-qualifier (and therefore could do the lookup).
5930 NamedDecl *FirstQualifierInScope = 0;
5931
John McCall9ae2f072010-08-23 23:25:46 +00005932 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005933 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00005934 QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00005935 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005936 Member,
John McCall6bb80172010-03-30 21:47:33 +00005937 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00005938 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00005939 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00005940 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005941}
Mike Stump1eb44332009-09-09 15:08:12 +00005942
Douglas Gregorb98b1992009-08-11 05:31:07 +00005943template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005944ExprResult
John McCall454feb92009-12-08 09:21:05 +00005945TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005946 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005947 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005948 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005949
John McCall60d7b3a2010-08-24 06:29:42 +00005950 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005951 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005952 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005953
Douglas Gregorb98b1992009-08-11 05:31:07 +00005954 if (!getDerived().AlwaysRebuild() &&
5955 LHS.get() == E->getLHS() &&
5956 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005957 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005958
Douglas Gregorb98b1992009-08-11 05:31:07 +00005959 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005960 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005961}
5962
Mike Stump1eb44332009-09-09 15:08:12 +00005963template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005964ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005965TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00005966 CompoundAssignOperator *E) {
5967 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005968}
Mike Stump1eb44332009-09-09 15:08:12 +00005969
Douglas Gregorb98b1992009-08-11 05:31:07 +00005970template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00005971ExprResult TreeTransform<Derived>::
5972TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5973 // Just rebuild the common and RHS expressions and see whether we
5974 // get any changes.
5975
5976 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5977 if (commonExpr.isInvalid())
5978 return ExprError();
5979
5980 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5981 if (rhs.isInvalid())
5982 return ExprError();
5983
5984 if (!getDerived().AlwaysRebuild() &&
5985 commonExpr.get() == e->getCommon() &&
5986 rhs.get() == e->getFalseExpr())
5987 return SemaRef.Owned(e);
5988
5989 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5990 e->getQuestionLoc(),
5991 0,
5992 e->getColonLoc(),
5993 rhs.get());
5994}
5995
5996template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005997ExprResult
John McCall454feb92009-12-08 09:21:05 +00005998TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005999 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006000 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006001 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006002
John McCall60d7b3a2010-08-24 06:29:42 +00006003 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006004 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006005 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006006
John McCall60d7b3a2010-08-24 06:29:42 +00006007 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006008 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006009 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006010
Douglas Gregorb98b1992009-08-11 05:31:07 +00006011 if (!getDerived().AlwaysRebuild() &&
6012 Cond.get() == E->getCond() &&
6013 LHS.get() == E->getLHS() &&
6014 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006015 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006016
John McCall9ae2f072010-08-23 23:25:46 +00006017 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006018 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006019 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006020 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006021 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006022}
Mike Stump1eb44332009-09-09 15:08:12 +00006023
6024template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006025ExprResult
John McCall454feb92009-12-08 09:21:05 +00006026TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006027 // Implicit casts are eliminated during transformation, since they
6028 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006029 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006030}
Mike Stump1eb44332009-09-09 15:08:12 +00006031
Douglas Gregorb98b1992009-08-11 05:31:07 +00006032template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006033ExprResult
John McCall454feb92009-12-08 09:21:05 +00006034TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006035 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6036 if (!Type)
6037 return ExprError();
6038
John McCall60d7b3a2010-08-24 06:29:42 +00006039 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006040 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006041 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006042 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006043
Douglas Gregorb98b1992009-08-11 05:31:07 +00006044 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006045 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006046 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006047 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006048
John McCall9d125032010-01-15 18:39:57 +00006049 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006050 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006051 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006052 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006053}
Mike Stump1eb44332009-09-09 15:08:12 +00006054
Douglas Gregorb98b1992009-08-11 05:31:07 +00006055template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006056ExprResult
John McCall454feb92009-12-08 09:21:05 +00006057TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006058 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6059 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6060 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006061 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006062
John McCall60d7b3a2010-08-24 06:29:42 +00006063 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006064 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006065 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006066
Douglas Gregorb98b1992009-08-11 05:31:07 +00006067 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006068 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006069 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00006070 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006071
John McCall1d7d8d62010-01-19 22:33:45 +00006072 // Note: the expression type doesn't necessarily match the
6073 // type-as-written, but that's okay, because it should always be
6074 // derivable from the initializer.
6075
John McCall42f56b52010-01-18 19:35:47 +00006076 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006077 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006078 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006079}
Mike Stump1eb44332009-09-09 15:08:12 +00006080
Douglas Gregorb98b1992009-08-11 05:31:07 +00006081template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006082ExprResult
John McCall454feb92009-12-08 09:21:05 +00006083TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006084 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006085 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006086 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006087
Douglas Gregorb98b1992009-08-11 05:31:07 +00006088 if (!getDerived().AlwaysRebuild() &&
6089 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006090 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006091
Douglas Gregorb98b1992009-08-11 05:31:07 +00006092 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006093 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006094 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006095 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006096 E->getAccessorLoc(),
6097 E->getAccessor());
6098}
Mike Stump1eb44332009-09-09 15:08:12 +00006099
Douglas Gregorb98b1992009-08-11 05:31:07 +00006100template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006101ExprResult
John McCall454feb92009-12-08 09:21:05 +00006102TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006103 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006104
John McCallca0408f2010-08-23 06:44:23 +00006105 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006106 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6107 Inits, &InitChanged))
6108 return ExprError();
6109
Douglas Gregorb98b1992009-08-11 05:31:07 +00006110 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006111 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006112
Douglas Gregorb98b1992009-08-11 05:31:07 +00006113 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006114 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006115}
Mike Stump1eb44332009-09-09 15:08:12 +00006116
Douglas Gregorb98b1992009-08-11 05:31:07 +00006117template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006118ExprResult
John McCall454feb92009-12-08 09:21:05 +00006119TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006120 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006121
Douglas Gregor43959a92009-08-20 07:17:43 +00006122 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006123 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006124 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006125 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006126
Douglas Gregor43959a92009-08-20 07:17:43 +00006127 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006128 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006129 bool ExprChanged = false;
6130 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6131 DEnd = E->designators_end();
6132 D != DEnd; ++D) {
6133 if (D->isFieldDesignator()) {
6134 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6135 D->getDotLoc(),
6136 D->getFieldLoc()));
6137 continue;
6138 }
Mike Stump1eb44332009-09-09 15:08:12 +00006139
Douglas Gregorb98b1992009-08-11 05:31:07 +00006140 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006141 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006142 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006143 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006144
6145 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006146 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006147
Douglas Gregorb98b1992009-08-11 05:31:07 +00006148 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6149 ArrayExprs.push_back(Index.release());
6150 continue;
6151 }
Mike Stump1eb44332009-09-09 15:08:12 +00006152
Douglas Gregorb98b1992009-08-11 05:31:07 +00006153 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006154 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006155 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6156 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006157 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006158
John McCall60d7b3a2010-08-24 06:29:42 +00006159 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006160 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006161 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006162
6163 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006164 End.get(),
6165 D->getLBracketLoc(),
6166 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006167
Douglas Gregorb98b1992009-08-11 05:31:07 +00006168 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6169 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006170
Douglas Gregorb98b1992009-08-11 05:31:07 +00006171 ArrayExprs.push_back(Start.release());
6172 ArrayExprs.push_back(End.release());
6173 }
Mike Stump1eb44332009-09-09 15:08:12 +00006174
Douglas Gregorb98b1992009-08-11 05:31:07 +00006175 if (!getDerived().AlwaysRebuild() &&
6176 Init.get() == E->getInit() &&
6177 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006178 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006179
Douglas Gregorb98b1992009-08-11 05:31:07 +00006180 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6181 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006182 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006183}
Mike Stump1eb44332009-09-09 15:08:12 +00006184
Douglas Gregorb98b1992009-08-11 05:31:07 +00006185template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006186ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006187TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006188 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006189 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006190
Douglas Gregor5557b252009-10-28 00:29:27 +00006191 // FIXME: Will we ever have proper type location here? Will we actually
6192 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006193 QualType T = getDerived().TransformType(E->getType());
6194 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006195 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006196
Douglas Gregorb98b1992009-08-11 05:31:07 +00006197 if (!getDerived().AlwaysRebuild() &&
6198 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006199 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006200
Douglas Gregorb98b1992009-08-11 05:31:07 +00006201 return getDerived().RebuildImplicitValueInitExpr(T);
6202}
Mike Stump1eb44332009-09-09 15:08:12 +00006203
Douglas Gregorb98b1992009-08-11 05:31:07 +00006204template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006205ExprResult
John McCall454feb92009-12-08 09:21:05 +00006206TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006207 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6208 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006209 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006210
John McCall60d7b3a2010-08-24 06:29:42 +00006211 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006212 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006213 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006214
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006216 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006218 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006219
John McCall9ae2f072010-08-23 23:25:46 +00006220 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006221 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006222}
6223
6224template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006225ExprResult
John McCall454feb92009-12-08 09:21:05 +00006226TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006227 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006228 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006229 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6230 &ArgumentChanged))
6231 return ExprError();
6232
Douglas Gregorb98b1992009-08-11 05:31:07 +00006233 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6234 move_arg(Inits),
6235 E->getRParenLoc());
6236}
Mike Stump1eb44332009-09-09 15:08:12 +00006237
Douglas Gregorb98b1992009-08-11 05:31:07 +00006238/// \brief Transform an address-of-label expression.
6239///
6240/// By default, the transformation of an address-of-label expression always
6241/// rebuilds the expression, so that the label identifier can be resolved to
6242/// the corresponding label statement by semantic analysis.
6243template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006244ExprResult
John McCall454feb92009-12-08 09:21:05 +00006245TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006246 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6247 E->getLabel());
6248 if (!LD)
6249 return ExprError();
6250
Douglas Gregorb98b1992009-08-11 05:31:07 +00006251 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006252 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006253}
Mike Stump1eb44332009-09-09 15:08:12 +00006254
6255template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006256ExprResult
John McCall454feb92009-12-08 09:21:05 +00006257TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006258 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006259 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6260 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006261 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006262
Douglas Gregorb98b1992009-08-11 05:31:07 +00006263 if (!getDerived().AlwaysRebuild() &&
6264 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00006265 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006266
6267 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006268 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006269 E->getRParenLoc());
6270}
Mike Stump1eb44332009-09-09 15:08:12 +00006271
Douglas Gregorb98b1992009-08-11 05:31:07 +00006272template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006273ExprResult
John McCall454feb92009-12-08 09:21:05 +00006274TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006275 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006276 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006277 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006278
John McCall60d7b3a2010-08-24 06:29:42 +00006279 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006280 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006281 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006282
John McCall60d7b3a2010-08-24 06:29:42 +00006283 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006284 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006285 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006286
Douglas Gregorb98b1992009-08-11 05:31:07 +00006287 if (!getDerived().AlwaysRebuild() &&
6288 Cond.get() == E->getCond() &&
6289 LHS.get() == E->getLHS() &&
6290 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006291 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006292
Douglas Gregorb98b1992009-08-11 05:31:07 +00006293 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006294 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006295 E->getRParenLoc());
6296}
Mike Stump1eb44332009-09-09 15:08:12 +00006297
Douglas Gregorb98b1992009-08-11 05:31:07 +00006298template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006299ExprResult
John McCall454feb92009-12-08 09:21:05 +00006300TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006301 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006302}
6303
6304template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006305ExprResult
John McCall454feb92009-12-08 09:21:05 +00006306TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006307 switch (E->getOperator()) {
6308 case OO_New:
6309 case OO_Delete:
6310 case OO_Array_New:
6311 case OO_Array_Delete:
6312 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006313 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006314
Douglas Gregor668d6d92009-12-13 20:44:55 +00006315 case OO_Call: {
6316 // This is a call to an object's operator().
6317 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6318
6319 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006320 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006321 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006322 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006323
6324 // FIXME: Poor location information
6325 SourceLocation FakeLParenLoc
6326 = SemaRef.PP.getLocForEndOfToken(
6327 static_cast<Expr *>(Object.get())->getLocEnd());
6328
6329 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006330 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006331 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6332 Args))
6333 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006334
John McCall9ae2f072010-08-23 23:25:46 +00006335 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006336 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006337 E->getLocEnd());
6338 }
6339
6340#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6341 case OO_##Name:
6342#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6343#include "clang/Basic/OperatorKinds.def"
6344 case OO_Subscript:
6345 // Handled below.
6346 break;
6347
6348 case OO_Conditional:
6349 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006350 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006351
6352 case OO_None:
6353 case NUM_OVERLOADED_OPERATORS:
6354 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006355 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006356 }
6357
John McCall60d7b3a2010-08-24 06:29:42 +00006358 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006359 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006360 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006361
John McCall60d7b3a2010-08-24 06:29:42 +00006362 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006363 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006364 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006365
John McCall60d7b3a2010-08-24 06:29:42 +00006366 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006367 if (E->getNumArgs() == 2) {
6368 Second = getDerived().TransformExpr(E->getArg(1));
6369 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006370 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006371 }
Mike Stump1eb44332009-09-09 15:08:12 +00006372
Douglas Gregorb98b1992009-08-11 05:31:07 +00006373 if (!getDerived().AlwaysRebuild() &&
6374 Callee.get() == E->getCallee() &&
6375 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006376 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00006377 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006378
Douglas Gregorb98b1992009-08-11 05:31:07 +00006379 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6380 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006381 Callee.get(),
6382 First.get(),
6383 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006384}
Mike Stump1eb44332009-09-09 15:08:12 +00006385
Douglas Gregorb98b1992009-08-11 05:31:07 +00006386template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006387ExprResult
John McCall454feb92009-12-08 09:21:05 +00006388TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6389 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006390}
Mike Stump1eb44332009-09-09 15:08:12 +00006391
Douglas Gregorb98b1992009-08-11 05:31:07 +00006392template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006393ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006394TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6395 // Transform the callee.
6396 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6397 if (Callee.isInvalid())
6398 return ExprError();
6399
6400 // Transform exec config.
6401 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6402 if (EC.isInvalid())
6403 return ExprError();
6404
6405 // Transform arguments.
6406 bool ArgChanged = false;
6407 ASTOwningVector<Expr*> Args(SemaRef);
6408 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6409 &ArgChanged))
6410 return ExprError();
6411
6412 if (!getDerived().AlwaysRebuild() &&
6413 Callee.get() == E->getCallee() &&
6414 !ArgChanged)
6415 return SemaRef.Owned(E);
6416
6417 // FIXME: Wrong source location information for the '('.
6418 SourceLocation FakeLParenLoc
6419 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6420 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6421 move_arg(Args),
6422 E->getRParenLoc(), EC.get());
6423}
6424
6425template<typename Derived>
6426ExprResult
John McCall454feb92009-12-08 09:21:05 +00006427TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006428 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6429 if (!Type)
6430 return ExprError();
6431
John McCall60d7b3a2010-08-24 06:29:42 +00006432 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006433 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006434 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006435 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006436
Douglas Gregorb98b1992009-08-11 05:31:07 +00006437 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006438 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006439 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006440 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006441
Douglas Gregorb98b1992009-08-11 05:31:07 +00006442 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006443 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006444 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6445 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6446 SourceLocation FakeRParenLoc
6447 = SemaRef.PP.getLocForEndOfToken(
6448 E->getSubExpr()->getSourceRange().getEnd());
6449 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006450 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006451 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006452 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006453 FakeRAngleLoc,
6454 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006455 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006456 FakeRParenLoc);
6457}
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>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6462 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006463}
Mike Stump1eb44332009-09-09 15:08:12 +00006464
6465template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006466ExprResult
John McCall454feb92009-12-08 09:21:05 +00006467TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6468 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006469}
6470
Douglas Gregorb98b1992009-08-11 05:31:07 +00006471template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006472ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006473TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006474 CXXReinterpretCastExpr *E) {
6475 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476}
Mike Stump1eb44332009-09-09 15:08:12 +00006477
Douglas Gregorb98b1992009-08-11 05:31:07 +00006478template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006479ExprResult
John McCall454feb92009-12-08 09:21:05 +00006480TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6481 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482}
Mike Stump1eb44332009-09-09 15:08:12 +00006483
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006485ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006486TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006487 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006488 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6489 if (!Type)
6490 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006491
John McCall60d7b3a2010-08-24 06:29:42 +00006492 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006493 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006494 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006495 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006496
Douglas Gregorb98b1992009-08-11 05:31:07 +00006497 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006498 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006499 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006500 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006501
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006502 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006503 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006504 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006505 E->getRParenLoc());
6506}
Mike Stump1eb44332009-09-09 15:08:12 +00006507
Douglas Gregorb98b1992009-08-11 05:31:07 +00006508template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006509ExprResult
John McCall454feb92009-12-08 09:21:05 +00006510TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006511 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006512 TypeSourceInfo *TInfo
6513 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6514 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006515 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006516
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006518 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006519 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006520
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006521 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6522 E->getLocStart(),
6523 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524 E->getLocEnd());
6525 }
Mike Stump1eb44332009-09-09 15:08:12 +00006526
Douglas Gregorb98b1992009-08-11 05:31:07 +00006527 // We don't know whether the expression is potentially evaluated until
6528 // after we perform semantic analysis, so the expression is potentially
6529 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006530 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006531 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006532
John McCall60d7b3a2010-08-24 06:29:42 +00006533 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006534 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006535 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006536
Douglas Gregorb98b1992009-08-11 05:31:07 +00006537 if (!getDerived().AlwaysRebuild() &&
6538 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006539 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006540
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006541 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6542 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006543 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006544 E->getLocEnd());
6545}
6546
6547template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006548ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006549TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6550 if (E->isTypeOperand()) {
6551 TypeSourceInfo *TInfo
6552 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6553 if (!TInfo)
6554 return ExprError();
6555
6556 if (!getDerived().AlwaysRebuild() &&
6557 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006558 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006559
Douglas Gregor3c52a212011-03-06 17:40:41 +00006560 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006561 E->getLocStart(),
6562 TInfo,
6563 E->getLocEnd());
6564 }
6565
6566 // We don't know whether the expression is potentially evaluated until
6567 // after we perform semantic analysis, so the expression is potentially
6568 // potentially evaluated.
6569 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6570
6571 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6572 if (SubExpr.isInvalid())
6573 return ExprError();
6574
6575 if (!getDerived().AlwaysRebuild() &&
6576 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006577 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006578
6579 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6580 E->getLocStart(),
6581 SubExpr.get(),
6582 E->getLocEnd());
6583}
6584
6585template<typename Derived>
6586ExprResult
John McCall454feb92009-12-08 09:21:05 +00006587TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006588 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006589}
Mike Stump1eb44332009-09-09 15:08:12 +00006590
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006592ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006594 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006595 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006596}
Mike Stump1eb44332009-09-09 15:08:12 +00006597
Douglas Gregorb98b1992009-08-11 05:31:07 +00006598template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006599ExprResult
John McCall454feb92009-12-08 09:21:05 +00006600TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006601 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6602 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6603 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00006604
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006605 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006606 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006607
Douglas Gregor828a1972010-01-07 23:12:05 +00006608 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006609}
Mike Stump1eb44332009-09-09 15:08:12 +00006610
Douglas Gregorb98b1992009-08-11 05:31:07 +00006611template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006612ExprResult
John McCall454feb92009-12-08 09:21:05 +00006613TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006614 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006615 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006616 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006617
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618 if (!getDerived().AlwaysRebuild() &&
6619 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006620 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621
John McCall9ae2f072010-08-23 23:25:46 +00006622 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623}
Mike Stump1eb44332009-09-09 15:08:12 +00006624
Douglas Gregorb98b1992009-08-11 05:31:07 +00006625template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006626ExprResult
John McCall454feb92009-12-08 09:21:05 +00006627TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006628 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006629 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6630 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006632 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006633
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006634 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006636 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006637
Douglas Gregor036aed12009-12-23 23:03:06 +00006638 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639}
Mike Stump1eb44332009-09-09 15:08:12 +00006640
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006642ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006643TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6644 CXXScalarValueInitExpr *E) {
6645 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6646 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006647 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006648
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006650 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006651 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006652
Douglas Gregorab6677e2010-09-08 00:15:04 +00006653 return getDerived().RebuildCXXScalarValueInitExpr(T,
6654 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006655 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656}
Mike Stump1eb44332009-09-09 15:08:12 +00006657
Douglas Gregorb98b1992009-08-11 05:31:07 +00006658template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006659ExprResult
John McCall454feb92009-12-08 09:21:05 +00006660TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006661 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006662 TypeSourceInfo *AllocTypeInfo
6663 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6664 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006665 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006666
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006668 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006669 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006670 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006671
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672 // Transform the placement arguments (if any).
6673 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006674 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006675 if (getDerived().TransformExprs(E->getPlacementArgs(),
6676 E->getNumPlacementArgs(), true,
6677 PlacementArgs, &ArgumentChanged))
6678 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006679
Douglas Gregor43959a92009-08-20 07:17:43 +00006680 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00006681 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006682 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6683 ConstructorArgs, &ArgumentChanged))
6684 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006685
Douglas Gregor1af74512010-02-26 00:38:10 +00006686 // Transform constructor, new operator, and delete operator.
6687 CXXConstructorDecl *Constructor = 0;
6688 if (E->getConstructor()) {
6689 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006690 getDerived().TransformDecl(E->getLocStart(),
6691 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006692 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006693 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006694 }
6695
6696 FunctionDecl *OperatorNew = 0;
6697 if (E->getOperatorNew()) {
6698 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006699 getDerived().TransformDecl(E->getLocStart(),
6700 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006701 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006702 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006703 }
6704
6705 FunctionDecl *OperatorDelete = 0;
6706 if (E->getOperatorDelete()) {
6707 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006708 getDerived().TransformDecl(E->getLocStart(),
6709 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006710 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006711 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006712 }
Sean Huntc3021132010-05-05 15:23:54 +00006713
Douglas Gregorb98b1992009-08-11 05:31:07 +00006714 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006715 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006716 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006717 Constructor == E->getConstructor() &&
6718 OperatorNew == E->getOperatorNew() &&
6719 OperatorDelete == E->getOperatorDelete() &&
6720 !ArgumentChanged) {
6721 // Mark any declarations we need as referenced.
6722 // FIXME: instantiation-specific.
6723 if (Constructor)
6724 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6725 if (OperatorNew)
6726 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6727 if (OperatorDelete)
6728 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00006729 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006730 }
Mike Stump1eb44332009-09-09 15:08:12 +00006731
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006732 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006733 if (!ArraySize.get()) {
6734 // If no array size was specified, but the new expression was
6735 // instantiated with an array type (e.g., "new T" where T is
6736 // instantiated with "int[4]"), extract the outer bound from the
6737 // array type as our array size. We do this with constant and
6738 // dependently-sized array types.
6739 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6740 if (!ArrayT) {
6741 // Do nothing
6742 } else if (const ConstantArrayType *ConsArrayT
6743 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00006744 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006745 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6746 ConsArrayT->getSize(),
6747 SemaRef.Context.getSizeType(),
6748 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006749 AllocType = ConsArrayT->getElementType();
6750 } else if (const DependentSizedArrayType *DepArrayT
6751 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6752 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00006753 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006754 AllocType = DepArrayT->getElementType();
6755 }
6756 }
6757 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006758
Douglas Gregorb98b1992009-08-11 05:31:07 +00006759 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6760 E->isGlobalNew(),
6761 /*FIXME:*/E->getLocStart(),
6762 move_arg(PlacementArgs),
6763 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00006764 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006765 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006766 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00006767 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006768 /*FIXME:*/E->getLocStart(),
6769 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00006770 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006771}
Mike Stump1eb44332009-09-09 15:08:12 +00006772
Douglas Gregorb98b1992009-08-11 05:31:07 +00006773template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006774ExprResult
John McCall454feb92009-12-08 09:21:05 +00006775TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006776 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006777 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006778 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006779
Douglas Gregor1af74512010-02-26 00:38:10 +00006780 // Transform the delete operator, if known.
6781 FunctionDecl *OperatorDelete = 0;
6782 if (E->getOperatorDelete()) {
6783 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006784 getDerived().TransformDecl(E->getLocStart(),
6785 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006786 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006787 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006788 }
Sean Huntc3021132010-05-05 15:23:54 +00006789
Douglas Gregorb98b1992009-08-11 05:31:07 +00006790 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006791 Operand.get() == E->getArgument() &&
6792 OperatorDelete == E->getOperatorDelete()) {
6793 // Mark any declarations we need as referenced.
6794 // FIXME: instantiation-specific.
6795 if (OperatorDelete)
6796 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00006797
6798 if (!E->getArgument()->isTypeDependent()) {
6799 QualType Destroyed = SemaRef.Context.getBaseElementType(
6800 E->getDestroyedType());
6801 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6802 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6803 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6804 SemaRef.LookupDestructor(Record));
6805 }
6806 }
6807
John McCall3fa5cae2010-10-26 07:05:15 +00006808 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006809 }
Mike Stump1eb44332009-09-09 15:08:12 +00006810
Douglas Gregorb98b1992009-08-11 05:31:07 +00006811 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6812 E->isGlobalDelete(),
6813 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00006814 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006815}
Mike Stump1eb44332009-09-09 15:08:12 +00006816
Douglas Gregorb98b1992009-08-11 05:31:07 +00006817template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006818ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00006819TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00006820 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006821 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00006822 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006823 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006824
John McCallb3d87482010-08-24 05:47:05 +00006825 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006826 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006827 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006828 E->getOperatorLoc(),
6829 E->isArrow()? tok::arrow : tok::period,
6830 ObjectTypePtr,
6831 MayBePseudoDestructor);
6832 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006833 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006834
John McCallb3d87482010-08-24 05:47:05 +00006835 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006836 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6837 if (QualifierLoc) {
6838 QualifierLoc
6839 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6840 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00006841 return ExprError();
6842 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006843 CXXScopeSpec SS;
6844 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00006845
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006846 PseudoDestructorTypeStorage Destroyed;
6847 if (E->getDestroyedTypeInfo()) {
6848 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00006849 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00006850 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006851 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006852 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006853 Destroyed = DestroyedTypeInfo;
6854 } else if (ObjectType->isDependentType()) {
6855 // We aren't likely to be able to resolve the identifier down to a type
6856 // now anyway, so just retain the identifier.
6857 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6858 E->getDestroyedTypeLoc());
6859 } else {
6860 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00006861 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006862 *E->getDestroyedTypeIdentifier(),
6863 E->getDestroyedTypeLoc(),
6864 /*Scope=*/0,
6865 SS, ObjectTypePtr,
6866 false);
6867 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006868 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006869
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006870 Destroyed
6871 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6872 E->getDestroyedTypeLoc());
6873 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006874
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006875 TypeSourceInfo *ScopeTypeInfo = 0;
6876 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00006877 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006878 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006879 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00006880 }
Sean Huntc3021132010-05-05 15:23:54 +00006881
John McCall9ae2f072010-08-23 23:25:46 +00006882 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006883 E->getOperatorLoc(),
6884 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00006885 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006886 ScopeTypeInfo,
6887 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006888 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006889 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00006890}
Mike Stump1eb44332009-09-09 15:08:12 +00006891
Douglas Gregora71d8192009-09-04 17:36:40 +00006892template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006893ExprResult
John McCallba135432009-11-21 08:51:07 +00006894TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00006895 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00006896 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6897 Sema::LookupOrdinaryName);
6898
6899 // Transform all the decls.
6900 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6901 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006902 NamedDecl *InstD = static_cast<NamedDecl*>(
6903 getDerived().TransformDecl(Old->getNameLoc(),
6904 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006905 if (!InstD) {
6906 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6907 // This can happen because of dependent hiding.
6908 if (isa<UsingShadowDecl>(*I))
6909 continue;
6910 else
John McCallf312b1e2010-08-26 23:41:50 +00006911 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006912 }
John McCallf7a1a742009-11-24 19:00:30 +00006913
6914 // Expand using declarations.
6915 if (isa<UsingDecl>(InstD)) {
6916 UsingDecl *UD = cast<UsingDecl>(InstD);
6917 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6918 E = UD->shadow_end(); I != E; ++I)
6919 R.addDecl(*I);
6920 continue;
6921 }
6922
6923 R.addDecl(InstD);
6924 }
6925
6926 // Resolve a kind, but don't do any further analysis. If it's
6927 // ambiguous, the callee needs to deal with it.
6928 R.resolveKind();
6929
6930 // Rebuild the nested-name qualifier, if present.
6931 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00006932 if (Old->getQualifierLoc()) {
6933 NestedNameSpecifierLoc QualifierLoc
6934 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
6935 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006936 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006937
Douglas Gregor4c9be892011-02-28 20:01:57 +00006938 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00006939 }
6940
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006941 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00006942 CXXRecordDecl *NamingClass
6943 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6944 Old->getNameLoc(),
6945 Old->getNamingClass()));
6946 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006947 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006948
Douglas Gregor66c45152010-04-27 16:10:10 +00006949 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00006950 }
6951
6952 // If we have no template arguments, it's a normal declaration name.
6953 if (!Old->hasExplicitTemplateArgs())
6954 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6955
6956 // If we have template arguments, rebuild them, then rebuild the
6957 // templateid expression.
6958 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006959 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6960 Old->getNumTemplateArgs(),
6961 TransArgs))
6962 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00006963
6964 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6965 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966}
Mike Stump1eb44332009-09-09 15:08:12 +00006967
Douglas Gregorb98b1992009-08-11 05:31:07 +00006968template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006969ExprResult
John McCall454feb92009-12-08 09:21:05 +00006970TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006971 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6972 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006973 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006974
Douglas Gregorb98b1992009-08-11 05:31:07 +00006975 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006976 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006977 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006978
Mike Stump1eb44332009-09-09 15:08:12 +00006979 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006981 T,
6982 E->getLocEnd());
6983}
Mike Stump1eb44332009-09-09 15:08:12 +00006984
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006986ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00006987TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6988 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6989 if (!LhsT)
6990 return ExprError();
6991
6992 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6993 if (!RhsT)
6994 return ExprError();
6995
6996 if (!getDerived().AlwaysRebuild() &&
6997 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6998 return SemaRef.Owned(E);
6999
7000 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7001 E->getLocStart(),
7002 LhsT, RhsT,
7003 E->getLocEnd());
7004}
7005
7006template<typename Derived>
7007ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007008TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7009 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7010 if (!T)
7011 return ExprError();
7012
7013 if (!getDerived().AlwaysRebuild() &&
7014 T == E->getQueriedTypeSourceInfo())
7015 return SemaRef.Owned(E);
7016
7017 ExprResult SubExpr;
7018 {
7019 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7020 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7021 if (SubExpr.isInvalid())
7022 return ExprError();
7023
7024 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7025 return SemaRef.Owned(E);
7026 }
7027
7028 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7029 E->getLocStart(),
7030 T,
7031 SubExpr.get(),
7032 E->getLocEnd());
7033}
7034
7035template<typename Derived>
7036ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007037TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7038 ExprResult SubExpr;
7039 {
7040 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7041 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7042 if (SubExpr.isInvalid())
7043 return ExprError();
7044
7045 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7046 return SemaRef.Owned(E);
7047 }
7048
7049 return getDerived().RebuildExpressionTrait(
7050 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7051}
7052
7053template<typename Derived>
7054ExprResult
John McCall865d4472009-11-19 22:55:06 +00007055TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007056 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007057 NestedNameSpecifierLoc QualifierLoc
7058 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7059 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007060 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007061
John McCall43fed0d2010-11-12 08:19:04 +00007062 // TODO: If this is a conversion-function-id, verify that the
7063 // destination type name (if present) resolves the same way after
7064 // instantiation as it did in the local scope.
7065
Abramo Bagnara25777432010-08-11 22:01:17 +00007066 DeclarationNameInfo NameInfo
7067 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7068 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007069 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007070
John McCallf7a1a742009-11-24 19:00:30 +00007071 if (!E->hasExplicitTemplateArgs()) {
7072 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007073 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007074 // Note: it is sufficient to compare the Name component of NameInfo:
7075 // if name has not changed, DNLoc has not changed either.
7076 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007077 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007078
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007079 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007080 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007081 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007082 }
John McCalld5532b62009-11-23 01:53:49 +00007083
7084 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007085 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7086 E->getNumTemplateArgs(),
7087 TransArgs))
7088 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007089
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007090 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007091 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007092 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007093}
7094
7095template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007096ExprResult
John McCall454feb92009-12-08 09:21:05 +00007097TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007098 // CXXConstructExprs are always implicit, so when we have a
7099 // 1-argument construction we just transform that argument.
7100 if (E->getNumArgs() == 1 ||
7101 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7102 return getDerived().TransformExpr(E->getArg(0));
7103
Douglas Gregorb98b1992009-08-11 05:31:07 +00007104 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7105
7106 QualType T = getDerived().TransformType(E->getType());
7107 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007108 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007109
7110 CXXConstructorDecl *Constructor
7111 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007112 getDerived().TransformDecl(E->getLocStart(),
7113 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007114 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007115 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007116
Douglas Gregorb98b1992009-08-11 05:31:07 +00007117 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007118 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007119 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7120 &ArgumentChanged))
7121 return ExprError();
7122
Douglas Gregorb98b1992009-08-11 05:31:07 +00007123 if (!getDerived().AlwaysRebuild() &&
7124 T == E->getType() &&
7125 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007126 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007127 // Mark the constructor as referenced.
7128 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00007129 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007130 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007131 }
Mike Stump1eb44332009-09-09 15:08:12 +00007132
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007133 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7134 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007135 move_arg(Args),
7136 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007137 E->getConstructionKind(),
7138 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007139}
Mike Stump1eb44332009-09-09 15:08:12 +00007140
Douglas Gregorb98b1992009-08-11 05:31:07 +00007141/// \brief Transform a C++ temporary-binding expression.
7142///
Douglas Gregor51326552009-12-24 18:51:59 +00007143/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7144/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007145template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007146ExprResult
John McCall454feb92009-12-08 09:21:05 +00007147TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007148 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007149}
Mike Stump1eb44332009-09-09 15:08:12 +00007150
John McCall4765fa02010-12-06 08:20:24 +00007151/// \brief Transform a C++ expression that contains cleanups that should
7152/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007153///
John McCall4765fa02010-12-06 08:20:24 +00007154/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007155/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007156template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007157ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007158TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007159 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007160}
Mike Stump1eb44332009-09-09 15:08:12 +00007161
Douglas Gregorb98b1992009-08-11 05:31:07 +00007162template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007163ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007164TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007165 CXXTemporaryObjectExpr *E) {
7166 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7167 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007168 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007169
Douglas Gregorb98b1992009-08-11 05:31:07 +00007170 CXXConstructorDecl *Constructor
7171 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007172 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007173 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007174 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007175 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007176
Douglas Gregorb98b1992009-08-11 05:31:07 +00007177 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007178 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007179 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007180 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7181 &ArgumentChanged))
7182 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007183
Douglas Gregorb98b1992009-08-11 05:31:07 +00007184 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007185 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007187 !ArgumentChanged) {
7188 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00007189 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007190 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007191 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007192
7193 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7194 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007195 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007196 E->getLocEnd());
7197}
Mike Stump1eb44332009-09-09 15:08:12 +00007198
Douglas Gregorb98b1992009-08-11 05:31:07 +00007199template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007200ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007201TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007202 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007203 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7204 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007205 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007206
Douglas Gregorb98b1992009-08-11 05:31:07 +00007207 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007208 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007209 Args.reserve(E->arg_size());
7210 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7211 &ArgumentChanged))
7212 return ExprError();
7213
Douglas Gregorb98b1992009-08-11 05:31:07 +00007214 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007215 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007216 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007217 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007218
Douglas Gregorb98b1992009-08-11 05:31:07 +00007219 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007220 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007221 E->getLParenLoc(),
7222 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007223 E->getRParenLoc());
7224}
Mike Stump1eb44332009-09-09 15:08:12 +00007225
Douglas Gregorb98b1992009-08-11 05:31:07 +00007226template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007227ExprResult
John McCall865d4472009-11-19 22:55:06 +00007228TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007229 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007230 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007231 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007232 Expr *OldBase;
7233 QualType BaseType;
7234 QualType ObjectType;
7235 if (!E->isImplicitAccess()) {
7236 OldBase = E->getBase();
7237 Base = getDerived().TransformExpr(OldBase);
7238 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007239 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007240
John McCallaa81e162009-12-01 22:10:20 +00007241 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007242 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007243 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007244 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007245 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007246 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007247 ObjectTy,
7248 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007249 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007250 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007251
John McCallb3d87482010-08-24 05:47:05 +00007252 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007253 BaseType = ((Expr*) Base.get())->getType();
7254 } else {
7255 OldBase = 0;
7256 BaseType = getDerived().TransformType(E->getBaseType());
7257 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7258 }
Mike Stump1eb44332009-09-09 15:08:12 +00007259
Douglas Gregor6cd21982009-10-20 05:58:46 +00007260 // Transform the first part of the nested-name-specifier that qualifies
7261 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007262 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007263 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007264 E->getFirstQualifierFoundInScope(),
7265 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007266
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007267 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007268 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007269 QualifierLoc
7270 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7271 ObjectType,
7272 FirstQualifierInScope);
7273 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007274 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007275 }
Mike Stump1eb44332009-09-09 15:08:12 +00007276
John McCall43fed0d2010-11-12 08:19:04 +00007277 // TODO: If this is a conversion-function-id, verify that the
7278 // destination type name (if present) resolves the same way after
7279 // instantiation as it did in the local scope.
7280
Abramo Bagnara25777432010-08-11 22:01:17 +00007281 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007282 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007283 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007284 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007285
John McCallaa81e162009-12-01 22:10:20 +00007286 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007287 // This is a reference to a member without an explicitly-specified
7288 // template argument list. Optimize for this common case.
7289 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007290 Base.get() == OldBase &&
7291 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007292 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007293 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007294 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007295 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007296
John McCall9ae2f072010-08-23 23:25:46 +00007297 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007298 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007299 E->isArrow(),
7300 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007301 QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00007302 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007303 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007304 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007305 }
7306
John McCalld5532b62009-11-23 01:53:49 +00007307 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007308 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7309 E->getNumTemplateArgs(),
7310 TransArgs))
7311 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007312
John McCall9ae2f072010-08-23 23:25:46 +00007313 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007314 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007315 E->isArrow(),
7316 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007317 QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007318 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007319 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007320 &TransArgs);
7321}
7322
7323template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007324ExprResult
John McCall454feb92009-12-08 09:21:05 +00007325TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007326 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007327 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007328 QualType BaseType;
7329 if (!Old->isImplicitAccess()) {
7330 Base = getDerived().TransformExpr(Old->getBase());
7331 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007332 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007333 BaseType = ((Expr*) Base.get())->getType();
7334 } else {
7335 BaseType = getDerived().TransformType(Old->getBaseType());
7336 }
John McCall129e2df2009-11-30 22:42:35 +00007337
Douglas Gregor4c9be892011-02-28 20:01:57 +00007338 NestedNameSpecifierLoc QualifierLoc;
7339 if (Old->getQualifierLoc()) {
7340 QualifierLoc
7341 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7342 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007343 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007344 }
7345
Abramo Bagnara25777432010-08-11 22:01:17 +00007346 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007347 Sema::LookupOrdinaryName);
7348
7349 // Transform all the decls.
7350 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7351 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007352 NamedDecl *InstD = static_cast<NamedDecl*>(
7353 getDerived().TransformDecl(Old->getMemberLoc(),
7354 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007355 if (!InstD) {
7356 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7357 // This can happen because of dependent hiding.
7358 if (isa<UsingShadowDecl>(*I))
7359 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007360 else {
7361 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007362 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007363 }
John McCall9f54ad42009-12-10 09:41:52 +00007364 }
John McCall129e2df2009-11-30 22:42:35 +00007365
7366 // Expand using declarations.
7367 if (isa<UsingDecl>(InstD)) {
7368 UsingDecl *UD = cast<UsingDecl>(InstD);
7369 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7370 E = UD->shadow_end(); I != E; ++I)
7371 R.addDecl(*I);
7372 continue;
7373 }
7374
7375 R.addDecl(InstD);
7376 }
7377
7378 R.resolveKind();
7379
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007380 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007381 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007382 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007383 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007384 Old->getMemberLoc(),
7385 Old->getNamingClass()));
7386 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007387 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007388
Douglas Gregor66c45152010-04-27 16:10:10 +00007389 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007390 }
Sean Huntc3021132010-05-05 15:23:54 +00007391
John McCall129e2df2009-11-30 22:42:35 +00007392 TemplateArgumentListInfo TransArgs;
7393 if (Old->hasExplicitTemplateArgs()) {
7394 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7395 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007396 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7397 Old->getNumTemplateArgs(),
7398 TransArgs))
7399 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007400 }
John McCallc2233c52010-01-15 08:34:02 +00007401
7402 // FIXME: to do this check properly, we will need to preserve the
7403 // first-qualifier-in-scope here, just in case we had a dependent
7404 // base (and therefore couldn't do the check) and a
7405 // nested-name-qualifier (and therefore could do the lookup).
7406 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007407
John McCall9ae2f072010-08-23 23:25:46 +00007408 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007409 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007410 Old->getOperatorLoc(),
7411 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007412 QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00007413 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007414 R,
7415 (Old->hasExplicitTemplateArgs()
7416 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007417}
7418
7419template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007420ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007421TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7422 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7423 if (SubExpr.isInvalid())
7424 return ExprError();
7425
7426 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007427 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007428
7429 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7430}
7431
7432template<typename Derived>
7433ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007434TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007435 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7436 if (Pattern.isInvalid())
7437 return ExprError();
7438
7439 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7440 return SemaRef.Owned(E);
7441
Douglas Gregor67fd1252011-01-14 21:20:45 +00007442 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7443 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007444}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007445
7446template<typename Derived>
7447ExprResult
7448TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7449 // If E is not value-dependent, then nothing will change when we transform it.
7450 // Note: This is an instantiation-centric view.
7451 if (!E->isValueDependent())
7452 return SemaRef.Owned(E);
7453
7454 // Note: None of the implementations of TryExpandParameterPacks can ever
7455 // produce a diagnostic when given only a single unexpanded parameter pack,
7456 // so
7457 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7458 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007459 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007460 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007461 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7462 &Unexpanded, 1,
Douglas Gregord3731192011-01-10 07:32:04 +00007463 ShouldExpand, RetainExpansion,
7464 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007465 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007466
Douglas Gregord3731192011-01-10 07:32:04 +00007467 if (!ShouldExpand || RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007468 return SemaRef.Owned(E);
7469
7470 // We now know the length of the parameter pack, so build a new expression
7471 // that stores that length.
7472 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7473 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00007474 *NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007475}
7476
Douglas Gregorbe230c32011-01-03 17:17:50 +00007477template<typename Derived>
7478ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007479TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7480 SubstNonTypeTemplateParmPackExpr *E) {
7481 // Default behavior is to do nothing with this transformation.
7482 return SemaRef.Owned(E);
7483}
7484
7485template<typename Derived>
7486ExprResult
John McCall454feb92009-12-08 09:21:05 +00007487TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007488 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007489}
7490
Mike Stump1eb44332009-09-09 15:08:12 +00007491template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007492ExprResult
John McCall454feb92009-12-08 09:21:05 +00007493TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007494 TypeSourceInfo *EncodedTypeInfo
7495 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7496 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007497 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007498
Douglas Gregorb98b1992009-08-11 05:31:07 +00007499 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007500 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007501 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007502
7503 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007504 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007505 E->getRParenLoc());
7506}
Mike Stump1eb44332009-09-09 15:08:12 +00007507
Douglas Gregorb98b1992009-08-11 05:31:07 +00007508template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007509ExprResult
John McCall454feb92009-12-08 09:21:05 +00007510TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007511 // Transform arguments.
7512 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007513 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007514 Args.reserve(E->getNumArgs());
7515 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7516 &ArgChanged))
7517 return ExprError();
7518
Douglas Gregor92e986e2010-04-22 16:44:27 +00007519 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7520 // Class message: transform the receiver type.
7521 TypeSourceInfo *ReceiverTypeInfo
7522 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7523 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007524 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007525
Douglas Gregor92e986e2010-04-22 16:44:27 +00007526 // If nothing changed, just retain the existing message send.
7527 if (!getDerived().AlwaysRebuild() &&
7528 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007529 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007530
7531 // Build a new class message send.
7532 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7533 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007534 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007535 E->getMethodDecl(),
7536 E->getLeftLoc(),
7537 move_arg(Args),
7538 E->getRightLoc());
7539 }
7540
7541 // Instance message: transform the receiver
7542 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7543 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007544 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007545 = getDerived().TransformExpr(E->getInstanceReceiver());
7546 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007547 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007548
7549 // If nothing changed, just retain the existing message send.
7550 if (!getDerived().AlwaysRebuild() &&
7551 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007552 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007553
Douglas Gregor92e986e2010-04-22 16:44:27 +00007554 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00007555 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007556 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007557 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007558 E->getMethodDecl(),
7559 E->getLeftLoc(),
7560 move_arg(Args),
7561 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007562}
7563
Mike Stump1eb44332009-09-09 15:08:12 +00007564template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007565ExprResult
John McCall454feb92009-12-08 09:21:05 +00007566TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007567 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007568}
7569
Mike Stump1eb44332009-09-09 15:08:12 +00007570template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007571ExprResult
John McCall454feb92009-12-08 09:21:05 +00007572TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007573 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007574}
7575
Mike Stump1eb44332009-09-09 15:08:12 +00007576template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007577ExprResult
John McCall454feb92009-12-08 09:21:05 +00007578TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007579 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007580 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007581 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007582 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007583
7584 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007585
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007586 // If nothing changed, just retain the existing expression.
7587 if (!getDerived().AlwaysRebuild() &&
7588 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007589 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007590
John McCall9ae2f072010-08-23 23:25:46 +00007591 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007592 E->getLocation(),
7593 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007594}
7595
Mike Stump1eb44332009-09-09 15:08:12 +00007596template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007597ExprResult
John McCall454feb92009-12-08 09:21:05 +00007598TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00007599 // 'super' and types never change. Property never changes. Just
7600 // retain the existing expression.
7601 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00007602 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00007603
Douglas Gregore3303542010-04-26 20:47:02 +00007604 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007605 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00007606 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007607 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007608
Douglas Gregore3303542010-04-26 20:47:02 +00007609 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007610
Douglas Gregore3303542010-04-26 20:47:02 +00007611 // If nothing changed, just retain the existing expression.
7612 if (!getDerived().AlwaysRebuild() &&
7613 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007614 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007615
John McCall12f78a62010-12-02 01:19:52 +00007616 if (E->isExplicitProperty())
7617 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7618 E->getExplicitProperty(),
7619 E->getLocation());
7620
7621 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7622 E->getType(),
7623 E->getImplicitPropertyGetter(),
7624 E->getImplicitPropertySetter(),
7625 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007626}
7627
Mike Stump1eb44332009-09-09 15:08:12 +00007628template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007629ExprResult
John McCall454feb92009-12-08 09:21:05 +00007630TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007631 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007632 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007633 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007634 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007635
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007636 // If nothing changed, just retain the existing expression.
7637 if (!getDerived().AlwaysRebuild() &&
7638 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007639 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007640
John McCall9ae2f072010-08-23 23:25:46 +00007641 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007642 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007643}
7644
Mike Stump1eb44332009-09-09 15:08:12 +00007645template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007646ExprResult
John McCall454feb92009-12-08 09:21:05 +00007647TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007648 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007649 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007650 SubExprs.reserve(E->getNumSubExprs());
7651 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7652 SubExprs, &ArgumentChanged))
7653 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007654
Douglas Gregorb98b1992009-08-11 05:31:07 +00007655 if (!getDerived().AlwaysRebuild() &&
7656 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007657 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007658
Douglas Gregorb98b1992009-08-11 05:31:07 +00007659 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7660 move_arg(SubExprs),
7661 E->getRParenLoc());
7662}
7663
Mike Stump1eb44332009-09-09 15:08:12 +00007664template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007665ExprResult
John McCall454feb92009-12-08 09:21:05 +00007666TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00007667 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007668
John McCallc6ac9c32011-02-04 18:33:18 +00007669 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7670 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7671
7672 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7673 llvm::SmallVector<ParmVarDecl*, 4> params;
7674 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007675
7676 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00007677 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7678 oldBlock->param_begin(),
7679 oldBlock->param_size(),
7680 0, paramTypes, &params))
Douglas Gregora779d9c2011-01-19 21:32:01 +00007681 return true;
John McCallc6ac9c32011-02-04 18:33:18 +00007682
7683 const FunctionType *exprFunctionType = E->getFunctionType();
7684 QualType exprResultType = exprFunctionType->getResultType();
7685 if (!exprResultType.isNull()) {
7686 if (!exprResultType->isDependentType())
7687 blockScope->ReturnType = exprResultType;
7688 else if (exprResultType != getSema().Context.DependentTy)
7689 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007690 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00007691
7692 // If the return type has not been determined yet, leave it as a dependent
7693 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00007694 if (blockScope->ReturnType.isNull())
7695 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007696
7697 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00007698 if (blockScope->ReturnType->isObjCObjectType()) {
7699 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00007700 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00007701 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007702 return ExprError();
7703 }
John McCall711c52b2011-01-05 12:14:39 +00007704
John McCallc6ac9c32011-02-04 18:33:18 +00007705 QualType functionType = getDerived().RebuildFunctionProtoType(
7706 blockScope->ReturnType,
7707 paramTypes.data(),
7708 paramTypes.size(),
7709 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00007710 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00007711 exprFunctionType->getExtInfo());
7712 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00007713
7714 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00007715 if (!params.empty())
7716 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregora779d9c2011-01-19 21:32:01 +00007717
7718 // If the return type wasn't explicitly set, it will have been marked as a
7719 // dependent type (DependentTy); clear out the return type setting so
7720 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00007721 if (blockScope->ReturnType == getSema().Context.DependentTy)
7722 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00007723
John McCall711c52b2011-01-05 12:14:39 +00007724 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00007725 StmtResult body = getDerived().TransformStmt(E->getBody());
7726 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00007727 return ExprError();
7728
John McCallc6ac9c32011-02-04 18:33:18 +00007729#ifndef NDEBUG
7730 // In builds with assertions, make sure that we captured everything we
7731 // captured before.
7732
7733 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7734
7735 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7736 e = oldBlock->capture_end(); i != e; ++i) {
John McCall6b5a61b2011-02-07 10:33:21 +00007737 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00007738
7739 // Ignore parameter packs.
7740 if (isa<ParmVarDecl>(oldCapture) &&
7741 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7742 continue;
7743
7744 VarDecl *newCapture =
7745 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7746 oldCapture));
John McCall6b5a61b2011-02-07 10:33:21 +00007747 assert(blockScope->CaptureMap.count(newCapture));
John McCallc6ac9c32011-02-04 18:33:18 +00007748 }
7749#endif
7750
7751 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7752 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007753}
7754
Mike Stump1eb44332009-09-09 15:08:12 +00007755template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007756ExprResult
John McCall454feb92009-12-08 09:21:05 +00007757TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007758 ValueDecl *ND
7759 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7760 E->getDecl()));
7761 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00007762 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00007763
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007764 if (!getDerived().AlwaysRebuild() &&
7765 ND == E->getDecl()) {
7766 // Mark it referenced in the new context regardless.
7767 // FIXME: this is a bit instantiation-specific.
7768 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7769
John McCall3fa5cae2010-10-26 07:05:15 +00007770 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007771 }
7772
Abramo Bagnara25777432010-08-11 22:01:17 +00007773 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00007774 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00007775 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007776}
Mike Stump1eb44332009-09-09 15:08:12 +00007777
Douglas Gregorb98b1992009-08-11 05:31:07 +00007778//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00007779// Type reconstruction
7780//===----------------------------------------------------------------------===//
7781
Mike Stump1eb44332009-09-09 15:08:12 +00007782template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007783QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7784 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007785 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007786 getDerived().getBaseEntity());
7787}
7788
Mike Stump1eb44332009-09-09 15:08:12 +00007789template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007790QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7791 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007792 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007793 getDerived().getBaseEntity());
7794}
7795
Mike Stump1eb44332009-09-09 15:08:12 +00007796template<typename Derived>
7797QualType
John McCall85737a72009-10-30 00:06:24 +00007798TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7799 bool WrittenAsLValue,
7800 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007801 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00007802 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007803}
7804
7805template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007806QualType
John McCall85737a72009-10-30 00:06:24 +00007807TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7808 QualType ClassType,
7809 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007810 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00007811 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007812}
7813
7814template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007815QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00007816TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7817 ArrayType::ArraySizeModifier SizeMod,
7818 const llvm::APInt *Size,
7819 Expr *SizeExpr,
7820 unsigned IndexTypeQuals,
7821 SourceRange BracketsRange) {
7822 if (SizeExpr || !Size)
7823 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7824 IndexTypeQuals, BracketsRange,
7825 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00007826
7827 QualType Types[] = {
7828 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7829 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7830 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00007831 };
7832 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7833 QualType SizeType;
7834 for (unsigned I = 0; I != NumTypes; ++I)
7835 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7836 SizeType = Types[I];
7837 break;
7838 }
Mike Stump1eb44332009-09-09 15:08:12 +00007839
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007840 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7841 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00007842 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007843 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00007844 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007845}
Mike Stump1eb44332009-09-09 15:08:12 +00007846
Douglas Gregor577f75a2009-08-04 16:50:30 +00007847template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007848QualType
7849TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007850 ArrayType::ArraySizeModifier SizeMod,
7851 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00007852 unsigned IndexTypeQuals,
7853 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007854 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00007855 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007856}
7857
7858template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007859QualType
Mike Stump1eb44332009-09-09 15:08:12 +00007860TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007861 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00007862 unsigned IndexTypeQuals,
7863 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007864 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00007865 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007866}
Mike Stump1eb44332009-09-09 15:08:12 +00007867
Douglas Gregor577f75a2009-08-04 16:50:30 +00007868template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007869QualType
7870TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007871 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007872 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007873 unsigned IndexTypeQuals,
7874 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007875 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007876 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007877 IndexTypeQuals, BracketsRange);
7878}
7879
7880template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007881QualType
7882TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007883 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007884 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007885 unsigned IndexTypeQuals,
7886 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007887 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007888 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007889 IndexTypeQuals, BracketsRange);
7890}
7891
7892template<typename Derived>
7893QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00007894 unsigned NumElements,
7895 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00007896 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00007897 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007898}
Mike Stump1eb44332009-09-09 15:08:12 +00007899
Douglas Gregor577f75a2009-08-04 16:50:30 +00007900template<typename Derived>
7901QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7902 unsigned NumElements,
7903 SourceLocation AttributeLoc) {
7904 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7905 NumElements, true);
7906 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007907 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7908 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00007909 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007910}
Mike Stump1eb44332009-09-09 15:08:12 +00007911
Douglas Gregor577f75a2009-08-04 16:50:30 +00007912template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007913QualType
7914TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00007915 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007916 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00007917 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007918}
Mike Stump1eb44332009-09-09 15:08:12 +00007919
Douglas Gregor577f75a2009-08-04 16:50:30 +00007920template<typename Derived>
7921QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00007922 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007923 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00007924 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00007925 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00007926 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00007927 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00007928 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00007929 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007930 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00007931 getDerived().getBaseEntity(),
7932 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007933}
Mike Stump1eb44332009-09-09 15:08:12 +00007934
Douglas Gregor577f75a2009-08-04 16:50:30 +00007935template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00007936QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7937 return SemaRef.Context.getFunctionNoProtoType(T);
7938}
7939
7940template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00007941QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7942 assert(D && "no decl found");
7943 if (D->isInvalidDecl()) return QualType();
7944
Douglas Gregor92e986e2010-04-22 16:44:27 +00007945 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00007946 TypeDecl *Ty;
7947 if (isa<UsingDecl>(D)) {
7948 UsingDecl *Using = cast<UsingDecl>(D);
7949 assert(Using->isTypeName() &&
7950 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7951
7952 // A valid resolved using typename decl points to exactly one type decl.
7953 assert(++Using->shadow_begin() == Using->shadow_end());
7954 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00007955
John McCalled976492009-12-04 22:46:56 +00007956 } else {
7957 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7958 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7959 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7960 }
7961
7962 return SemaRef.Context.getTypeDeclType(Ty);
7963}
7964
7965template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007966QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7967 SourceLocation Loc) {
7968 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007969}
7970
7971template<typename Derived>
7972QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7973 return SemaRef.Context.getTypeOfType(Underlying);
7974}
7975
7976template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007977QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7978 SourceLocation Loc) {
7979 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007980}
7981
7982template<typename Derived>
7983QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00007984 TemplateName Template,
7985 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00007986 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00007987 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007988}
Mike Stump1eb44332009-09-09 15:08:12 +00007989
Douglas Gregordcee1a12009-08-06 05:28:30 +00007990template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007991TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007992TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00007993 bool TemplateKW,
7994 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00007995 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00007996 Template);
7997}
7998
7999template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008000TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008001TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8002 const IdentifierInfo &Name,
8003 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008004 QualType ObjectType,
8005 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008006 UnqualifiedId TemplateName;
8007 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008008 Sema::TemplateTy Template;
8009 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008010 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008011 SS,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008012 TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008013 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008014 /*EnteringContext=*/false,
8015 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008016 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008017}
Mike Stump1eb44332009-09-09 15:08:12 +00008018
Douglas Gregorb98b1992009-08-11 05:31:07 +00008019template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008020TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008021TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008022 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008023 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008024 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008025 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008026 // FIXME: Bogus location information.
8027 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8028 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008029 Sema::TemplateTy Template;
8030 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008031 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008032 SS,
8033 Name,
John McCallb3d87482010-08-24 05:47:05 +00008034 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008035 /*EnteringContext=*/false,
8036 Template);
8037 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008038}
Sean Huntc3021132010-05-05 15:23:54 +00008039
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008040template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008041ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008042TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8043 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008044 Expr *OrigCallee,
8045 Expr *First,
8046 Expr *Second) {
8047 Expr *Callee = OrigCallee->IgnoreParenCasts();
8048 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008049
Douglas Gregorb98b1992009-08-11 05:31:07 +00008050 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008051 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008052 if (!First->getType()->isOverloadableType() &&
8053 !Second->getType()->isOverloadableType())
8054 return getSema().CreateBuiltinArraySubscriptExpr(First,
8055 Callee->getLocStart(),
8056 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008057 } else if (Op == OO_Arrow) {
8058 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008059 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8060 } else if (Second == 0 || isPostIncDec) {
8061 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008062 // The argument is not of overloadable type, so try to create a
8063 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008064 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008065 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008066
John McCall9ae2f072010-08-23 23:25:46 +00008067 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008068 }
8069 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008070 if (!First->getType()->isOverloadableType() &&
8071 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008072 // Neither of the arguments is an overloadable type, so try to
8073 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008074 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008075 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008076 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008077 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008078 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008079
Douglas Gregorb98b1992009-08-11 05:31:07 +00008080 return move(Result);
8081 }
8082 }
Mike Stump1eb44332009-09-09 15:08:12 +00008083
8084 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008085 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008086 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008087
John McCall9ae2f072010-08-23 23:25:46 +00008088 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008089 assert(ULE->requiresADL());
8090
8091 // FIXME: Do we have to check
8092 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008093 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008094 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008095 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008096 }
Mike Stump1eb44332009-09-09 15:08:12 +00008097
Douglas Gregorb98b1992009-08-11 05:31:07 +00008098 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008099 Expr *Args[2] = { First, Second };
8100 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008101
Douglas Gregorb98b1992009-08-11 05:31:07 +00008102 // Create the overloaded operator invocation for unary operators.
8103 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008104 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008105 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008106 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008107 }
Mike Stump1eb44332009-09-09 15:08:12 +00008108
Sebastian Redlf322ed62009-10-29 20:17:01 +00008109 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00008110 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00008111 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008112 First,
8113 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00008114
Douglas Gregorb98b1992009-08-11 05:31:07 +00008115 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008116 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008117 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008118 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8119 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008120 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008121
Mike Stump1eb44332009-09-09 15:08:12 +00008122 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008123}
Mike Stump1eb44332009-09-09 15:08:12 +00008124
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008125template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008126ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008127TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008128 SourceLocation OperatorLoc,
8129 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008130 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008131 TypeSourceInfo *ScopeType,
8132 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008133 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008134 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008135 QualType BaseType = Base->getType();
8136 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008137 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008138 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008139 !BaseType->getAs<PointerType>()->getPointeeType()
8140 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008141 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008142 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008143 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008144 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008145 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008146 /*FIXME?*/true);
8147 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008148
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008149 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008150 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8151 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8152 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8153 NameInfo.setNamedTypeInfo(DestroyedType);
8154
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008155 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008156
John McCall9ae2f072010-08-23 23:25:46 +00008157 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008158 OperatorLoc, isArrow,
8159 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008160 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008161 /*TemplateArgs*/ 0);
8162}
8163
Douglas Gregor577f75a2009-08-04 16:50:30 +00008164} // end namespace clang
8165
8166#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H