blob: 7995b0ba77cfafdadf8c45ec2b631c8dfccbc14c [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"
Richard Smith3e4c6c42011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
David Blaikiea71f9d02011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCalla2becad2009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000036#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCall781472f2010-08-25 08:40:02 +000040using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000041
Douglas Gregor577f75a2009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump1eb44332009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump1eb44332009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
101
102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
106
107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
111
Douglas Gregor577f75a2009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000114
Mike Stump1eb44332009-09-09 15:08:12 +0000115public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000116 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000117 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000118
Douglas Gregor577f75a2009-08-04 16:50:30 +0000119 /// \brief Retrieves a reference to the derived class.
120 Derived &getDerived() { return static_cast<Derived&>(*this); }
121
122 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000123 const Derived &getDerived() const {
124 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000125 }
126
John McCall60d7b3a2010-08-24 06:29:42 +0000127 static inline ExprResult Owned(Expr *E) { return E; }
128 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000129
Douglas Gregor577f75a2009-08-04 16:50:30 +0000130 /// \brief Retrieves a reference to the semantic analysis object used for
131 /// this tree transform.
132 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000133
Douglas Gregor577f75a2009-08-04 16:50:30 +0000134 /// \brief Whether the transformation should always rebuild AST nodes, even
135 /// if none of the children have changed.
136 ///
137 /// Subclasses may override this function to specify when the transformation
138 /// should rebuild all AST nodes.
139 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000140
Douglas Gregor577f75a2009-08-04 16:50:30 +0000141 /// \brief Returns the location of the entity being transformed, if that
142 /// information was not available elsewhere in the AST.
143 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000144 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000145 /// provide an alternative implementation that provides better location
146 /// information.
147 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000148
Douglas Gregor577f75a2009-08-04 16:50:30 +0000149 /// \brief Returns the name of the entity being transformed, if that
150 /// information was not available elsewhere in the AST.
151 ///
152 /// By default, returns an empty name. Subclasses can provide an alternative
153 /// implementation with a more precise name.
154 DeclarationName getBaseEntity() { return DeclarationName(); }
155
Douglas Gregorb98b1992009-08-11 05:31:07 +0000156 /// \brief Sets the "base" location and entity when that
157 /// information is known based on another transformation.
158 ///
159 /// By default, the source location and entity are ignored. Subclasses can
160 /// override this function to provide a customized implementation.
161 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000162
Douglas Gregorb98b1992009-08-11 05:31:07 +0000163 /// \brief RAII object that temporarily sets the base location and entity
164 /// used for reporting diagnostics in types.
165 class TemporaryBase {
166 TreeTransform &Self;
167 SourceLocation OldLocation;
168 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000169
Douglas Gregorb98b1992009-08-11 05:31:07 +0000170 public:
171 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000172 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000173 OldLocation = Self.getDerived().getBaseLocation();
174 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregorae201f72011-01-25 17:51:48 +0000175
176 if (Location.isValid())
177 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000178 }
Mike Stump1eb44332009-09-09 15:08:12 +0000179
Douglas Gregorb98b1992009-08-11 05:31:07 +0000180 ~TemporaryBase() {
181 Self.getDerived().setBase(OldLocation, OldEntity);
182 }
183 };
Mike Stump1eb44332009-09-09 15:08:12 +0000184
185 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000186 /// transformed.
187 ///
188 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000189 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000190 /// not change. For example, template instantiation need not traverse
191 /// non-dependent types.
192 bool AlreadyTransformed(QualType T) {
193 return T.isNull();
194 }
195
Douglas Gregor6eef5192009-12-14 19:27:10 +0000196 /// \brief Determine whether the given call argument should be dropped, e.g.,
197 /// because it is a default argument.
198 ///
199 /// Subclasses can provide an alternative implementation of this routine to
200 /// determine which kinds of call arguments get dropped. By default,
201 /// CXXDefaultArgument nodes are dropped (prior to transformation).
202 bool DropCallArgument(Expr *E) {
203 return E->isDefaultArgument();
204 }
Sean Huntc3021132010-05-05 15:23:54 +0000205
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000206 /// \brief Determine whether we should expand a pack expansion with the
207 /// given set of parameter packs into separate arguments by repeatedly
208 /// transforming the pattern.
209 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000210 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000211 /// Subclasses can override this routine to provide different behavior.
212 ///
213 /// \param EllipsisLoc The location of the ellipsis that identifies the
214 /// pack expansion.
215 ///
216 /// \param PatternRange The source range that covers the entire pattern of
217 /// the pack expansion.
218 ///
219 /// \param Unexpanded The set of unexpanded parameter packs within the
220 /// pattern.
221 ///
222 /// \param NumUnexpanded The number of unexpanded parameter packs in
223 /// \p Unexpanded.
224 ///
225 /// \param ShouldExpand Will be set to \c true if the transformer should
226 /// expand the corresponding pack expansions into separate arguments. When
227 /// set, \c NumExpansions must also be set.
228 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000229 /// \param RetainExpansion Whether the caller should add an unexpanded
230 /// pack expansion after all of the expanded arguments. This is used
231 /// when extending explicitly-specified template argument packs per
232 /// C++0x [temp.arg.explicit]p9.
233 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000234 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000235 /// the expanded form of the corresponding pack expansion. This is both an
236 /// input and an output parameter, which can be set by the caller if the
237 /// number of expansions is known a priori (e.g., due to a prior substitution)
238 /// and will be set by the callee when the number of expansions is known.
239 /// The callee must set this value when \c ShouldExpand is \c true; it may
240 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000241 ///
242 /// \returns true if an error occurred (e.g., because the parameter packs
243 /// are to be instantiated with arguments of different lengths), false
244 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
245 /// must be set.
246 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
247 SourceRange PatternRange,
David Blaikiea71f9d02011-09-22 02:34:54 +0000248 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000249 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000250 bool &RetainExpansion,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000251 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000252 ShouldExpand = false;
253 return false;
254 }
255
Douglas Gregord3731192011-01-10 07:32:04 +0000256 /// \brief "Forget" about the partially-substituted pack template argument,
257 /// when performing an instantiation that must preserve the parameter pack
258 /// use.
259 ///
260 /// This routine is meant to be overridden by the template instantiator.
261 TemplateArgument ForgetPartiallySubstitutedPack() {
262 return TemplateArgument();
263 }
264
265 /// \brief "Remember" the partially-substituted pack template argument
266 /// after performing an instantiation that must preserve the parameter pack
267 /// use.
268 ///
269 /// This routine is meant to be overridden by the template instantiator.
270 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
271
Douglas Gregor12c9c002011-01-07 16:43:16 +0000272 /// \brief Note to the derived class when a function parameter pack is
273 /// being expanded.
274 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
275
Douglas Gregor577f75a2009-08-04 16:50:30 +0000276 /// \brief Transforms the given type into another type.
277 ///
John McCalla2becad2009-10-21 00:40:46 +0000278 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000279 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000280 /// function. This is expensive, but we don't mind, because
281 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000282 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000283 ///
284 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000285 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000286
John McCalla2becad2009-10-21 00:40:46 +0000287 /// \brief Transforms the given type-with-location into a new
288 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000289 ///
John McCalla2becad2009-10-21 00:40:46 +0000290 /// By default, this routine transforms a type by delegating to the
291 /// appropriate TransformXXXType to build a new type. Subclasses
292 /// may override this function (to take over all type
293 /// transformations) or some set of the TransformXXXType functions
294 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000295 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000296
297 /// \brief Transform the given type-with-location into a new
298 /// type, collecting location information in the given builder
299 /// as necessary.
300 ///
John McCall43fed0d2010-11-12 08:19:04 +0000301 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000302
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000303 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000304 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000305 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000306 /// appropriate TransformXXXStmt function to transform a specific kind of
307 /// statement or the TransformExpr() function to transform an expression.
308 /// Subclasses may override this function to transform statements using some
309 /// other mechanism.
310 ///
311 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000312 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000313
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000314 /// \brief Transform the given expression.
315 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000316 /// By default, this routine transforms an expression by delegating to the
317 /// appropriate TransformXXXExpr function to build a new expression.
318 /// Subclasses may override this function to transform expressions using some
319 /// other mechanism.
320 ///
321 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000322 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000323
Douglas Gregoraa165f82011-01-03 19:04:46 +0000324 /// \brief Transform the given list of expressions.
325 ///
326 /// This routine transforms a list of expressions by invoking
327 /// \c TransformExpr() for each subexpression. However, it also provides
328 /// support for variadic templates by expanding any pack expansions (if the
329 /// derived class permits such expansion) along the way. When pack expansions
330 /// are present, the number of outputs may not equal the number of inputs.
331 ///
332 /// \param Inputs The set of expressions to be transformed.
333 ///
334 /// \param NumInputs The number of expressions in \c Inputs.
335 ///
336 /// \param IsCall If \c true, then this transform is being performed on
337 /// function-call arguments, and any arguments that should be dropped, will
338 /// be.
339 ///
340 /// \param Outputs The transformed input expressions will be added to this
341 /// vector.
342 ///
343 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
344 /// due to transformation.
345 ///
346 /// \returns true if an error occurred, false otherwise.
347 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +0000348 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +0000349 bool *ArgChanged = 0);
350
Douglas Gregor577f75a2009-08-04 16:50:30 +0000351 /// \brief Transform the given declaration, which is referenced from a type
352 /// or expression.
353 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000354 /// By default, acts as the identity function on declarations. Subclasses
355 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000356 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000357
358 /// \brief Transform the definition of the given declaration.
359 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000360 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000361 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000362 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
363 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000364 }
Mike Stump1eb44332009-09-09 15:08:12 +0000365
Douglas Gregor6cd21982009-10-20 05:58:46 +0000366 /// \brief Transform the given declaration, which was the first part of a
367 /// nested-name-specifier in a member access expression.
368 ///
Sean Huntc3021132010-05-05 15:23:54 +0000369 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000370 /// identifier in a nested-name-specifier of a member access expression, e.g.,
371 /// the \c T in \c x->T::member
372 ///
373 /// By default, invokes TransformDecl() to transform the declaration.
374 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000375 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
376 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000377 }
Sean Huntc3021132010-05-05 15:23:54 +0000378
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000379 /// \brief Transform the given nested-name-specifier with source-location
380 /// information.
381 ///
382 /// By default, transforms all of the types and declarations within the
383 /// nested-name-specifier. Subclasses may override this function to provide
384 /// alternate behavior.
385 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
386 NestedNameSpecifierLoc NNS,
387 QualType ObjectType = QualType(),
388 NamedDecl *FirstQualifierInScope = 0);
389
Douglas Gregor81499bb2009-09-03 22:13:48 +0000390 /// \brief Transform the given declaration name.
391 ///
392 /// By default, transforms the types of conversion function, constructor,
393 /// and destructor names and then (if needed) rebuilds the declaration name.
394 /// Identifiers and selectors are returned unmodified. Sublcasses may
395 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000396 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000397 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000398
Douglas Gregor577f75a2009-08-04 16:50:30 +0000399 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000400 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000401 /// \param SS The nested-name-specifier that qualifies the template
402 /// name. This nested-name-specifier must already have been transformed.
403 ///
404 /// \param Name The template name to transform.
405 ///
406 /// \param NameLoc The source location of the template name.
407 ///
408 /// \param ObjectType If we're translating a template name within a member
409 /// access expression, this is the type of the object whose member template
410 /// is being referenced.
411 ///
412 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
413 /// also refers to a name within the current (lexical) scope, this is the
414 /// declaration it refers to.
415 ///
416 /// By default, transforms the template name by transforming the declarations
417 /// and nested-name-specifiers that occur within the template name.
418 /// Subclasses may override this function to provide alternate behavior.
419 TemplateName TransformTemplateName(CXXScopeSpec &SS,
420 TemplateName Name,
421 SourceLocation NameLoc,
422 QualType ObjectType = QualType(),
423 NamedDecl *FirstQualifierInScope = 0);
424
Douglas Gregor577f75a2009-08-04 16:50:30 +0000425 /// \brief Transform the given template argument.
426 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000427 /// By default, this operation transforms the type, expression, or
428 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000429 /// new template argument from the transformed result. Subclasses may
430 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000431 ///
432 /// Returns true if there was an error.
433 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
434 TemplateArgumentLoc &Output);
435
Douglas Gregorfcc12532010-12-20 17:31:10 +0000436 /// \brief Transform the given set of template arguments.
437 ///
438 /// By default, this operation transforms all of the template arguments
439 /// in the input set using \c TransformTemplateArgument(), and appends
440 /// the transformed arguments to the output list.
441 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000442 /// Note that this overload of \c TransformTemplateArguments() is merely
443 /// a convenience function. Subclasses that wish to override this behavior
444 /// should override the iterator-based member template version.
445 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000446 /// \param Inputs The set of template arguments to be transformed.
447 ///
448 /// \param NumInputs The number of template arguments in \p Inputs.
449 ///
450 /// \param Outputs The set of transformed template arguments output by this
451 /// routine.
452 ///
453 /// Returns true if an error occurred.
454 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
455 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000456 TemplateArgumentListInfo &Outputs) {
457 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
458 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000459
460 /// \brief Transform the given set of template arguments.
461 ///
462 /// By default, this operation transforms all of the template arguments
463 /// in the input set using \c TransformTemplateArgument(), and appends
464 /// the transformed arguments to the output list.
465 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000466 /// \param First An iterator to the first template argument.
467 ///
468 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000469 ///
470 /// \param Outputs The set of transformed template arguments output by this
471 /// routine.
472 ///
473 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000474 template<typename InputIterator>
475 bool TransformTemplateArguments(InputIterator First,
476 InputIterator Last,
477 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000478
John McCall833ca992009-10-29 08:12:44 +0000479 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
480 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
481 TemplateArgumentLoc &ArgLoc);
482
John McCalla93c9342009-12-07 02:54:59 +0000483 /// \brief Fakes up a TypeSourceInfo for a type.
484 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
485 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000486 getDerived().getBaseLocation());
487 }
Mike Stump1eb44332009-09-09 15:08:12 +0000488
John McCalla2becad2009-10-21 00:40:46 +0000489#define ABSTRACT_TYPELOC(CLASS, PARENT)
490#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000491 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000492#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000493
John Wiegley28bbe4b2011-04-28 01:08:34 +0000494 StmtResult
495 TransformSEHHandler(Stmt *Handler);
496
John McCall43fed0d2010-11-12 08:19:04 +0000497 QualType
498 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
499 TemplateSpecializationTypeLoc TL,
500 TemplateName Template);
501
502 QualType
503 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
504 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000505 TemplateName Template,
506 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000507
508 QualType
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000510 DependentTemplateSpecializationTypeLoc TL,
511 NestedNameSpecifierLoc QualifierLoc);
512
John McCall21ef0fa2010-03-11 09:03:00 +0000513 /// \brief Transforms the parameters of a function type into the
514 /// given vectors.
515 ///
516 /// The result vectors should be kept in sync; null entries in the
517 /// variables vector are acceptable.
518 ///
519 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000520 bool TransformFunctionTypeParams(SourceLocation Loc,
521 ParmVarDecl **Params, unsigned NumParams,
522 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +0000523 SmallVectorImpl<QualType> &PTypes,
524 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000525
526 /// \brief Transforms a single function-type parameter. Return null
527 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000528 ///
529 /// \param indexAdjustment - A number to add to the parameter's
530 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000531 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000532 int indexAdjustment,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000533 llvm::Optional<unsigned> NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +0000534
John McCall43fed0d2010-11-12 08:19:04 +0000535 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000536
John McCall60d7b3a2010-08-24 06:29:42 +0000537 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
538 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000539
Douglas Gregor43959a92009-08-20 07:17:43 +0000540#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000541 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000542#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000543 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000544#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000545#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000546
Douglas Gregor577f75a2009-08-04 16:50:30 +0000547 /// \brief Build a new pointer type given its pointee type.
548 ///
549 /// By default, performs semantic analysis when building the pointer type.
550 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000551 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000552
553 /// \brief Build a new block pointer type given its pointee type.
554 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000555 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000556 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000557 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000558
John McCall85737a72009-10-30 00:06:24 +0000559 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000560 ///
John McCall85737a72009-10-30 00:06:24 +0000561 /// By default, performs semantic analysis when building the
562 /// reference type. Subclasses may override this routine to provide
563 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000564 ///
John McCall85737a72009-10-30 00:06:24 +0000565 /// \param LValue whether the type was written with an lvalue sigil
566 /// or an rvalue sigil.
567 QualType RebuildReferenceType(QualType ReferentType,
568 bool LValue,
569 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000570
Douglas Gregor577f75a2009-08-04 16:50:30 +0000571 /// \brief Build a new member pointer type given the pointee type and the
572 /// class type it refers into.
573 ///
574 /// By default, performs semantic analysis when building the member pointer
575 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000576 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
577 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000578
Douglas Gregor577f75a2009-08-04 16:50:30 +0000579 /// \brief Build a new array type given the element type, size
580 /// modifier, size of the array (if known), size expression, and index type
581 /// qualifiers.
582 ///
583 /// By default, performs semantic analysis when building the array type.
584 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000585 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000586 QualType RebuildArrayType(QualType ElementType,
587 ArrayType::ArraySizeModifier SizeMod,
588 const llvm::APInt *Size,
589 Expr *SizeExpr,
590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000592
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593 /// \brief Build a new constant array type given the element type, size
594 /// modifier, (known) size of the array, and index type qualifiers.
595 ///
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000598 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
600 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000603
Douglas Gregor577f75a2009-08-04 16:50:30 +0000604 /// \brief Build a new incomplete array type given the element type, size
605 /// modifier, and index type qualifiers.
606 ///
607 /// By default, performs semantic analysis when building the array type.
608 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000609 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000610 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000613
Mike Stump1eb44332009-09-09 15:08:12 +0000614 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000615 /// size modifier, size expression, and index type qualifiers.
616 ///
617 /// By default, performs semantic analysis when building the array type.
618 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000619 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000620 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000621 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
624
Mike Stump1eb44332009-09-09 15:08:12 +0000625 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000626 /// size modifier, size expression, and index type qualifiers.
627 ///
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000630 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000632 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
635
636 /// \brief Build a new vector type given the element type and
637 /// number of elements.
638 ///
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000641 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000642 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000643
Douglas Gregor577f75a2009-08-04 16:50:30 +0000644 /// \brief Build a new extended vector type given the element type and
645 /// number of elements.
646 ///
647 /// By default, performs semantic analysis when building the vector type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
650 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000651
652 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000653 /// given the element type and number of elements.
654 ///
655 /// By default, performs semantic analysis when building the vector type.
656 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000657 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000659 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000660
Douglas Gregor577f75a2009-08-04 16:50:30 +0000661 /// \brief Build a new function type.
662 ///
663 /// By default, performs semantic analysis when building the function type.
664 /// Subclasses may override this routine to provide different behavior.
665 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000666 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000667 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000668 bool Variadic, unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000669 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000670 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000671
John McCalla2becad2009-10-21 00:40:46 +0000672 /// \brief Build a new unprototyped function type.
673 QualType RebuildFunctionNoProtoType(QualType ResultType);
674
John McCalled976492009-12-04 22:46:56 +0000675 /// \brief Rebuild an unresolved typename type, given the decl that
676 /// the UnresolvedUsingTypenameDecl was transformed to.
677 QualType RebuildUnresolvedUsingType(Decl *D);
678
Douglas Gregor577f75a2009-08-04 16:50:30 +0000679 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000680 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 return SemaRef.Context.getTypeDeclType(Typedef);
682 }
683
684 /// \brief Build a new class/struct/union type.
685 QualType RebuildRecordType(RecordDecl *Record) {
686 return SemaRef.Context.getTypeDeclType(Record);
687 }
688
689 /// \brief Build a new Enum type.
690 QualType RebuildEnumType(EnumDecl *Enum) {
691 return SemaRef.Context.getTypeDeclType(Enum);
692 }
John McCall7da24312009-09-05 00:15:47 +0000693
Mike Stump1eb44332009-09-09 15:08:12 +0000694 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000695 ///
696 /// By default, performs semantic analysis when building the typeof type.
697 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000698 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000699
Mike Stump1eb44332009-09-09 15:08:12 +0000700 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000701 ///
702 /// By default, builds a new TypeOfType with the given underlying type.
703 QualType RebuildTypeOfType(QualType Underlying);
704
Sean Huntca63c202011-05-24 22:41:36 +0000705 /// \brief Build a new unary transform type.
706 QualType RebuildUnaryTransformType(QualType BaseType,
707 UnaryTransformType::UTTKind UKind,
708 SourceLocation Loc);
709
Mike Stump1eb44332009-09-09 15:08:12 +0000710 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000711 ///
712 /// By default, performs semantic analysis when building the decltype type.
713 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000714 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000715
Richard Smith34b41d92011-02-20 03:19:35 +0000716 /// \brief Build a new C++0x auto type.
717 ///
718 /// By default, builds a new AutoType with the given deduced type.
719 QualType RebuildAutoType(QualType Deduced) {
720 return SemaRef.Context.getAutoType(Deduced);
721 }
722
Douglas Gregor577f75a2009-08-04 16:50:30 +0000723 /// \brief Build a new template specialization type.
724 ///
725 /// By default, performs semantic analysis when building the template
726 /// specialization type. Subclasses may override this routine to provide
727 /// different behavior.
728 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000729 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000730 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000731
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000732 /// \brief Build a new parenthesized type.
733 ///
734 /// By default, builds a new ParenType type from the inner type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildParenType(QualType InnerType) {
737 return SemaRef.Context.getParenType(InnerType);
738 }
739
Douglas Gregor577f75a2009-08-04 16:50:30 +0000740 /// \brief Build a new qualified name type.
741 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000742 /// By default, builds a new ElaboratedType type from the keyword,
743 /// the nested-name-specifier and the named type.
744 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000745 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
746 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000747 NestedNameSpecifierLoc QualifierLoc,
748 QualType Named) {
749 return SemaRef.Context.getElaboratedType(Keyword,
750 QualifierLoc.getNestedNameSpecifier(),
751 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000752 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000753
754 /// \brief Build a new typename type that refers to a template-id.
755 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000756 /// By default, builds a new DependentNameType type from the
757 /// nested-name-specifier and the given type. Subclasses may override
758 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000759 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000760 ElaboratedTypeKeyword Keyword,
761 NestedNameSpecifierLoc QualifierLoc,
762 const IdentifierInfo *Name,
763 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000764 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000765 // Rebuild the template name.
766 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000767 CXXScopeSpec SS;
768 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000769 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000770 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000771
772 if (InstName.isNull())
773 return QualType();
774
775 // If it's still dependent, make a dependent specialization.
776 if (InstName.getAsDependentTemplateName())
777 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
778 QualifierLoc.getNestedNameSpecifier(),
779 Name,
780 Args);
781
782 // Otherwise, make an elaborated type wrapping a non-dependent
783 // specialization.
784 QualType T =
785 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
786 if (T.isNull()) return QualType();
787
788 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
789 return T;
790
791 return SemaRef.Context.getElaboratedType(Keyword,
792 QualifierLoc.getNestedNameSpecifier(),
793 T);
794 }
795
Douglas Gregor577f75a2009-08-04 16:50:30 +0000796 /// \brief Build a new typename type that refers to an identifier.
797 ///
798 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000799 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000800 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000801 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000802 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000803 NestedNameSpecifierLoc QualifierLoc,
804 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000805 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000806 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000807 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000808
Douglas Gregor2494dd02011-03-01 01:34:45 +0000809 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000810 // If the name is still dependent, just build a new dependent name type.
811 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000812 return SemaRef.Context.getDependentNameType(Keyword,
813 QualifierLoc.getNestedNameSpecifier(),
814 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000815 }
816
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000817 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000818 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000819 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000820
821 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
822
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000823 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000824 // into a non-dependent elaborated-type-specifier. Find the tag we're
825 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000826 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000827 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
828 if (!DC)
829 return QualType();
830
John McCall56138762010-05-27 06:40:31 +0000831 if (SemaRef.RequireCompleteDeclContext(SS, DC))
832 return QualType();
833
Douglas Gregor40336422010-03-31 22:19:08 +0000834 TagDecl *Tag = 0;
835 SemaRef.LookupQualifiedName(Result, DC);
836 switch (Result.getResultKind()) {
837 case LookupResult::NotFound:
838 case LookupResult::NotFoundInCurrentInstantiation:
839 break;
Sean Huntc3021132010-05-05 15:23:54 +0000840
Douglas Gregor40336422010-03-31 22:19:08 +0000841 case LookupResult::Found:
842 Tag = Result.getAsSingle<TagDecl>();
843 break;
Sean Huntc3021132010-05-05 15:23:54 +0000844
Douglas Gregor40336422010-03-31 22:19:08 +0000845 case LookupResult::FoundOverloaded:
846 case LookupResult::FoundUnresolvedValue:
847 llvm_unreachable("Tag lookup cannot find non-tags");
848 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000849
Douglas Gregor40336422010-03-31 22:19:08 +0000850 case LookupResult::Ambiguous:
851 // Let the LookupResult structure handle ambiguities.
852 return QualType();
853 }
854
855 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000856 // Check where the name exists but isn't a tag type and use that to emit
857 // better diagnostics.
858 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
859 SemaRef.LookupQualifiedName(Result, DC);
860 switch (Result.getResultKind()) {
861 case LookupResult::Found:
862 case LookupResult::FoundOverloaded:
863 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000864 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000865 unsigned Kind = 0;
866 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000867 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
868 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000869 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
870 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
871 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000872 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000873 default:
874 // FIXME: Would be nice to highlight just the source range.
875 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
876 << Kind << Id << DC;
877 break;
878 }
Douglas Gregor40336422010-03-31 22:19:08 +0000879 return QualType();
880 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000881
Richard Trieubbf34c02011-06-10 03:11:26 +0000882 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
883 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000884 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000885 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
886 return QualType();
887 }
888
889 // Build the elaborated-type-specifier type.
890 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000891 return SemaRef.Context.getElaboratedType(Keyword,
892 QualifierLoc.getNestedNameSpecifier(),
893 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000894 }
Mike Stump1eb44332009-09-09 15:08:12 +0000895
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000896 /// \brief Build a new pack expansion type.
897 ///
898 /// By default, builds a new PackExpansionType type from the given pattern.
899 /// Subclasses may override this routine to provide different behavior.
900 QualType RebuildPackExpansionType(QualType Pattern,
901 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000902 SourceLocation EllipsisLoc,
903 llvm::Optional<unsigned> NumExpansions) {
904 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
905 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000906 }
907
Eli Friedmanb001de72011-10-06 23:00:33 +0000908 /// \brief Build a new atomic type given its value type.
909 ///
910 /// By default, performs semantic analysis when building the atomic type.
911 /// Subclasses may override this routine to provide different behavior.
912 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
913
Douglas Gregord1067e52009-08-06 06:41:21 +0000914 /// \brief Build a new template name given a nested name specifier, a flag
915 /// indicating whether the "template" keyword was provided, and the template
916 /// that the template name refers to.
917 ///
918 /// By default, builds the new template name directly. Subclasses may override
919 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000920 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000921 bool TemplateKW,
922 TemplateDecl *Template);
923
Douglas Gregord1067e52009-08-06 06:41:21 +0000924 /// \brief Build a new template name given a nested name specifier and the
925 /// name that is referred to as a template.
926 ///
927 /// By default, performs semantic analysis to determine whether the name can
928 /// be resolved to a specific template, then builds the appropriate kind of
929 /// template name. Subclasses may override this routine to provide different
930 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000931 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
932 const IdentifierInfo &Name,
933 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000934 QualType ObjectType,
935 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000936
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000937 /// \brief Build a new template name given a nested name specifier and the
938 /// overloaded operator name that is referred to as a template.
939 ///
940 /// By default, performs semantic analysis to determine whether the name can
941 /// be resolved to a specific template, then builds the appropriate kind of
942 /// template name. Subclasses may override this routine to provide different
943 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000944 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000945 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000946 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000947 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000948
949 /// \brief Build a new template name given a template template parameter pack
950 /// and the
951 ///
952 /// By default, performs semantic analysis to determine whether the name can
953 /// be resolved to a specific template, then builds the appropriate kind of
954 /// template name. Subclasses may override this routine to provide different
955 /// behavior.
956 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
957 const TemplateArgument &ArgPack) {
958 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
959 }
960
Douglas Gregor43959a92009-08-20 07:17:43 +0000961 /// \brief Build a new compound statement.
962 ///
963 /// By default, performs semantic analysis to build the new statement.
964 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000965 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000966 MultiStmtArg Statements,
967 SourceLocation RBraceLoc,
968 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000969 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000970 IsStmtExpr);
971 }
972
973 /// \brief Build a new case statement.
974 ///
975 /// By default, performs semantic analysis to build the new statement.
976 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000977 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000978 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000979 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000980 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000981 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000982 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000983 ColonLoc);
984 }
Mike Stump1eb44332009-09-09 15:08:12 +0000985
Douglas Gregor43959a92009-08-20 07:17:43 +0000986 /// \brief Attach the body to a new case statement.
987 ///
988 /// By default, performs semantic analysis to build the new statement.
989 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000990 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000991 getSema().ActOnCaseStmtBody(S, Body);
992 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000993 }
Mike Stump1eb44332009-09-09 15:08:12 +0000994
Douglas Gregor43959a92009-08-20 07:17:43 +0000995 /// \brief Build a new default statement.
996 ///
997 /// By default, performs semantic analysis to build the new statement.
998 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000999 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001000 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001001 Stmt *SubStmt) {
1002 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001003 /*CurScope=*/0);
1004 }
Mike Stump1eb44332009-09-09 15:08:12 +00001005
Douglas Gregor43959a92009-08-20 07:17:43 +00001006 /// \brief Build a new label statement.
1007 ///
1008 /// By default, performs semantic analysis to build the new statement.
1009 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001010 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1011 SourceLocation ColonLoc, Stmt *SubStmt) {
1012 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001013 }
Mike Stump1eb44332009-09-09 15:08:12 +00001014
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 /// \brief Build a new "if" statement.
1016 ///
1017 /// By default, performs semantic analysis to build the new statement.
1018 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001019 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001020 VarDecl *CondVar, Stmt *Then,
1021 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001022 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001023 }
Mike Stump1eb44332009-09-09 15:08:12 +00001024
Douglas Gregor43959a92009-08-20 07:17:43 +00001025 /// \brief Start building a new switch statement.
1026 ///
1027 /// By default, performs semantic analysis to build the new statement.
1028 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001029 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001030 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001031 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001032 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001033 }
Mike Stump1eb44332009-09-09 15:08:12 +00001034
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 /// \brief Attach the body to the switch statement.
1036 ///
1037 /// By default, performs semantic analysis to build the new statement.
1038 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001039 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001040 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001041 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001042 }
1043
1044 /// \brief Build a new while statement.
1045 ///
1046 /// By default, performs semantic analysis to build the new statement.
1047 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001048 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1049 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001050 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001051 }
Mike Stump1eb44332009-09-09 15:08:12 +00001052
Douglas Gregor43959a92009-08-20 07:17:43 +00001053 /// \brief Build a new do-while statement.
1054 ///
1055 /// By default, performs semantic analysis to build the new statement.
1056 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001057 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001058 SourceLocation WhileLoc, SourceLocation LParenLoc,
1059 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001060 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1061 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001062 }
1063
1064 /// \brief Build a new for statement.
1065 ///
1066 /// By default, performs semantic analysis to build the new statement.
1067 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001068 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1069 Stmt *Init, Sema::FullExprArg Cond,
1070 VarDecl *CondVar, Sema::FullExprArg Inc,
1071 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001072 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001073 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001074 }
Mike Stump1eb44332009-09-09 15:08:12 +00001075
Douglas Gregor43959a92009-08-20 07:17:43 +00001076 /// \brief Build a new goto statement.
1077 ///
1078 /// By default, performs semantic analysis to build the new statement.
1079 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001080 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1081 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001082 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001083 }
1084
1085 /// \brief Build a new indirect goto statement.
1086 ///
1087 /// By default, performs semantic analysis to build the new statement.
1088 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001089 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001090 SourceLocation StarLoc,
1091 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001092 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001093 }
Mike Stump1eb44332009-09-09 15:08:12 +00001094
Douglas Gregor43959a92009-08-20 07:17:43 +00001095 /// \brief Build a new return statement.
1096 ///
1097 /// By default, performs semantic analysis to build the new statement.
1098 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001099 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001100 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001101 }
Mike Stump1eb44332009-09-09 15:08:12 +00001102
Douglas Gregor43959a92009-08-20 07:17:43 +00001103 /// \brief Build a new declaration statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001107 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001108 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001109 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001110 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1111 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001112 }
Mike Stump1eb44332009-09-09 15:08:12 +00001113
Anders Carlsson703e3942010-01-24 05:50:09 +00001114 /// \brief Build a new inline asm statement.
1115 ///
1116 /// By default, performs semantic analysis to build the new statement.
1117 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001118 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001119 bool IsSimple,
1120 bool IsVolatile,
1121 unsigned NumOutputs,
1122 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001123 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001124 MultiExprArg Constraints,
1125 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001126 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001127 MultiExprArg Clobbers,
1128 SourceLocation RParenLoc,
1129 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001130 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001131 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001132 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001133 RParenLoc, MSAsm);
1134 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001135
1136 /// \brief Build a new Objective-C @try statement.
1137 ///
1138 /// By default, performs semantic analysis to build the new statement.
1139 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001140 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001141 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001142 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001143 Stmt *Finally) {
1144 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1145 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001146 }
1147
Douglas Gregorbe270a02010-04-26 17:57:08 +00001148 /// \brief Rebuild an Objective-C exception declaration.
1149 ///
1150 /// By default, performs semantic analysis to build the new declaration.
1151 /// Subclasses may override this routine to provide different behavior.
1152 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1153 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001154 return getSema().BuildObjCExceptionDecl(TInfo, T,
1155 ExceptionDecl->getInnerLocStart(),
1156 ExceptionDecl->getLocation(),
1157 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001158 }
Sean Huntc3021132010-05-05 15:23:54 +00001159
Douglas Gregorbe270a02010-04-26 17:57:08 +00001160 /// \brief Build a new Objective-C @catch statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001164 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001165 SourceLocation RParenLoc,
1166 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001167 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001168 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001169 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001170 }
Sean Huntc3021132010-05-05 15:23:54 +00001171
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001172 /// \brief Build a new Objective-C @finally statement.
1173 ///
1174 /// By default, performs semantic analysis to build the new statement.
1175 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001176 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001177 Stmt *Body) {
1178 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001179 }
Sean Huntc3021132010-05-05 15:23:54 +00001180
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001181 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001185 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001186 Expr *Operand) {
1187 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001188 }
Sean Huntc3021132010-05-05 15:23:54 +00001189
John McCall07524032011-07-27 21:50:02 +00001190 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1191 ///
1192 /// By default, performs semantic analysis to build the new statement.
1193 /// Subclasses may override this routine to provide different behavior.
1194 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1195 Expr *object) {
1196 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1197 }
1198
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001199 /// \brief Build a new Objective-C @synchronized statement.
1200 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001201 /// By default, performs semantic analysis to build the new statement.
1202 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001203 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001204 Expr *Object, Stmt *Body) {
1205 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001206 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001207
John McCallf85e1932011-06-15 23:02:42 +00001208 /// \brief Build a new Objective-C @autoreleasepool statement.
1209 ///
1210 /// By default, performs semantic analysis to build the new statement.
1211 /// Subclasses may override this routine to provide different behavior.
1212 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1213 Stmt *Body) {
1214 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1215 }
John McCall990567c2011-07-27 01:07:15 +00001216
1217 /// \brief Build the collection operand to a new Objective-C fast
1218 /// enumeration statement.
1219 ///
1220 /// By default, performs semantic analysis to build the new statement.
1221 /// Subclasses may override this routine to provide different behavior.
1222 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1223 Expr *collection) {
1224 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1225 }
John McCallf85e1932011-06-15 23:02:42 +00001226
Douglas Gregorc3203e72010-04-22 23:10:45 +00001227 /// \brief Build a new Objective-C fast enumeration statement.
1228 ///
1229 /// By default, performs semantic analysis to build the new statement.
1230 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001231 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001232 SourceLocation LParenLoc,
1233 Stmt *Element,
1234 Expr *Collection,
1235 SourceLocation RParenLoc,
1236 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001237 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001238 Element,
1239 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001240 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001241 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001242 }
Sean Huntc3021132010-05-05 15:23:54 +00001243
Douglas Gregor43959a92009-08-20 07:17:43 +00001244 /// \brief Build a new C++ exception declaration.
1245 ///
1246 /// By default, performs semantic analysis to build the new decaration.
1247 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001248 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001249 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001250 SourceLocation StartLoc,
1251 SourceLocation IdLoc,
1252 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001253 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1254 StartLoc, IdLoc, Id);
1255 if (Var)
1256 getSema().CurContext->addDecl(Var);
1257 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001258 }
1259
1260 /// \brief Build a new C++ catch statement.
1261 ///
1262 /// By default, performs semantic analysis to build the new statement.
1263 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001264 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001265 VarDecl *ExceptionDecl,
1266 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001267 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1268 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001269 }
Mike Stump1eb44332009-09-09 15:08:12 +00001270
Douglas Gregor43959a92009-08-20 07:17:43 +00001271 /// \brief Build a new C++ try statement.
1272 ///
1273 /// By default, performs semantic analysis to build the new statement.
1274 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001275 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001276 Stmt *TryBlock,
1277 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001278 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001279 }
Mike Stump1eb44332009-09-09 15:08:12 +00001280
Richard Smithad762fc2011-04-14 22:09:26 +00001281 /// \brief Build a new C++0x range-based for statement.
1282 ///
1283 /// By default, performs semantic analysis to build the new statement.
1284 /// Subclasses may override this routine to provide different behavior.
1285 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1286 SourceLocation ColonLoc,
1287 Stmt *Range, Stmt *BeginEnd,
1288 Expr *Cond, Expr *Inc,
1289 Stmt *LoopVar,
1290 SourceLocation RParenLoc) {
1291 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1292 Cond, Inc, LoopVar, RParenLoc);
1293 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001294
1295 /// \brief Build a new C++0x range-based for statement.
1296 ///
1297 /// By default, performs semantic analysis to build the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
1299 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1300 bool IsIfExists,
1301 NestedNameSpecifierLoc QualifierLoc,
1302 DeclarationNameInfo NameInfo,
1303 Stmt *Nested) {
1304 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1305 QualifierLoc, NameInfo, Nested);
1306 }
1307
Richard Smithad762fc2011-04-14 22:09:26 +00001308 /// \brief Attach body to a C++0x range-based for statement.
1309 ///
1310 /// By default, performs semantic analysis to finish the new statement.
1311 /// Subclasses may override this routine to provide different behavior.
1312 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1313 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1314 }
1315
John Wiegley28bbe4b2011-04-28 01:08:34 +00001316 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1317 SourceLocation TryLoc,
1318 Stmt *TryBlock,
1319 Stmt *Handler) {
1320 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1321 }
1322
1323 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1324 Expr *FilterExpr,
1325 Stmt *Block) {
1326 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1327 }
1328
1329 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1330 Stmt *Block) {
1331 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1332 }
1333
Douglas Gregorb98b1992009-08-11 05:31:07 +00001334 /// \brief Build a new expression that references a declaration.
1335 ///
1336 /// By default, performs semantic analysis to build the new expression.
1337 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001338 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001339 LookupResult &R,
1340 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001341 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1342 }
1343
1344
1345 /// \brief Build a new expression that references a declaration.
1346 ///
1347 /// By default, performs semantic analysis to build the new expression.
1348 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001349 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001350 ValueDecl *VD,
1351 const DeclarationNameInfo &NameInfo,
1352 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001353 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001354 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001355
1356 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001357
1358 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001359 }
Mike Stump1eb44332009-09-09 15:08:12 +00001360
Douglas Gregorb98b1992009-08-11 05:31:07 +00001361 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001362 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001363 /// By default, performs semantic analysis to build the new expression.
1364 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001365 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001366 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001367 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001368 }
1369
Douglas Gregora71d8192009-09-04 17:36:40 +00001370 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001371 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001372 /// By default, performs semantic analysis to build the new expression.
1373 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001374 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001375 SourceLocation OperatorLoc,
1376 bool isArrow,
1377 CXXScopeSpec &SS,
1378 TypeSourceInfo *ScopeType,
1379 SourceLocation CCLoc,
1380 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001381 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001382
Douglas Gregorb98b1992009-08-11 05:31:07 +00001383 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001384 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001385 /// By default, performs semantic analysis to build the new expression.
1386 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001387 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001388 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001389 Expr *SubExpr) {
1390 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001391 }
Mike Stump1eb44332009-09-09 15:08:12 +00001392
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001393 /// \brief Build a new builtin offsetof expression.
1394 ///
1395 /// By default, performs semantic analysis to build the new expression.
1396 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001397 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001398 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001399 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001400 unsigned NumComponents,
1401 SourceLocation RParenLoc) {
1402 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1403 NumComponents, RParenLoc);
1404 }
Sean Huntc3021132010-05-05 15:23:54 +00001405
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001406 /// \brief Build a new sizeof, alignof or vec_step expression with a
1407 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001408 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 /// By default, performs semantic analysis to build the new expression.
1410 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001411 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1412 SourceLocation OpLoc,
1413 UnaryExprOrTypeTrait ExprKind,
1414 SourceRange R) {
1415 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001416 }
1417
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001418 /// \brief Build a new sizeof, alignof or vec step expression with an
1419 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001420 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 /// By default, performs semantic analysis to build the new expression.
1422 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001423 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1424 UnaryExprOrTypeTrait ExprKind,
1425 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001426 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001427 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001428 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001429 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001430
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 return move(Result);
1432 }
Mike Stump1eb44332009-09-09 15:08:12 +00001433
Douglas Gregorb98b1992009-08-11 05:31:07 +00001434 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001435 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001438 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001440 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001441 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001442 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1443 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001444 RBracketLoc);
1445 }
1446
1447 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001448 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001449 /// By default, performs semantic analysis to build the new expression.
1450 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001451 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001452 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001453 SourceLocation RParenLoc,
1454 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001455 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001456 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001457 }
1458
1459 /// \brief Build a new member access 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 RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001464 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001465 NestedNameSpecifierLoc QualifierLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001466 const DeclarationNameInfo &MemberNameInfo,
1467 ValueDecl *Member,
1468 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001469 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001470 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001471 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1472 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001473 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001474 // We have a reference to an unnamed field. This is always the
1475 // base of an anonymous struct/union member access, i.e. the
1476 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001477 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001478 assert(Member->getType()->isRecordType() &&
1479 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001480
Richard Smith9138b4e2011-10-26 19:06:56 +00001481 BaseResult =
1482 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001483 QualifierLoc.getNestedNameSpecifier(),
1484 FoundDecl, Member);
1485 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001486 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001487 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001488 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001489 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001490 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001491 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001492 cast<FieldDecl>(Member)->getType(),
1493 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001494 return getSema().Owned(ME);
1495 }
Mike Stump1eb44332009-09-09 15:08:12 +00001496
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001497 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001498 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001499
John Wiegley429bb272011-04-08 18:41:53 +00001500 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001501 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001502
John McCall6bb80172010-03-30 21:47:33 +00001503 // FIXME: this involves duplicating earlier analysis in a lot of
1504 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001505 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001506 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001507 R.resolveKind();
1508
John McCall9ae2f072010-08-23 23:25:46 +00001509 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001510 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001511 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 }
Mike Stump1eb44332009-09-09 15:08:12 +00001513
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001515 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 /// By default, performs semantic analysis to build the new expression.
1517 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001518 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001519 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001520 Expr *LHS, Expr *RHS) {
1521 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001522 }
1523
1524 /// \brief Build a new conditional operator 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 RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001529 SourceLocation QuestionLoc,
1530 Expr *LHS,
1531 SourceLocation ColonLoc,
1532 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001533 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1534 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001535 }
1536
Douglas Gregorb98b1992009-08-11 05:31:07 +00001537 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001538 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001539 /// By default, performs semantic analysis to build the new expression.
1540 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001541 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001542 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001543 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001544 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001545 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001546 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001547 }
Mike Stump1eb44332009-09-09 15:08:12 +00001548
Douglas Gregorb98b1992009-08-11 05:31:07 +00001549 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001550 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 /// By default, performs semantic analysis to build the new expression.
1552 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001553 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001554 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001556 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001557 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001558 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 }
Mike Stump1eb44332009-09-09 15:08:12 +00001560
Douglas Gregorb98b1992009-08-11 05:31:07 +00001561 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001562 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001565 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001566 SourceLocation OpLoc,
1567 SourceLocation AccessorLoc,
1568 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001569
John McCall129e2df2009-11-30 22:42:35 +00001570 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001571 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001572 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001573 OpLoc, /*IsArrow*/ false,
1574 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001575 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001576 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 }
Mike Stump1eb44332009-09-09 15:08:12 +00001578
Douglas Gregorb98b1992009-08-11 05:31:07 +00001579 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001580 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001581 /// By default, performs semantic analysis to build the new expression.
1582 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001583 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001584 MultiExprArg Inits,
1585 SourceLocation RBraceLoc,
1586 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001587 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001588 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1589 if (Result.isInvalid() || ResultTy->isDependentType())
1590 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001591
Douglas Gregore48319a2009-11-09 17:16:50 +00001592 // Patch in the result type we were given, which may have been computed
1593 // when the initial InitListExpr was built.
1594 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1595 ILE->setType(ResultTy);
1596 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 }
Mike Stump1eb44332009-09-09 15:08:12 +00001598
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001600 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001601 /// By default, performs semantic analysis to build the new expression.
1602 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001603 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 MultiExprArg ArrayExprs,
1605 SourceLocation EqualOrColonLoc,
1606 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001607 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001608 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001610 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001611 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001612 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001613
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 ArrayExprs.release();
1615 return move(Result);
1616 }
Mike Stump1eb44332009-09-09 15:08:12 +00001617
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001619 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 /// By default, builds the implicit value initialization without performing
1621 /// any semantic analysis. Subclasses may override this routine to provide
1622 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001623 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1625 }
Mike Stump1eb44332009-09-09 15:08:12 +00001626
Douglas Gregorb98b1992009-08-11 05:31:07 +00001627 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001628 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 /// By default, performs semantic analysis to build the new expression.
1630 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001631 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001632 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001633 SourceLocation RParenLoc) {
1634 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001635 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001636 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 }
1638
1639 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001640 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 /// By default, performs semantic analysis to build the new expression.
1642 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001643 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 MultiExprArg SubExprs,
1645 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001646 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001647 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 }
Mike Stump1eb44332009-09-09 15:08:12 +00001649
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001651 ///
1652 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 /// rather than attempting to map the label statement itself.
1654 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001655 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001656 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001657 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 }
Mike Stump1eb44332009-09-09 15:08:12 +00001659
Douglas Gregorb98b1992009-08-11 05:31:07 +00001660 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001661 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 /// By default, performs semantic analysis to build the new expression.
1663 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001664 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001665 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001667 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001668 }
Mike Stump1eb44332009-09-09 15:08:12 +00001669
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 /// \brief Build a new __builtin_choose_expr expression.
1671 ///
1672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001674 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001675 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001676 SourceLocation RParenLoc) {
1677 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001678 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 RParenLoc);
1680 }
Mike Stump1eb44332009-09-09 15:08:12 +00001681
Peter Collingbournef111d932011-04-15 00:35:48 +00001682 /// \brief Build a new generic selection expression.
1683 ///
1684 /// By default, performs semantic analysis to build the new expression.
1685 /// Subclasses may override this routine to provide different behavior.
1686 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1687 SourceLocation DefaultLoc,
1688 SourceLocation RParenLoc,
1689 Expr *ControllingExpr,
1690 TypeSourceInfo **Types,
1691 Expr **Exprs,
1692 unsigned NumAssocs) {
1693 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1694 ControllingExpr, Types, Exprs,
1695 NumAssocs);
1696 }
1697
Douglas Gregorb98b1992009-08-11 05:31:07 +00001698 /// \brief Build a new overloaded operator call expression.
1699 ///
1700 /// By default, performs semantic analysis to build the new expression.
1701 /// The semantic analysis provides the behavior of template instantiation,
1702 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001703 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001704 /// argument-dependent lookup, etc. Subclasses may override this routine to
1705 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001706 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001708 Expr *Callee,
1709 Expr *First,
1710 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001711
1712 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 /// reinterpret_cast.
1714 ///
1715 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001716 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001718 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719 Stmt::StmtClass Class,
1720 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001721 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 SourceLocation RAngleLoc,
1723 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001724 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 SourceLocation RParenLoc) {
1726 switch (Class) {
1727 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001728 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001729 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001730 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001731
1732 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001733 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001734 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001735 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001736
Douglas Gregorb98b1992009-08-11 05:31:07 +00001737 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001738 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001739 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001740 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001742
Douglas Gregorb98b1992009-08-11 05:31:07 +00001743 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001744 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001745 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001746 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001747
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001749 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 }
Mike Stump1eb44332009-09-09 15:08:12 +00001751
John McCallf312b1e2010-08-26 23:41:50 +00001752 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 }
Mike Stump1eb44332009-09-09 15:08:12 +00001754
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 /// \brief Build a new C++ static_cast expression.
1756 ///
1757 /// By default, performs semantic analysis to build the new expression.
1758 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001759 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001761 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001762 SourceLocation RAngleLoc,
1763 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001764 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001766 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001767 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001768 SourceRange(LAngleLoc, RAngleLoc),
1769 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 }
1771
1772 /// \brief Build a new C++ dynamic_cast expression.
1773 ///
1774 /// By default, performs semantic analysis to build the new expression.
1775 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001776 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001778 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001779 SourceLocation RAngleLoc,
1780 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001781 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001783 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001784 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001785 SourceRange(LAngleLoc, RAngleLoc),
1786 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 }
1788
1789 /// \brief Build a new C++ reinterpret_cast expression.
1790 ///
1791 /// By default, performs semantic analysis to build the new expression.
1792 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001793 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001795 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001796 SourceLocation RAngleLoc,
1797 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001798 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001800 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001801 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001802 SourceRange(LAngleLoc, RAngleLoc),
1803 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 }
1805
1806 /// \brief Build a new C++ const_cast expression.
1807 ///
1808 /// By default, performs semantic analysis to build the new expression.
1809 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001810 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001812 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 SourceLocation RAngleLoc,
1814 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001815 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001817 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001818 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001819 SourceRange(LAngleLoc, RAngleLoc),
1820 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001821 }
Mike Stump1eb44332009-09-09 15:08:12 +00001822
Douglas Gregorb98b1992009-08-11 05:31:07 +00001823 /// \brief Build a new C++ functional-style cast expression.
1824 ///
1825 /// By default, performs semantic analysis to build the new expression.
1826 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001827 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1828 SourceLocation LParenLoc,
1829 Expr *Sub,
1830 SourceLocation RParenLoc) {
1831 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001832 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001833 RParenLoc);
1834 }
Mike Stump1eb44332009-09-09 15:08:12 +00001835
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 /// \brief Build a new C++ typeid(type) expression.
1837 ///
1838 /// By default, performs semantic analysis to build the new expression.
1839 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001840 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001841 SourceLocation TypeidLoc,
1842 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001843 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001844 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001845 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001846 }
Mike Stump1eb44332009-09-09 15:08:12 +00001847
Francois Pichet01b7c302010-09-08 12:20:18 +00001848
Douglas Gregorb98b1992009-08-11 05:31:07 +00001849 /// \brief Build a new C++ typeid(expr) expression.
1850 ///
1851 /// By default, performs semantic analysis to build the new expression.
1852 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001853 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001854 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001855 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001856 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001857 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001858 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001859 }
1860
Francois Pichet01b7c302010-09-08 12:20:18 +00001861 /// \brief Build a new C++ __uuidof(type) expression.
1862 ///
1863 /// By default, performs semantic analysis to build the new expression.
1864 /// Subclasses may override this routine to provide different behavior.
1865 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1866 SourceLocation TypeidLoc,
1867 TypeSourceInfo *Operand,
1868 SourceLocation RParenLoc) {
1869 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1870 RParenLoc);
1871 }
1872
1873 /// \brief Build a new C++ __uuidof(expr) expression.
1874 ///
1875 /// By default, performs semantic analysis to build the new expression.
1876 /// Subclasses may override this routine to provide different behavior.
1877 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1878 SourceLocation TypeidLoc,
1879 Expr *Operand,
1880 SourceLocation RParenLoc) {
1881 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1882 RParenLoc);
1883 }
1884
Douglas Gregorb98b1992009-08-11 05:31:07 +00001885 /// \brief Build a new C++ "this" expression.
1886 ///
1887 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001888 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001890 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001891 QualType ThisType,
1892 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001893 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001894 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1895 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001896 }
1897
1898 /// \brief Build a new C++ throw expression.
1899 ///
1900 /// By default, performs semantic analysis to build the new expression.
1901 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001902 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1903 bool IsThrownVariableInScope) {
1904 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001905 }
1906
1907 /// \brief Build a new C++ default-argument expression.
1908 ///
1909 /// By default, builds a new default-argument expression, which does not
1910 /// require any semantic analysis. Subclasses may override this routine to
1911 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001912 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001913 ParmVarDecl *Param) {
1914 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1915 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001916 }
1917
1918 /// \brief Build a new C++ zero-initialization expression.
1919 ///
1920 /// By default, performs semantic analysis to build the new expression.
1921 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001922 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1923 SourceLocation LParenLoc,
1924 SourceLocation RParenLoc) {
1925 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001926 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001927 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001928 }
Mike Stump1eb44332009-09-09 15:08:12 +00001929
Douglas Gregorb98b1992009-08-11 05:31:07 +00001930 /// \brief Build a new C++ "new" expression.
1931 ///
1932 /// By default, performs semantic analysis to build the new expression.
1933 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001934 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001935 bool UseGlobal,
1936 SourceLocation PlacementLParen,
1937 MultiExprArg PlacementArgs,
1938 SourceLocation PlacementRParen,
1939 SourceRange TypeIdParens,
1940 QualType AllocatedType,
1941 TypeSourceInfo *AllocatedTypeInfo,
1942 Expr *ArraySize,
1943 SourceLocation ConstructorLParen,
1944 MultiExprArg ConstructorArgs,
1945 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001946 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 PlacementLParen,
1948 move(PlacementArgs),
1949 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001950 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001951 AllocatedType,
1952 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001953 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001954 ConstructorLParen,
1955 move(ConstructorArgs),
1956 ConstructorRParen);
1957 }
Mike Stump1eb44332009-09-09 15:08:12 +00001958
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 /// \brief Build a new C++ "delete" expression.
1960 ///
1961 /// By default, performs semantic analysis to build the new expression.
1962 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001963 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001964 bool IsGlobalDelete,
1965 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001966 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001967 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001968 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001969 }
Mike Stump1eb44332009-09-09 15:08:12 +00001970
Douglas Gregorb98b1992009-08-11 05:31:07 +00001971 /// \brief Build a new unary type trait expression.
1972 ///
1973 /// By default, performs semantic analysis to build the new expression.
1974 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001975 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001976 SourceLocation StartLoc,
1977 TypeSourceInfo *T,
1978 SourceLocation RParenLoc) {
1979 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001980 }
1981
Francois Pichet6ad6f282010-12-07 00:08:36 +00001982 /// \brief Build a new binary type trait expression.
1983 ///
1984 /// By default, performs semantic analysis to build the new expression.
1985 /// Subclasses may override this routine to provide different behavior.
1986 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1987 SourceLocation StartLoc,
1988 TypeSourceInfo *LhsT,
1989 TypeSourceInfo *RhsT,
1990 SourceLocation RParenLoc) {
1991 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1992 }
1993
John Wiegley21ff2e52011-04-28 00:16:57 +00001994 /// \brief Build a new array type trait expression.
1995 ///
1996 /// By default, performs semantic analysis to build the new expression.
1997 /// Subclasses may override this routine to provide different behavior.
1998 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1999 SourceLocation StartLoc,
2000 TypeSourceInfo *TSInfo,
2001 Expr *DimExpr,
2002 SourceLocation RParenLoc) {
2003 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2004 }
2005
John Wiegley55262202011-04-25 06:54:41 +00002006 /// \brief Build a new expression trait expression.
2007 ///
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
2010 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2011 SourceLocation StartLoc,
2012 Expr *Queried,
2013 SourceLocation RParenLoc) {
2014 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2015 }
2016
Mike Stump1eb44332009-09-09 15:08:12 +00002017 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002018 /// expression.
2019 ///
2020 /// By default, performs semantic analysis to build the new expression.
2021 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002022 ExprResult RebuildDependentScopeDeclRefExpr(
2023 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002024 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002025 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002026 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002027 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002028
2029 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00002030 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002031 *TemplateArgs);
2032
Abramo Bagnara25777432010-08-11 22:01:17 +00002033 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002034 }
2035
2036 /// \brief Build a new template-id expression.
2037 ///
2038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002040 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00002041 LookupResult &R,
2042 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00002043 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00002044 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002045 }
2046
2047 /// \brief Build a new object-construction expression.
2048 ///
2049 /// By default, performs semantic analysis to build the new expression.
2050 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002051 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002052 SourceLocation Loc,
2053 CXXConstructorDecl *Constructor,
2054 bool IsElidable,
2055 MultiExprArg Args,
2056 bool HadMultipleCandidates,
2057 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002058 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002059 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002060 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002061 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002062 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002063 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002064
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002065 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002066 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002067 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002068 RequiresZeroInit, ConstructKind,
2069 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002070 }
2071
2072 /// \brief Build a new object-construction expression.
2073 ///
2074 /// By default, performs semantic analysis to build the new expression.
2075 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002076 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2077 SourceLocation LParenLoc,
2078 MultiExprArg Args,
2079 SourceLocation RParenLoc) {
2080 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002081 LParenLoc,
2082 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002083 RParenLoc);
2084 }
2085
2086 /// \brief Build a new object-construction expression.
2087 ///
2088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002090 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2091 SourceLocation LParenLoc,
2092 MultiExprArg Args,
2093 SourceLocation RParenLoc) {
2094 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002095 LParenLoc,
2096 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002097 RParenLoc);
2098 }
Mike Stump1eb44332009-09-09 15:08:12 +00002099
Douglas Gregorb98b1992009-08-11 05:31:07 +00002100 /// \brief Build a new member reference expression.
2101 ///
2102 /// By default, performs semantic analysis to build the new expression.
2103 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002104 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002105 QualType BaseType,
2106 bool IsArrow,
2107 SourceLocation OperatorLoc,
2108 NestedNameSpecifierLoc QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00002109 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002110 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002111 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002112 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002113 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002114
John McCall9ae2f072010-08-23 23:25:46 +00002115 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002116 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00002117 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002118 MemberNameInfo,
2119 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002120 }
2121
John McCall129e2df2009-11-30 22:42:35 +00002122 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002123 ///
2124 /// By default, performs semantic analysis to build the new expression.
2125 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002126 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2127 SourceLocation OperatorLoc,
2128 bool IsArrow,
2129 NestedNameSpecifierLoc QualifierLoc,
2130 NamedDecl *FirstQualifierInScope,
2131 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002132 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002133 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002134 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002135
John McCall9ae2f072010-08-23 23:25:46 +00002136 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002137 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00002138 SS, FirstQualifierInScope,
2139 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002140 }
Mike Stump1eb44332009-09-09 15:08:12 +00002141
Sebastian Redl2e156222010-09-10 20:55:43 +00002142 /// \brief Build a new noexcept expression.
2143 ///
2144 /// By default, performs semantic analysis to build the new expression.
2145 /// Subclasses may override this routine to provide different behavior.
2146 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2147 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2148 }
2149
Douglas Gregoree8aff02011-01-04 17:33:58 +00002150 /// \brief Build a new expression to compute the length of a parameter pack.
2151 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2152 SourceLocation PackLoc,
2153 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002154 llvm::Optional<unsigned> Length) {
2155 if (Length)
2156 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2157 OperatorLoc, Pack, PackLoc,
2158 RParenLoc, *Length);
2159
Douglas Gregoree8aff02011-01-04 17:33:58 +00002160 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2161 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002162 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002163 }
2164
Douglas Gregorb98b1992009-08-11 05:31:07 +00002165 /// \brief Build a new Objective-C @encode expression.
2166 ///
2167 /// By default, performs semantic analysis to build the new expression.
2168 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002169 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002170 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002171 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002172 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002173 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002174 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002175
Douglas Gregor92e986e2010-04-22 16:44:27 +00002176 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002177 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002178 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002179 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002180 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002181 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002182 MultiExprArg Args,
2183 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002184 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2185 ReceiverTypeInfo->getType(),
2186 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002187 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002188 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002189 }
2190
2191 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002192 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002193 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002194 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002195 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002196 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002197 MultiExprArg Args,
2198 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002199 return SemaRef.BuildInstanceMessage(Receiver,
2200 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002201 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002202 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002203 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002204 }
2205
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002206 /// \brief Build a new Objective-C ivar reference expression.
2207 ///
2208 /// By default, performs semantic analysis to build the new expression.
2209 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002210 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002211 SourceLocation IvarLoc,
2212 bool IsArrow, bool IsFreeIvar) {
2213 // FIXME: We lose track of the IsFreeIvar bit.
2214 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002215 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002216 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2217 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002218 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002219 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002220 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002221 false);
John Wiegley429bb272011-04-08 18:41:53 +00002222 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002223 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002224
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002225 if (Result.get())
2226 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002227
John Wiegley429bb272011-04-08 18:41:53 +00002228 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002229 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002230 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002231 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002232 /*TemplateArgs=*/0);
2233 }
Douglas Gregore3303542010-04-26 20:47:02 +00002234
2235 /// \brief Build a new Objective-C property reference expression.
2236 ///
2237 /// By default, performs semantic analysis to build the new expression.
2238 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002239 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002240 ObjCPropertyDecl *Property,
2241 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002242 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002243 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002244 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2245 Sema::LookupMemberName);
2246 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002247 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002248 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002249 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002250 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002251 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002252
Douglas Gregore3303542010-04-26 20:47:02 +00002253 if (Result.get())
2254 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002255
John Wiegley429bb272011-04-08 18:41:53 +00002256 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002257 /*FIXME:*/PropertyLoc, IsArrow,
2258 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002259 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002260 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002261 /*TemplateArgs=*/0);
2262 }
Sean Huntc3021132010-05-05 15:23:54 +00002263
John McCall12f78a62010-12-02 01:19:52 +00002264 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002265 ///
2266 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002267 /// Subclasses may override this routine to provide different behavior.
2268 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2269 ObjCMethodDecl *Getter,
2270 ObjCMethodDecl *Setter,
2271 SourceLocation PropertyLoc) {
2272 // Since these expressions can only be value-dependent, we do not
2273 // need to perform semantic analysis again.
2274 return Owned(
2275 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2276 VK_LValue, OK_ObjCProperty,
2277 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002278 }
2279
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002280 /// \brief Build a new Objective-C "isa" expression.
2281 ///
2282 /// By default, performs semantic analysis to build the new expression.
2283 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002284 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002285 bool IsArrow) {
2286 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002287 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002288 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2289 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002290 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002291 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002292 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002293 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002294 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002295
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002296 if (Result.get())
2297 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002298
John Wiegley429bb272011-04-08 18:41:53 +00002299 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002300 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002301 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002302 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002303 /*TemplateArgs=*/0);
2304 }
Sean Huntc3021132010-05-05 15:23:54 +00002305
Douglas Gregorb98b1992009-08-11 05:31:07 +00002306 /// \brief Build a new shuffle vector expression.
2307 ///
2308 /// By default, performs semantic analysis to build the new expression.
2309 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002310 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002311 MultiExprArg SubExprs,
2312 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002313 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002314 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002315 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2316 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2317 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2318 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002319
Douglas Gregorb98b1992009-08-11 05:31:07 +00002320 // Build a reference to the __builtin_shufflevector builtin
2321 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002322 ExprResult Callee
2323 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2324 VK_LValue, BuiltinLoc));
2325 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2326 if (Callee.isInvalid())
2327 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002328
2329 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002330 unsigned NumSubExprs = SubExprs.size();
2331 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002332 ExprResult TheCall = SemaRef.Owned(
2333 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002334 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002335 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002336 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002337 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002338
Douglas Gregorb98b1992009-08-11 05:31:07 +00002339 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002340 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002341 }
John McCall43fed0d2010-11-12 08:19:04 +00002342
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002343 /// \brief Build a new template argument pack expansion.
2344 ///
2345 /// By default, performs semantic analysis to build a new pack expansion
2346 /// for a template argument. Subclasses may override this routine to provide
2347 /// different behavior.
2348 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002349 SourceLocation EllipsisLoc,
2350 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002351 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002352 case TemplateArgument::Expression: {
2353 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002354 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2355 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002356 if (Result.isInvalid())
2357 return TemplateArgumentLoc();
2358
2359 return TemplateArgumentLoc(Result.get(), Result.get());
2360 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002361
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002362 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002363 return TemplateArgumentLoc(TemplateArgument(
2364 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002365 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002366 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002367 Pattern.getTemplateNameLoc(),
2368 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002369
2370 case TemplateArgument::Null:
2371 case TemplateArgument::Integral:
2372 case TemplateArgument::Declaration:
2373 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002374 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002375 llvm_unreachable("Pack expansion pattern has no parameter packs");
2376
2377 case TemplateArgument::Type:
2378 if (TypeSourceInfo *Expansion
2379 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002380 EllipsisLoc,
2381 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002382 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2383 Expansion);
2384 break;
2385 }
2386
2387 return TemplateArgumentLoc();
2388 }
2389
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002390 /// \brief Build a new expression pack expansion.
2391 ///
2392 /// By default, performs semantic analysis to build a new pack expansion
2393 /// for an expression. Subclasses may override this routine to provide
2394 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002395 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2396 llvm::Optional<unsigned> NumExpansions) {
2397 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002398 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002399
2400 /// \brief Build a new atomic operation expression.
2401 ///
2402 /// By default, performs semantic analysis to build the new expression.
2403 /// Subclasses may override this routine to provide different behavior.
2404 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2405 MultiExprArg SubExprs,
2406 QualType RetTy,
2407 AtomicExpr::AtomicOp Op,
2408 SourceLocation RParenLoc) {
2409 // Just create the expression; there is not any interesting semantic
2410 // analysis here because we can't actually build an AtomicExpr until
2411 // we are sure it is semantically sound.
2412 unsigned NumSubExprs = SubExprs.size();
2413 Expr **Subs = (Expr **)SubExprs.release();
2414 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2415 NumSubExprs, RetTy, Op,
2416 RParenLoc);
2417 }
2418
John McCall43fed0d2010-11-12 08:19:04 +00002419private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002420 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2421 QualType ObjectType,
2422 NamedDecl *FirstQualifierInScope,
2423 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002424
2425 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2426 QualType ObjectType,
2427 NamedDecl *FirstQualifierInScope,
2428 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002429};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002430
Douglas Gregor43959a92009-08-20 07:17:43 +00002431template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002432StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002433 if (!S)
2434 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002435
Douglas Gregor43959a92009-08-20 07:17:43 +00002436 switch (S->getStmtClass()) {
2437 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002438
Douglas Gregor43959a92009-08-20 07:17:43 +00002439 // Transform individual statement nodes
2440#define STMT(Node, Parent) \
2441 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002442#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002443#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002444#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002445
Douglas Gregor43959a92009-08-20 07:17:43 +00002446 // Transform expressions by calling TransformExpr.
2447#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002448#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002449#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002450#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002451 {
John McCall60d7b3a2010-08-24 06:29:42 +00002452 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002453 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002454 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002455
John McCall9ae2f072010-08-23 23:25:46 +00002456 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002457 }
Mike Stump1eb44332009-09-09 15:08:12 +00002458 }
2459
John McCall3fa5cae2010-10-26 07:05:15 +00002460 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002461}
Mike Stump1eb44332009-09-09 15:08:12 +00002462
2463
Douglas Gregor670444e2009-08-04 22:27:00 +00002464template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002465ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002466 if (!E)
2467 return SemaRef.Owned(E);
2468
2469 switch (E->getStmtClass()) {
2470 case Stmt::NoStmtClass: break;
2471#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002472#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002473#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002474 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002475#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002476 }
2477
John McCall3fa5cae2010-10-26 07:05:15 +00002478 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002479}
2480
2481template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002482bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2483 unsigned NumInputs,
2484 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002485 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002486 bool *ArgChanged) {
2487 for (unsigned I = 0; I != NumInputs; ++I) {
2488 // If requested, drop call arguments that need to be dropped.
2489 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2490 if (ArgChanged)
2491 *ArgChanged = true;
2492
2493 break;
2494 }
2495
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002496 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2497 Expr *Pattern = Expansion->getPattern();
2498
Chris Lattner686775d2011-07-20 06:58:45 +00002499 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002500 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2501 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2502
2503 // Determine whether the set of unexpanded parameter packs can and should
2504 // be expanded.
2505 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002506 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002507 llvm::Optional<unsigned> OrigNumExpansions
2508 = Expansion->getNumExpansions();
2509 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002510 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2511 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002512 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002513 Expand, RetainExpansion,
2514 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002515 return true;
2516
2517 if (!Expand) {
2518 // The transform has determined that we should perform a simple
2519 // transformation on the pack expansion, producing another pack
2520 // expansion.
2521 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2522 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2523 if (OutPattern.isInvalid())
2524 return true;
2525
2526 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002527 Expansion->getEllipsisLoc(),
2528 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002529 if (Out.isInvalid())
2530 return true;
2531
2532 if (ArgChanged)
2533 *ArgChanged = true;
2534 Outputs.push_back(Out.get());
2535 continue;
2536 }
John McCallc8fc90a2011-07-06 07:30:07 +00002537
2538 // Record right away that the argument was changed. This needs
2539 // to happen even if the array expands to nothing.
2540 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002541
2542 // The transform has determined that we should perform an elementwise
2543 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002544 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002545 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2546 ExprResult Out = getDerived().TransformExpr(Pattern);
2547 if (Out.isInvalid())
2548 return true;
2549
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002550 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002551 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2552 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002553 if (Out.isInvalid())
2554 return true;
2555 }
2556
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002557 Outputs.push_back(Out.get());
2558 }
2559
2560 continue;
2561 }
2562
Douglas Gregoraa165f82011-01-03 19:04:46 +00002563 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2564 if (Result.isInvalid())
2565 return true;
2566
2567 if (Result.get() != Inputs[I] && ArgChanged)
2568 *ArgChanged = true;
2569
2570 Outputs.push_back(Result.get());
2571 }
2572
2573 return false;
2574}
2575
2576template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002577NestedNameSpecifierLoc
2578TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2579 NestedNameSpecifierLoc NNS,
2580 QualType ObjectType,
2581 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002582 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002583 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2584 Qualifier = Qualifier.getPrefix())
2585 Qualifiers.push_back(Qualifier);
2586
2587 CXXScopeSpec SS;
2588 while (!Qualifiers.empty()) {
2589 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2590 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2591
2592 switch (QNNS->getKind()) {
2593 case NestedNameSpecifier::Identifier:
2594 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2595 *QNNS->getAsIdentifier(),
2596 Q.getLocalBeginLoc(),
2597 Q.getLocalEndLoc(),
2598 ObjectType, false, SS,
2599 FirstQualifierInScope, false))
2600 return NestedNameSpecifierLoc();
2601
2602 break;
2603
2604 case NestedNameSpecifier::Namespace: {
2605 NamespaceDecl *NS
2606 = cast_or_null<NamespaceDecl>(
2607 getDerived().TransformDecl(
2608 Q.getLocalBeginLoc(),
2609 QNNS->getAsNamespace()));
2610 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2611 break;
2612 }
2613
2614 case NestedNameSpecifier::NamespaceAlias: {
2615 NamespaceAliasDecl *Alias
2616 = cast_or_null<NamespaceAliasDecl>(
2617 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2618 QNNS->getAsNamespaceAlias()));
2619 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2620 Q.getLocalEndLoc());
2621 break;
2622 }
2623
2624 case NestedNameSpecifier::Global:
2625 // There is no meaningful transformation that one could perform on the
2626 // global scope.
2627 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2628 break;
2629
2630 case NestedNameSpecifier::TypeSpecWithTemplate:
2631 case NestedNameSpecifier::TypeSpec: {
2632 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2633 FirstQualifierInScope, SS);
2634
2635 if (!TL)
2636 return NestedNameSpecifierLoc();
2637
2638 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2639 (SemaRef.getLangOptions().CPlusPlus0x &&
2640 TL.getType()->isEnumeralType())) {
2641 assert(!TL.getType().hasLocalQualifiers() &&
2642 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002643 if (TL.getType()->isEnumeralType())
2644 SemaRef.Diag(TL.getBeginLoc(),
2645 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002646 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2647 Q.getLocalEndLoc());
2648 break;
2649 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002650 // If the nested-name-specifier is an invalid type def, don't emit an
2651 // error because a previous error should have already been emitted.
2652 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2653 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2654 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2655 << TL.getType() << SS.getRange();
2656 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002657 return NestedNameSpecifierLoc();
2658 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002659 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002660
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002661 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002662 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002663 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002664 }
2665
2666 // Don't rebuild the nested-name-specifier if we don't have to.
2667 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2668 !getDerived().AlwaysRebuild())
2669 return NNS;
2670
2671 // If we can re-use the source-location data from the original
2672 // nested-name-specifier, do so.
2673 if (SS.location_size() == NNS.getDataLength() &&
2674 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2675 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2676
2677 // Allocate new nested-name-specifier location information.
2678 return SS.getWithLocInContext(SemaRef.Context);
2679}
2680
2681template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002682DeclarationNameInfo
2683TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002684::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002685 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002686 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002687 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002688
2689 switch (Name.getNameKind()) {
2690 case DeclarationName::Identifier:
2691 case DeclarationName::ObjCZeroArgSelector:
2692 case DeclarationName::ObjCOneArgSelector:
2693 case DeclarationName::ObjCMultiArgSelector:
2694 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002695 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002696 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002697 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002698
Douglas Gregor81499bb2009-09-03 22:13:48 +00002699 case DeclarationName::CXXConstructorName:
2700 case DeclarationName::CXXDestructorName:
2701 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002702 TypeSourceInfo *NewTInfo;
2703 CanQualType NewCanTy;
2704 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002705 NewTInfo = getDerived().TransformType(OldTInfo);
2706 if (!NewTInfo)
2707 return DeclarationNameInfo();
2708 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002709 }
2710 else {
2711 NewTInfo = 0;
2712 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002713 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002714 if (NewT.isNull())
2715 return DeclarationNameInfo();
2716 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2717 }
Mike Stump1eb44332009-09-09 15:08:12 +00002718
Abramo Bagnara25777432010-08-11 22:01:17 +00002719 DeclarationName NewName
2720 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2721 NewCanTy);
2722 DeclarationNameInfo NewNameInfo(NameInfo);
2723 NewNameInfo.setName(NewName);
2724 NewNameInfo.setNamedTypeInfo(NewTInfo);
2725 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002726 }
Mike Stump1eb44332009-09-09 15:08:12 +00002727 }
2728
David Blaikieb219cfc2011-09-23 05:06:16 +00002729 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002730}
2731
2732template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002733TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002734TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2735 TemplateName Name,
2736 SourceLocation NameLoc,
2737 QualType ObjectType,
2738 NamedDecl *FirstQualifierInScope) {
2739 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2740 TemplateDecl *Template = QTN->getTemplateDecl();
2741 assert(Template && "qualified template name must refer to a template");
2742
2743 TemplateDecl *TransTemplate
2744 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2745 Template));
2746 if (!TransTemplate)
2747 return TemplateName();
2748
2749 if (!getDerived().AlwaysRebuild() &&
2750 SS.getScopeRep() == QTN->getQualifier() &&
2751 TransTemplate == Template)
2752 return Name;
2753
2754 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2755 TransTemplate);
2756 }
2757
2758 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2759 if (SS.getScopeRep()) {
2760 // These apply to the scope specifier, not the template.
2761 ObjectType = QualType();
2762 FirstQualifierInScope = 0;
2763 }
2764
2765 if (!getDerived().AlwaysRebuild() &&
2766 SS.getScopeRep() == DTN->getQualifier() &&
2767 ObjectType.isNull())
2768 return Name;
2769
2770 if (DTN->isIdentifier()) {
2771 return getDerived().RebuildTemplateName(SS,
2772 *DTN->getIdentifier(),
2773 NameLoc,
2774 ObjectType,
2775 FirstQualifierInScope);
2776 }
2777
2778 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2779 ObjectType);
2780 }
2781
2782 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2783 TemplateDecl *TransTemplate
2784 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2785 Template));
2786 if (!TransTemplate)
2787 return TemplateName();
2788
2789 if (!getDerived().AlwaysRebuild() &&
2790 TransTemplate == Template)
2791 return Name;
2792
2793 return TemplateName(TransTemplate);
2794 }
2795
2796 if (SubstTemplateTemplateParmPackStorage *SubstPack
2797 = Name.getAsSubstTemplateTemplateParmPack()) {
2798 TemplateTemplateParmDecl *TransParam
2799 = cast_or_null<TemplateTemplateParmDecl>(
2800 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2801 if (!TransParam)
2802 return TemplateName();
2803
2804 if (!getDerived().AlwaysRebuild() &&
2805 TransParam == SubstPack->getParameterPack())
2806 return Name;
2807
2808 return getDerived().RebuildTemplateName(TransParam,
2809 SubstPack->getArgumentPack());
2810 }
2811
2812 // These should be getting filtered out before they reach the AST.
2813 llvm_unreachable("overloaded function decl survived to here");
2814 return TemplateName();
2815}
2816
2817template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002818void TreeTransform<Derived>::InventTemplateArgumentLoc(
2819 const TemplateArgument &Arg,
2820 TemplateArgumentLoc &Output) {
2821 SourceLocation Loc = getDerived().getBaseLocation();
2822 switch (Arg.getKind()) {
2823 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002824 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002825 break;
2826
2827 case TemplateArgument::Type:
2828 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002829 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002830
John McCall833ca992009-10-29 08:12:44 +00002831 break;
2832
Douglas Gregor788cd062009-11-11 01:00:40 +00002833 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002834 case TemplateArgument::TemplateExpansion: {
2835 NestedNameSpecifierLocBuilder Builder;
2836 TemplateName Template = Arg.getAsTemplate();
2837 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2838 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2839 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2840 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2841
2842 if (Arg.getKind() == TemplateArgument::Template)
2843 Output = TemplateArgumentLoc(Arg,
2844 Builder.getWithLocInContext(SemaRef.Context),
2845 Loc);
2846 else
2847 Output = TemplateArgumentLoc(Arg,
2848 Builder.getWithLocInContext(SemaRef.Context),
2849 Loc, Loc);
2850
Douglas Gregor788cd062009-11-11 01:00:40 +00002851 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002852 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002853
John McCall833ca992009-10-29 08:12:44 +00002854 case TemplateArgument::Expression:
2855 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2856 break;
2857
2858 case TemplateArgument::Declaration:
2859 case TemplateArgument::Integral:
2860 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002861 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002862 break;
2863 }
2864}
2865
2866template<typename Derived>
2867bool TreeTransform<Derived>::TransformTemplateArgument(
2868 const TemplateArgumentLoc &Input,
2869 TemplateArgumentLoc &Output) {
2870 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002871 switch (Arg.getKind()) {
2872 case TemplateArgument::Null:
2873 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002874 Output = Input;
2875 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002876
Douglas Gregor670444e2009-08-04 22:27:00 +00002877 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002878 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002879 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002880 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002881
2882 DI = getDerived().TransformType(DI);
2883 if (!DI) return true;
2884
2885 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2886 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002887 }
Mike Stump1eb44332009-09-09 15:08:12 +00002888
Douglas Gregor670444e2009-08-04 22:27:00 +00002889 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002890 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002891 DeclarationName Name;
2892 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2893 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002894 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002895 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002896 if (!D) return true;
2897
John McCall828bff22009-10-29 18:45:58 +00002898 Expr *SourceExpr = Input.getSourceDeclExpression();
2899 if (SourceExpr) {
2900 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002901 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002902 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002903 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002904 }
2905
2906 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002907 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002908 }
Mike Stump1eb44332009-09-09 15:08:12 +00002909
Douglas Gregor788cd062009-11-11 01:00:40 +00002910 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002911 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2912 if (QualifierLoc) {
2913 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2914 if (!QualifierLoc)
2915 return true;
2916 }
2917
Douglas Gregor1d752d72011-03-02 18:46:51 +00002918 CXXScopeSpec SS;
2919 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002920 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002921 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2922 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002923 if (Template.isNull())
2924 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002925
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002926 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002927 Input.getTemplateNameLoc());
2928 return false;
2929 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002930
2931 case TemplateArgument::TemplateExpansion:
2932 llvm_unreachable("Caller should expand pack expansions");
2933
Douglas Gregor670444e2009-08-04 22:27:00 +00002934 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00002935 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00002936 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002937 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002938
John McCall833ca992009-10-29 08:12:44 +00002939 Expr *InputExpr = Input.getSourceExpression();
2940 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2941
Chris Lattner223de242011-04-25 20:37:58 +00002942 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall833ca992009-10-29 08:12:44 +00002943 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002944 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002945 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002946 }
Mike Stump1eb44332009-09-09 15:08:12 +00002947
Douglas Gregor670444e2009-08-04 22:27:00 +00002948 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00002949 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00002950 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002951 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002952 AEnd = Arg.pack_end();
2953 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002954
John McCall833ca992009-10-29 08:12:44 +00002955 // FIXME: preserve source information here when we start
2956 // caring about parameter packs.
2957
John McCall828bff22009-10-29 18:45:58 +00002958 TemplateArgumentLoc InputArg;
2959 TemplateArgumentLoc OutputArg;
2960 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2961 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002962 return true;
2963
John McCall828bff22009-10-29 18:45:58 +00002964 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002965 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002966
2967 TemplateArgument *TransformedArgsPtr
2968 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2969 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2970 TransformedArgsPtr);
2971 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2972 TransformedArgs.size()),
2973 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002974 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002975 }
2976 }
Mike Stump1eb44332009-09-09 15:08:12 +00002977
Douglas Gregor670444e2009-08-04 22:27:00 +00002978 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002979 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002980}
2981
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002982/// \brief Iterator adaptor that invents template argument location information
2983/// for each of the template arguments in its underlying iterator.
2984template<typename Derived, typename InputIterator>
2985class TemplateArgumentLocInventIterator {
2986 TreeTransform<Derived> &Self;
2987 InputIterator Iter;
2988
2989public:
2990 typedef TemplateArgumentLoc value_type;
2991 typedef TemplateArgumentLoc reference;
2992 typedef typename std::iterator_traits<InputIterator>::difference_type
2993 difference_type;
2994 typedef std::input_iterator_tag iterator_category;
2995
2996 class pointer {
2997 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002998
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002999 public:
3000 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3001
3002 const TemplateArgumentLoc *operator->() const { return &Arg; }
3003 };
3004
3005 TemplateArgumentLocInventIterator() { }
3006
3007 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3008 InputIterator Iter)
3009 : Self(Self), Iter(Iter) { }
3010
3011 TemplateArgumentLocInventIterator &operator++() {
3012 ++Iter;
3013 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003014 }
3015
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003016 TemplateArgumentLocInventIterator operator++(int) {
3017 TemplateArgumentLocInventIterator Old(*this);
3018 ++(*this);
3019 return Old;
3020 }
3021
3022 reference operator*() const {
3023 TemplateArgumentLoc Result;
3024 Self.InventTemplateArgumentLoc(*Iter, Result);
3025 return Result;
3026 }
3027
3028 pointer operator->() const { return pointer(**this); }
3029
3030 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3031 const TemplateArgumentLocInventIterator &Y) {
3032 return X.Iter == Y.Iter;
3033 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003034
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003035 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3036 const TemplateArgumentLocInventIterator &Y) {
3037 return X.Iter != Y.Iter;
3038 }
3039};
3040
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003041template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003042template<typename InputIterator>
3043bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3044 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003045 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003046 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003047 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003048 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003049
3050 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3051 // Unpack argument packs, which we translate them into separate
3052 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003053 // FIXME: We could do much better if we could guarantee that the
3054 // TemplateArgumentLocInfo for the pack expansion would be usable for
3055 // all of the template arguments in the argument pack.
3056 typedef TemplateArgumentLocInventIterator<Derived,
3057 TemplateArgument::pack_iterator>
3058 PackLocIterator;
3059 if (TransformTemplateArguments(PackLocIterator(*this,
3060 In.getArgument().pack_begin()),
3061 PackLocIterator(*this,
3062 In.getArgument().pack_end()),
3063 Outputs))
3064 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003065
3066 continue;
3067 }
3068
3069 if (In.getArgument().isPackExpansion()) {
3070 // We have a pack expansion, for which we will be substituting into
3071 // the pattern.
3072 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003073 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003074 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003075 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3076 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003077
Chris Lattner686775d2011-07-20 06:58:45 +00003078 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003079 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3080 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3081
3082 // Determine whether the set of unexpanded parameter packs can and should
3083 // be expanded.
3084 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003085 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003086 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003087 if (getDerived().TryExpandParameterPacks(Ellipsis,
3088 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003089 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003090 Expand,
3091 RetainExpansion,
3092 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003093 return true;
3094
3095 if (!Expand) {
3096 // The transform has determined that we should perform a simple
3097 // transformation on the pack expansion, producing another pack
3098 // expansion.
3099 TemplateArgumentLoc OutPattern;
3100 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3101 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3102 return true;
3103
Douglas Gregorcded4f62011-01-14 17:04:44 +00003104 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3105 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003106 if (Out.getArgument().isNull())
3107 return true;
3108
3109 Outputs.addArgument(Out);
3110 continue;
3111 }
3112
3113 // The transform has determined that we should perform an elementwise
3114 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003115 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003116 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3117
3118 if (getDerived().TransformTemplateArgument(Pattern, Out))
3119 return true;
3120
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003121 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003122 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3123 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003124 if (Out.getArgument().isNull())
3125 return true;
3126 }
3127
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003128 Outputs.addArgument(Out);
3129 }
3130
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003131 // If we're supposed to retain a pack expansion, do so by temporarily
3132 // forgetting the partially-substituted parameter pack.
3133 if (RetainExpansion) {
3134 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3135
3136 if (getDerived().TransformTemplateArgument(Pattern, Out))
3137 return true;
3138
Douglas Gregorcded4f62011-01-14 17:04:44 +00003139 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3140 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003141 if (Out.getArgument().isNull())
3142 return true;
3143
3144 Outputs.addArgument(Out);
3145 }
Douglas Gregord3731192011-01-10 07:32:04 +00003146
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003147 continue;
3148 }
3149
3150 // The simple case:
3151 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003152 return true;
3153
3154 Outputs.addArgument(Out);
3155 }
3156
3157 return false;
3158
3159}
3160
Douglas Gregor577f75a2009-08-04 16:50:30 +00003161//===----------------------------------------------------------------------===//
3162// Type transformation
3163//===----------------------------------------------------------------------===//
3164
3165template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003166QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003167 if (getDerived().AlreadyTransformed(T))
3168 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003169
John McCalla2becad2009-10-21 00:40:46 +00003170 // Temporary workaround. All of these transformations should
3171 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003172 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3173 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003174
John McCall43fed0d2010-11-12 08:19:04 +00003175 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003176
John McCalla2becad2009-10-21 00:40:46 +00003177 if (!NewDI)
3178 return QualType();
3179
3180 return NewDI->getType();
3181}
3182
3183template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003184TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003185 // Refine the base location to the type's location.
3186 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3187 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003188 if (getDerived().AlreadyTransformed(DI->getType()))
3189 return DI;
3190
3191 TypeLocBuilder TLB;
3192
3193 TypeLoc TL = DI->getTypeLoc();
3194 TLB.reserve(TL.getFullDataSize());
3195
John McCall43fed0d2010-11-12 08:19:04 +00003196 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003197 if (Result.isNull())
3198 return 0;
3199
John McCalla93c9342009-12-07 02:54:59 +00003200 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003201}
3202
3203template<typename Derived>
3204QualType
John McCall43fed0d2010-11-12 08:19:04 +00003205TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003206 switch (T.getTypeLocClass()) {
3207#define ABSTRACT_TYPELOC(CLASS, PARENT)
3208#define TYPELOC(CLASS, PARENT) \
3209 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003210 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003211#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003212 }
Mike Stump1eb44332009-09-09 15:08:12 +00003213
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003214 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003215 return QualType();
3216}
3217
3218/// FIXME: By default, this routine adds type qualifiers only to types
3219/// that can have qualifiers, and silently suppresses those qualifiers
3220/// that are not permitted (e.g., qualifiers on reference or function
3221/// types). This is the right thing for template instantiation, but
3222/// probably not for other clients.
3223template<typename Derived>
3224QualType
3225TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003226 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003227 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003228
John McCall43fed0d2010-11-12 08:19:04 +00003229 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003230 if (Result.isNull())
3231 return QualType();
3232
3233 // Silently suppress qualifiers if the result type can't be qualified.
3234 // FIXME: this is the right thing for template instantiation, but
3235 // probably not for other clients.
3236 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003237 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003238
John McCallf85e1932011-06-15 23:02:42 +00003239 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003240 // resulting type.
3241 if (Quals.hasObjCLifetime()) {
3242 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3243 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003244 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003245 // Objective-C ARC:
3246 // A lifetime qualifier applied to a substituted template parameter
3247 // overrides the lifetime qualifier from the template argument.
3248 if (const SubstTemplateTypeParmType *SubstTypeParam
3249 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3250 QualType Replacement = SubstTypeParam->getReplacementType();
3251 Qualifiers Qs = Replacement.getQualifiers();
3252 Qs.removeObjCLifetime();
3253 Replacement
3254 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3255 Qs);
3256 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3257 SubstTypeParam->getReplacedParameter(),
3258 Replacement);
3259 TLB.TypeWasModifiedSafely(Result);
3260 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003261 // Otherwise, complain about the addition of a qualifier to an
3262 // already-qualified type.
3263 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003264 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003265 << Result << R;
3266
Douglas Gregore559ca12011-06-17 22:11:49 +00003267 Quals.removeObjCLifetime();
3268 }
3269 }
3270 }
John McCall28654742010-06-05 06:41:15 +00003271 if (!Quals.empty()) {
3272 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3273 TLB.push<QualifiedTypeLoc>(Result);
3274 // No location information to preserve.
3275 }
John McCalla2becad2009-10-21 00:40:46 +00003276
3277 return Result;
3278}
3279
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003280template<typename Derived>
3281TypeLoc
3282TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3283 QualType ObjectType,
3284 NamedDecl *UnqualLookup,
3285 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003286 QualType T = TL.getType();
3287 if (getDerived().AlreadyTransformed(T))
3288 return TL;
3289
3290 TypeLocBuilder TLB;
3291 QualType Result;
3292
3293 if (isa<TemplateSpecializationType>(T)) {
3294 TemplateSpecializationTypeLoc SpecTL
3295 = cast<TemplateSpecializationTypeLoc>(TL);
3296
3297 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003298 getDerived().TransformTemplateName(SS,
3299 SpecTL.getTypePtr()->getTemplateName(),
3300 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003301 ObjectType, UnqualLookup);
3302 if (Template.isNull())
3303 return TypeLoc();
3304
3305 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3306 Template);
3307 } else if (isa<DependentTemplateSpecializationType>(T)) {
3308 DependentTemplateSpecializationTypeLoc SpecTL
3309 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3310
Douglas Gregora88f09f2011-02-28 17:23:35 +00003311 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003312 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003313 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003314 SpecTL.getNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003315 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003316 if (Template.isNull())
3317 return TypeLoc();
3318
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003319 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003320 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003321 Template,
3322 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003323 } else {
3324 // Nothing special needs to be done for these.
3325 Result = getDerived().TransformType(TLB, TL);
3326 }
3327
3328 if (Result.isNull())
3329 return TypeLoc();
3330
3331 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3332}
3333
Douglas Gregorb71d8212011-03-02 18:32:08 +00003334template<typename Derived>
3335TypeSourceInfo *
3336TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3337 QualType ObjectType,
3338 NamedDecl *UnqualLookup,
3339 CXXScopeSpec &SS) {
3340 // FIXME: Painfully copy-paste from the above!
3341
3342 QualType T = TSInfo->getType();
3343 if (getDerived().AlreadyTransformed(T))
3344 return TSInfo;
3345
3346 TypeLocBuilder TLB;
3347 QualType Result;
3348
3349 TypeLoc TL = TSInfo->getTypeLoc();
3350 if (isa<TemplateSpecializationType>(T)) {
3351 TemplateSpecializationTypeLoc SpecTL
3352 = cast<TemplateSpecializationTypeLoc>(TL);
3353
3354 TemplateName Template
3355 = getDerived().TransformTemplateName(SS,
3356 SpecTL.getTypePtr()->getTemplateName(),
3357 SpecTL.getTemplateNameLoc(),
3358 ObjectType, UnqualLookup);
3359 if (Template.isNull())
3360 return 0;
3361
3362 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3363 Template);
3364 } else if (isa<DependentTemplateSpecializationType>(T)) {
3365 DependentTemplateSpecializationTypeLoc SpecTL
3366 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3367
3368 TemplateName Template
3369 = getDerived().RebuildTemplateName(SS,
3370 *SpecTL.getTypePtr()->getIdentifier(),
3371 SpecTL.getNameLoc(),
3372 ObjectType, UnqualLookup);
3373 if (Template.isNull())
3374 return 0;
3375
3376 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3377 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003378 Template,
3379 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003380 } else {
3381 // Nothing special needs to be done for these.
3382 Result = getDerived().TransformType(TLB, TL);
3383 }
3384
3385 if (Result.isNull())
3386 return 0;
3387
3388 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3389}
3390
John McCalla2becad2009-10-21 00:40:46 +00003391template <class TyLoc> static inline
3392QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3393 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3394 NewT.setNameLoc(T.getNameLoc());
3395 return T.getType();
3396}
3397
John McCalla2becad2009-10-21 00:40:46 +00003398template<typename Derived>
3399QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003400 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003401 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3402 NewT.setBuiltinLoc(T.getBuiltinLoc());
3403 if (T.needsExtraLocalData())
3404 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3405 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003406}
Mike Stump1eb44332009-09-09 15:08:12 +00003407
Douglas Gregor577f75a2009-08-04 16:50:30 +00003408template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003409QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003410 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003411 // FIXME: recurse?
3412 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003413}
Mike Stump1eb44332009-09-09 15:08:12 +00003414
Douglas Gregor577f75a2009-08-04 16:50:30 +00003415template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003416QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003417 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003418 QualType PointeeType
3419 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003420 if (PointeeType.isNull())
3421 return QualType();
3422
3423 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003424 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003425 // A dependent pointer type 'T *' has is being transformed such
3426 // that an Objective-C class type is being replaced for 'T'. The
3427 // resulting pointer type is an ObjCObjectPointerType, not a
3428 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003429 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003430
John McCallc12c5bb2010-05-15 11:32:37 +00003431 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3432 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003433 return Result;
3434 }
John McCall43fed0d2010-11-12 08:19:04 +00003435
Douglas Gregor92e986e2010-04-22 16:44:27 +00003436 if (getDerived().AlwaysRebuild() ||
3437 PointeeType != TL.getPointeeLoc().getType()) {
3438 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3439 if (Result.isNull())
3440 return QualType();
3441 }
John McCallf85e1932011-06-15 23:02:42 +00003442
3443 // Objective-C ARC can add lifetime qualifiers to the type that we're
3444 // pointing to.
3445 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3446
Douglas Gregor92e986e2010-04-22 16:44:27 +00003447 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3448 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003449 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003450}
Mike Stump1eb44332009-09-09 15:08:12 +00003451
3452template<typename Derived>
3453QualType
John McCalla2becad2009-10-21 00:40:46 +00003454TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003455 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003456 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003457 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3458 if (PointeeType.isNull())
3459 return QualType();
3460
3461 QualType Result = TL.getType();
3462 if (getDerived().AlwaysRebuild() ||
3463 PointeeType != TL.getPointeeLoc().getType()) {
3464 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003465 TL.getSigilLoc());
3466 if (Result.isNull())
3467 return QualType();
3468 }
3469
Douglas Gregor39968ad2010-04-22 16:50:51 +00003470 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003471 NewT.setSigilLoc(TL.getSigilLoc());
3472 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003473}
3474
John McCall85737a72009-10-30 00:06:24 +00003475/// Transforms a reference type. Note that somewhat paradoxically we
3476/// don't care whether the type itself is an l-value type or an r-value
3477/// type; we only care if the type was *written* as an l-value type
3478/// or an r-value type.
3479template<typename Derived>
3480QualType
3481TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003482 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003483 const ReferenceType *T = TL.getTypePtr();
3484
3485 // Note that this works with the pointee-as-written.
3486 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3487 if (PointeeType.isNull())
3488 return QualType();
3489
3490 QualType Result = TL.getType();
3491 if (getDerived().AlwaysRebuild() ||
3492 PointeeType != T->getPointeeTypeAsWritten()) {
3493 Result = getDerived().RebuildReferenceType(PointeeType,
3494 T->isSpelledAsLValue(),
3495 TL.getSigilLoc());
3496 if (Result.isNull())
3497 return QualType();
3498 }
3499
John McCallf85e1932011-06-15 23:02:42 +00003500 // Objective-C ARC can add lifetime qualifiers to the type that we're
3501 // referring to.
3502 TLB.TypeWasModifiedSafely(
3503 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3504
John McCall85737a72009-10-30 00:06:24 +00003505 // r-value references can be rebuilt as l-value references.
3506 ReferenceTypeLoc NewTL;
3507 if (isa<LValueReferenceType>(Result))
3508 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3509 else
3510 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3511 NewTL.setSigilLoc(TL.getSigilLoc());
3512
3513 return Result;
3514}
3515
Mike Stump1eb44332009-09-09 15:08:12 +00003516template<typename Derived>
3517QualType
John McCalla2becad2009-10-21 00:40:46 +00003518TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003519 LValueReferenceTypeLoc TL) {
3520 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003521}
3522
Mike Stump1eb44332009-09-09 15:08:12 +00003523template<typename Derived>
3524QualType
John McCalla2becad2009-10-21 00:40:46 +00003525TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003526 RValueReferenceTypeLoc TL) {
3527 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003528}
Mike Stump1eb44332009-09-09 15:08:12 +00003529
Douglas Gregor577f75a2009-08-04 16:50:30 +00003530template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003531QualType
John McCalla2becad2009-10-21 00:40:46 +00003532TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003533 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003534 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003535 if (PointeeType.isNull())
3536 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003537
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003538 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3539 TypeSourceInfo* NewClsTInfo = 0;
3540 if (OldClsTInfo) {
3541 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3542 if (!NewClsTInfo)
3543 return QualType();
3544 }
3545
3546 const MemberPointerType *T = TL.getTypePtr();
3547 QualType OldClsType = QualType(T->getClass(), 0);
3548 QualType NewClsType;
3549 if (NewClsTInfo)
3550 NewClsType = NewClsTInfo->getType();
3551 else {
3552 NewClsType = getDerived().TransformType(OldClsType);
3553 if (NewClsType.isNull())
3554 return QualType();
3555 }
Mike Stump1eb44332009-09-09 15:08:12 +00003556
John McCalla2becad2009-10-21 00:40:46 +00003557 QualType Result = TL.getType();
3558 if (getDerived().AlwaysRebuild() ||
3559 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003560 NewClsType != OldClsType) {
3561 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003562 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003563 if (Result.isNull())
3564 return QualType();
3565 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003566
John McCalla2becad2009-10-21 00:40:46 +00003567 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3568 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003569 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003570
3571 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003572}
3573
Mike Stump1eb44332009-09-09 15:08:12 +00003574template<typename Derived>
3575QualType
John McCalla2becad2009-10-21 00:40:46 +00003576TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003577 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003578 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003579 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003580 if (ElementType.isNull())
3581 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003582
John McCalla2becad2009-10-21 00:40:46 +00003583 QualType Result = TL.getType();
3584 if (getDerived().AlwaysRebuild() ||
3585 ElementType != T->getElementType()) {
3586 Result = getDerived().RebuildConstantArrayType(ElementType,
3587 T->getSizeModifier(),
3588 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003589 T->getIndexTypeCVRQualifiers(),
3590 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003591 if (Result.isNull())
3592 return QualType();
3593 }
Sean Huntc3021132010-05-05 15:23:54 +00003594
John McCalla2becad2009-10-21 00:40:46 +00003595 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3596 NewTL.setLBracketLoc(TL.getLBracketLoc());
3597 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003598
John McCalla2becad2009-10-21 00:40:46 +00003599 Expr *Size = TL.getSizeExpr();
3600 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003601 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3602 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003603 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3604 }
3605 NewTL.setSizeExpr(Size);
3606
3607 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003608}
Mike Stump1eb44332009-09-09 15:08:12 +00003609
Douglas Gregor577f75a2009-08-04 16:50:30 +00003610template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003611QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003612 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003613 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003614 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003615 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003616 if (ElementType.isNull())
3617 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003618
John McCalla2becad2009-10-21 00:40:46 +00003619 QualType Result = TL.getType();
3620 if (getDerived().AlwaysRebuild() ||
3621 ElementType != T->getElementType()) {
3622 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003623 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003624 T->getIndexTypeCVRQualifiers(),
3625 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003626 if (Result.isNull())
3627 return QualType();
3628 }
Sean Huntc3021132010-05-05 15:23:54 +00003629
John McCalla2becad2009-10-21 00:40:46 +00003630 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3631 NewTL.setLBracketLoc(TL.getLBracketLoc());
3632 NewTL.setRBracketLoc(TL.getRBracketLoc());
3633 NewTL.setSizeExpr(0);
3634
3635 return Result;
3636}
3637
3638template<typename Derived>
3639QualType
3640TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003641 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003642 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003643 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3644 if (ElementType.isNull())
3645 return QualType();
3646
John McCall60d7b3a2010-08-24 06:29:42 +00003647 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003648 = getDerived().TransformExpr(T->getSizeExpr());
3649 if (SizeResult.isInvalid())
3650 return QualType();
3651
John McCall9ae2f072010-08-23 23:25:46 +00003652 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003653
3654 QualType Result = TL.getType();
3655 if (getDerived().AlwaysRebuild() ||
3656 ElementType != T->getElementType() ||
3657 Size != T->getSizeExpr()) {
3658 Result = getDerived().RebuildVariableArrayType(ElementType,
3659 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003660 Size,
John McCalla2becad2009-10-21 00:40:46 +00003661 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003662 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003663 if (Result.isNull())
3664 return QualType();
3665 }
Sean Huntc3021132010-05-05 15:23:54 +00003666
John McCalla2becad2009-10-21 00:40:46 +00003667 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3668 NewTL.setLBracketLoc(TL.getLBracketLoc());
3669 NewTL.setRBracketLoc(TL.getRBracketLoc());
3670 NewTL.setSizeExpr(Size);
3671
3672 return Result;
3673}
3674
3675template<typename Derived>
3676QualType
3677TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003678 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003679 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003680 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3681 if (ElementType.isNull())
3682 return QualType();
3683
Richard Smithf6702a32011-12-20 02:08:33 +00003684 // Array bounds are constant expressions.
3685 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3686 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003687
John McCall3b657512011-01-19 10:06:00 +00003688 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3689 Expr *origSize = TL.getSizeExpr();
3690 if (!origSize) origSize = T->getSizeExpr();
3691
3692 ExprResult sizeResult
3693 = getDerived().TransformExpr(origSize);
3694 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003695 return QualType();
3696
John McCall3b657512011-01-19 10:06:00 +00003697 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003698
3699 QualType Result = TL.getType();
3700 if (getDerived().AlwaysRebuild() ||
3701 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003702 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003703 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3704 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003705 size,
John McCalla2becad2009-10-21 00:40:46 +00003706 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003707 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003708 if (Result.isNull())
3709 return QualType();
3710 }
John McCalla2becad2009-10-21 00:40:46 +00003711
3712 // We might have any sort of array type now, but fortunately they
3713 // all have the same location layout.
3714 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3715 NewTL.setLBracketLoc(TL.getLBracketLoc());
3716 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003717 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003718
3719 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003720}
Mike Stump1eb44332009-09-09 15:08:12 +00003721
3722template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003723QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003724 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003725 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003726 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003727
3728 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003729 QualType ElementType = getDerived().TransformType(T->getElementType());
3730 if (ElementType.isNull())
3731 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003732
Richard Smithf6702a32011-12-20 02:08:33 +00003733 // Vector sizes are constant expressions.
3734 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3735 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003736
John McCall60d7b3a2010-08-24 06:29:42 +00003737 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003738 if (Size.isInvalid())
3739 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003740
John McCalla2becad2009-10-21 00:40:46 +00003741 QualType Result = TL.getType();
3742 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003743 ElementType != T->getElementType() ||
3744 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003745 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003746 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003747 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003748 if (Result.isNull())
3749 return QualType();
3750 }
John McCalla2becad2009-10-21 00:40:46 +00003751
3752 // Result might be dependent or not.
3753 if (isa<DependentSizedExtVectorType>(Result)) {
3754 DependentSizedExtVectorTypeLoc NewTL
3755 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3756 NewTL.setNameLoc(TL.getNameLoc());
3757 } else {
3758 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3759 NewTL.setNameLoc(TL.getNameLoc());
3760 }
3761
3762 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003763}
Mike Stump1eb44332009-09-09 15:08:12 +00003764
3765template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003766QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003767 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003768 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003769 QualType ElementType = getDerived().TransformType(T->getElementType());
3770 if (ElementType.isNull())
3771 return QualType();
3772
John McCalla2becad2009-10-21 00:40:46 +00003773 QualType Result = TL.getType();
3774 if (getDerived().AlwaysRebuild() ||
3775 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003776 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003777 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003778 if (Result.isNull())
3779 return QualType();
3780 }
Sean Huntc3021132010-05-05 15:23:54 +00003781
John McCalla2becad2009-10-21 00:40:46 +00003782 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3783 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003784
John McCalla2becad2009-10-21 00:40:46 +00003785 return Result;
3786}
3787
3788template<typename Derived>
3789QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003790 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003791 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003792 QualType ElementType = getDerived().TransformType(T->getElementType());
3793 if (ElementType.isNull())
3794 return QualType();
3795
3796 QualType Result = TL.getType();
3797 if (getDerived().AlwaysRebuild() ||
3798 ElementType != T->getElementType()) {
3799 Result = getDerived().RebuildExtVectorType(ElementType,
3800 T->getNumElements(),
3801 /*FIXME*/ SourceLocation());
3802 if (Result.isNull())
3803 return QualType();
3804 }
Sean Huntc3021132010-05-05 15:23:54 +00003805
John McCalla2becad2009-10-21 00:40:46 +00003806 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3807 NewTL.setNameLoc(TL.getNameLoc());
3808
3809 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003810}
Mike Stump1eb44332009-09-09 15:08:12 +00003811
3812template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003813ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003814TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003815 int indexAdjustment,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003816 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003817 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003818 TypeSourceInfo *NewDI = 0;
3819
3820 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3821 // If we're substituting into a pack expansion type and we know the
3822 TypeLoc OldTL = OldDI->getTypeLoc();
3823 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3824
3825 TypeLocBuilder TLB;
3826 TypeLoc NewTL = OldDI->getTypeLoc();
3827 TLB.reserve(NewTL.getFullDataSize());
3828
3829 QualType Result = getDerived().TransformType(TLB,
3830 OldExpansionTL.getPatternLoc());
3831 if (Result.isNull())
3832 return 0;
3833
3834 Result = RebuildPackExpansionType(Result,
3835 OldExpansionTL.getPatternLoc().getSourceRange(),
3836 OldExpansionTL.getEllipsisLoc(),
3837 NumExpansions);
3838 if (Result.isNull())
3839 return 0;
3840
3841 PackExpansionTypeLoc NewExpansionTL
3842 = TLB.push<PackExpansionTypeLoc>(Result);
3843 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3844 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3845 } else
3846 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003847 if (!NewDI)
3848 return 0;
3849
John McCallfb44de92011-05-01 22:35:37 +00003850 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003851 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003852
3853 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3854 OldParm->getDeclContext(),
3855 OldParm->getInnerLocStart(),
3856 OldParm->getLocation(),
3857 OldParm->getIdentifier(),
3858 NewDI->getType(),
3859 NewDI,
3860 OldParm->getStorageClass(),
3861 OldParm->getStorageClassAsWritten(),
3862 /* DefArg */ NULL);
3863 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3864 OldParm->getFunctionScopeIndex() + indexAdjustment);
3865 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003866}
3867
3868template<typename Derived>
3869bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003870 TransformFunctionTypeParams(SourceLocation Loc,
3871 ParmVarDecl **Params, unsigned NumParams,
3872 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003873 SmallVectorImpl<QualType> &OutParamTypes,
3874 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003875 int indexAdjustment = 0;
3876
Douglas Gregora009b592011-01-07 00:20:55 +00003877 for (unsigned i = 0; i != NumParams; ++i) {
3878 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003879 assert(OldParm->getFunctionScopeIndex() == i);
3880
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003881 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003882 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003883 if (OldParm->isParameterPack()) {
3884 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003885 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003886
Douglas Gregor603cfb42011-01-05 23:12:31 +00003887 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003888 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3889 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3890 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3891 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003892 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3893
Douglas Gregor603cfb42011-01-05 23:12:31 +00003894 // Determine whether we should expand the parameter packs.
3895 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003896 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003897 llvm::Optional<unsigned> OrigNumExpansions
3898 = ExpansionTL.getTypePtr()->getNumExpansions();
3899 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003900 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3901 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003902 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003903 ShouldExpand,
3904 RetainExpansion,
3905 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003906 return true;
3907 }
3908
3909 if (ShouldExpand) {
3910 // Expand the function parameter pack into multiple, separate
3911 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003912 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003913 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003914 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3915 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003916 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003917 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003918 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003919 if (!NewParm)
3920 return true;
3921
Douglas Gregora009b592011-01-07 00:20:55 +00003922 OutParamTypes.push_back(NewParm->getType());
3923 if (PVars)
3924 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003925 }
Douglas Gregord3731192011-01-10 07:32:04 +00003926
3927 // If we're supposed to retain a pack expansion, do so by temporarily
3928 // forgetting the partially-substituted parameter pack.
3929 if (RetainExpansion) {
3930 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3931 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003932 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003933 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003934 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003935 if (!NewParm)
3936 return true;
3937
3938 OutParamTypes.push_back(NewParm->getType());
3939 if (PVars)
3940 PVars->push_back(NewParm);
3941 }
3942
John McCallfb44de92011-05-01 22:35:37 +00003943 // The next parameter should have the same adjustment as the
3944 // last thing we pushed, but we post-incremented indexAdjustment
3945 // on every push. Also, if we push nothing, the adjustment should
3946 // go down by one.
3947 indexAdjustment--;
3948
Douglas Gregor603cfb42011-01-05 23:12:31 +00003949 // We're done with the pack expansion.
3950 continue;
3951 }
3952
3953 // We'll substitute the parameter now without expanding the pack
3954 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003955 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3956 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003957 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003958 NumExpansions);
3959 } else {
3960 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003961 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003962 llvm::Optional<unsigned>());
Douglas Gregor603cfb42011-01-05 23:12:31 +00003963 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003964
John McCall21ef0fa2010-03-11 09:03:00 +00003965 if (!NewParm)
3966 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003967
Douglas Gregora009b592011-01-07 00:20:55 +00003968 OutParamTypes.push_back(NewParm->getType());
3969 if (PVars)
3970 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003971 continue;
3972 }
John McCall21ef0fa2010-03-11 09:03:00 +00003973
3974 // Deal with the possibility that we don't have a parameter
3975 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003976 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003977 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003978 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003979 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003980 if (const PackExpansionType *Expansion
3981 = dyn_cast<PackExpansionType>(OldType)) {
3982 // We have a function parameter pack that may need to be expanded.
3983 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00003984 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003985 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3986
3987 // Determine whether we should expand the parameter packs.
3988 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003989 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003990 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003991 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003992 ShouldExpand,
3993 RetainExpansion,
3994 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003995 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003996 }
3997
3998 if (ShouldExpand) {
3999 // Expand the function parameter pack into multiple, separate
4000 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004001 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004002 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4003 QualType NewType = getDerived().TransformType(Pattern);
4004 if (NewType.isNull())
4005 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004006
Douglas Gregora009b592011-01-07 00:20:55 +00004007 OutParamTypes.push_back(NewType);
4008 if (PVars)
4009 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004010 }
4011
4012 // We're done with the pack expansion.
4013 continue;
4014 }
4015
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004016 // If we're supposed to retain a pack expansion, do so by temporarily
4017 // forgetting the partially-substituted parameter pack.
4018 if (RetainExpansion) {
4019 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4020 QualType NewType = getDerived().TransformType(Pattern);
4021 if (NewType.isNull())
4022 return true;
4023
4024 OutParamTypes.push_back(NewType);
4025 if (PVars)
4026 PVars->push_back(0);
4027 }
Douglas Gregord3731192011-01-10 07:32:04 +00004028
Douglas Gregor603cfb42011-01-05 23:12:31 +00004029 // We'll substitute the parameter now without expanding the pack
4030 // expansion.
4031 OldType = Expansion->getPattern();
4032 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004033 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4034 NewType = getDerived().TransformType(OldType);
4035 } else {
4036 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004037 }
4038
Douglas Gregor603cfb42011-01-05 23:12:31 +00004039 if (NewType.isNull())
4040 return true;
4041
4042 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004043 NewType = getSema().Context.getPackExpansionType(NewType,
4044 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004045
Douglas Gregora009b592011-01-07 00:20:55 +00004046 OutParamTypes.push_back(NewType);
4047 if (PVars)
4048 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004049 }
4050
John McCallfb44de92011-05-01 22:35:37 +00004051#ifndef NDEBUG
4052 if (PVars) {
4053 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4054 if (ParmVarDecl *parm = (*PVars)[i])
4055 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004056 }
John McCallfb44de92011-05-01 22:35:37 +00004057#endif
4058
4059 return false;
4060}
John McCall21ef0fa2010-03-11 09:03:00 +00004061
4062template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004063QualType
John McCalla2becad2009-10-21 00:40:46 +00004064TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004065 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004066 // Transform the parameters and return type.
4067 //
4068 // We instantiate in source order, with the return type first followed by
4069 // the parameters, because users tend to expect this (even if they shouldn't
4070 // rely on it!).
4071 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004072 // When the function has a trailing return type, we instantiate the
4073 // parameters before the return type, since the return type can then refer
4074 // to the parameters themselves (via decltype, sizeof, etc.).
4075 //
Chris Lattner686775d2011-07-20 06:58:45 +00004076 SmallVector<QualType, 4> ParamTypes;
4077 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004078 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004079
Douglas Gregordab60ad2010-10-01 18:44:50 +00004080 QualType ResultType;
4081
4082 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004083 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4084 TL.getParmArray(),
4085 TL.getNumArgs(),
4086 TL.getTypePtr()->arg_type_begin(),
4087 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004088 return QualType();
4089
4090 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4091 if (ResultType.isNull())
4092 return QualType();
4093 }
4094 else {
4095 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4096 if (ResultType.isNull())
4097 return QualType();
4098
Douglas Gregora009b592011-01-07 00:20:55 +00004099 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4100 TL.getParmArray(),
4101 TL.getNumArgs(),
4102 TL.getTypePtr()->arg_type_begin(),
4103 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004104 return QualType();
4105 }
4106
John McCalla2becad2009-10-21 00:40:46 +00004107 QualType Result = TL.getType();
4108 if (getDerived().AlwaysRebuild() ||
4109 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004110 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004111 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4112 Result = getDerived().RebuildFunctionProtoType(ResultType,
4113 ParamTypes.data(),
4114 ParamTypes.size(),
4115 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004116 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004117 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004118 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004119 if (Result.isNull())
4120 return QualType();
4121 }
Mike Stump1eb44332009-09-09 15:08:12 +00004122
John McCalla2becad2009-10-21 00:40:46 +00004123 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004124 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4125 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004126 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004127 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4128 NewTL.setArg(i, ParamDecls[i]);
4129
4130 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004131}
Mike Stump1eb44332009-09-09 15:08:12 +00004132
Douglas Gregor577f75a2009-08-04 16:50:30 +00004133template<typename Derived>
4134QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004135 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004136 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004137 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004138 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4139 if (ResultType.isNull())
4140 return QualType();
4141
4142 QualType Result = TL.getType();
4143 if (getDerived().AlwaysRebuild() ||
4144 ResultType != T->getResultType())
4145 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4146
4147 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004148 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4149 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004150 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004151
4152 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004153}
Mike Stump1eb44332009-09-09 15:08:12 +00004154
John McCalled976492009-12-04 22:46:56 +00004155template<typename Derived> QualType
4156TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004157 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004158 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004159 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004160 if (!D)
4161 return QualType();
4162
4163 QualType Result = TL.getType();
4164 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4165 Result = getDerived().RebuildUnresolvedUsingType(D);
4166 if (Result.isNull())
4167 return QualType();
4168 }
4169
4170 // We might get an arbitrary type spec type back. We should at
4171 // least always get a type spec type, though.
4172 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4173 NewTL.setNameLoc(TL.getNameLoc());
4174
4175 return Result;
4176}
4177
Douglas Gregor577f75a2009-08-04 16:50:30 +00004178template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004179QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004180 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004181 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004182 TypedefNameDecl *Typedef
4183 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4184 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004185 if (!Typedef)
4186 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004187
John McCalla2becad2009-10-21 00:40:46 +00004188 QualType Result = TL.getType();
4189 if (getDerived().AlwaysRebuild() ||
4190 Typedef != T->getDecl()) {
4191 Result = getDerived().RebuildTypedefType(Typedef);
4192 if (Result.isNull())
4193 return QualType();
4194 }
Mike Stump1eb44332009-09-09 15:08:12 +00004195
John McCalla2becad2009-10-21 00:40:46 +00004196 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4197 NewTL.setNameLoc(TL.getNameLoc());
4198
4199 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004200}
Mike Stump1eb44332009-09-09 15:08:12 +00004201
Douglas Gregor577f75a2009-08-04 16:50:30 +00004202template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004203QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004204 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004205 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004206 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004207
John McCall60d7b3a2010-08-24 06:29:42 +00004208 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004209 if (E.isInvalid())
4210 return QualType();
4211
John McCalla2becad2009-10-21 00:40:46 +00004212 QualType Result = TL.getType();
4213 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004214 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004215 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004216 if (Result.isNull())
4217 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004218 }
John McCalla2becad2009-10-21 00:40:46 +00004219 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004220
John McCalla2becad2009-10-21 00:40:46 +00004221 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004222 NewTL.setTypeofLoc(TL.getTypeofLoc());
4223 NewTL.setLParenLoc(TL.getLParenLoc());
4224 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004225
4226 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004227}
Mike Stump1eb44332009-09-09 15:08:12 +00004228
4229template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004230QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004231 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004232 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4233 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4234 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004235 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004236
John McCalla2becad2009-10-21 00:40:46 +00004237 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004238 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4239 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004240 if (Result.isNull())
4241 return QualType();
4242 }
Mike Stump1eb44332009-09-09 15:08:12 +00004243
John McCalla2becad2009-10-21 00:40:46 +00004244 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004245 NewTL.setTypeofLoc(TL.getTypeofLoc());
4246 NewTL.setLParenLoc(TL.getLParenLoc());
4247 NewTL.setRParenLoc(TL.getRParenLoc());
4248 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004249
4250 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004251}
Mike Stump1eb44332009-09-09 15:08:12 +00004252
4253template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004254QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004255 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004256 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004257
Douglas Gregor670444e2009-08-04 22:27:00 +00004258 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004259 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004260
John McCall60d7b3a2010-08-24 06:29:42 +00004261 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004262 if (E.isInvalid())
4263 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004264
John McCalla2becad2009-10-21 00:40:46 +00004265 QualType Result = TL.getType();
4266 if (getDerived().AlwaysRebuild() ||
4267 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004268 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004269 if (Result.isNull())
4270 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004271 }
John McCalla2becad2009-10-21 00:40:46 +00004272 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004273
John McCalla2becad2009-10-21 00:40:46 +00004274 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4275 NewTL.setNameLoc(TL.getNameLoc());
4276
4277 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004278}
4279
4280template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004281QualType TreeTransform<Derived>::TransformUnaryTransformType(
4282 TypeLocBuilder &TLB,
4283 UnaryTransformTypeLoc TL) {
4284 QualType Result = TL.getType();
4285 if (Result->isDependentType()) {
4286 const UnaryTransformType *T = TL.getTypePtr();
4287 QualType NewBase =
4288 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4289 Result = getDerived().RebuildUnaryTransformType(NewBase,
4290 T->getUTTKind(),
4291 TL.getKWLoc());
4292 if (Result.isNull())
4293 return QualType();
4294 }
4295
4296 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4297 NewTL.setKWLoc(TL.getKWLoc());
4298 NewTL.setParensRange(TL.getParensRange());
4299 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4300 return Result;
4301}
4302
4303template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004304QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4305 AutoTypeLoc TL) {
4306 const AutoType *T = TL.getTypePtr();
4307 QualType OldDeduced = T->getDeducedType();
4308 QualType NewDeduced;
4309 if (!OldDeduced.isNull()) {
4310 NewDeduced = getDerived().TransformType(OldDeduced);
4311 if (NewDeduced.isNull())
4312 return QualType();
4313 }
4314
4315 QualType Result = TL.getType();
4316 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4317 Result = getDerived().RebuildAutoType(NewDeduced);
4318 if (Result.isNull())
4319 return QualType();
4320 }
4321
4322 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4323 NewTL.setNameLoc(TL.getNameLoc());
4324
4325 return Result;
4326}
4327
4328template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004329QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004330 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004331 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004332 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004333 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4334 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004335 if (!Record)
4336 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004337
John McCalla2becad2009-10-21 00:40:46 +00004338 QualType Result = TL.getType();
4339 if (getDerived().AlwaysRebuild() ||
4340 Record != T->getDecl()) {
4341 Result = getDerived().RebuildRecordType(Record);
4342 if (Result.isNull())
4343 return QualType();
4344 }
Mike Stump1eb44332009-09-09 15:08:12 +00004345
John McCalla2becad2009-10-21 00:40:46 +00004346 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4347 NewTL.setNameLoc(TL.getNameLoc());
4348
4349 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004350}
Mike Stump1eb44332009-09-09 15:08:12 +00004351
4352template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004353QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004354 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004355 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004356 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004357 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4358 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004359 if (!Enum)
4360 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004361
John McCalla2becad2009-10-21 00:40:46 +00004362 QualType Result = TL.getType();
4363 if (getDerived().AlwaysRebuild() ||
4364 Enum != T->getDecl()) {
4365 Result = getDerived().RebuildEnumType(Enum);
4366 if (Result.isNull())
4367 return QualType();
4368 }
Mike Stump1eb44332009-09-09 15:08:12 +00004369
John McCalla2becad2009-10-21 00:40:46 +00004370 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4371 NewTL.setNameLoc(TL.getNameLoc());
4372
4373 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004374}
John McCall7da24312009-09-05 00:15:47 +00004375
John McCall3cb0ebd2010-03-10 03:28:59 +00004376template<typename Derived>
4377QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4378 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004379 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004380 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4381 TL.getTypePtr()->getDecl());
4382 if (!D) return QualType();
4383
4384 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4385 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4386 return T;
4387}
4388
Douglas Gregor577f75a2009-08-04 16:50:30 +00004389template<typename Derived>
4390QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004391 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004392 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004393 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004394}
4395
Mike Stump1eb44332009-09-09 15:08:12 +00004396template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004397QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004398 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004399 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004400 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4401
4402 // Substitute into the replacement type, which itself might involve something
4403 // that needs to be transformed. This only tends to occur with default
4404 // template arguments of template template parameters.
4405 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4406 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4407 if (Replacement.isNull())
4408 return QualType();
4409
4410 // Always canonicalize the replacement type.
4411 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4412 QualType Result
4413 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4414 Replacement);
4415
4416 // Propagate type-source information.
4417 SubstTemplateTypeParmTypeLoc NewTL
4418 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4419 NewTL.setNameLoc(TL.getNameLoc());
4420 return Result;
4421
John McCall49a832b2009-10-18 09:09:24 +00004422}
4423
4424template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004425QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4426 TypeLocBuilder &TLB,
4427 SubstTemplateTypeParmPackTypeLoc TL) {
4428 return TransformTypeSpecType(TLB, TL);
4429}
4430
4431template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004432QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004433 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004434 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004435 const TemplateSpecializationType *T = TL.getTypePtr();
4436
Douglas Gregor1d752d72011-03-02 18:46:51 +00004437 // The nested-name-specifier never matters in a TemplateSpecializationType,
4438 // because we can't have a dependent nested-name-specifier anyway.
4439 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004440 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004441 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4442 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004443 if (Template.isNull())
4444 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004445
John McCall43fed0d2010-11-12 08:19:04 +00004446 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4447}
4448
Eli Friedmanb001de72011-10-06 23:00:33 +00004449template<typename Derived>
4450QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4451 AtomicTypeLoc TL) {
4452 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4453 if (ValueType.isNull())
4454 return QualType();
4455
4456 QualType Result = TL.getType();
4457 if (getDerived().AlwaysRebuild() ||
4458 ValueType != TL.getValueLoc().getType()) {
4459 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4460 if (Result.isNull())
4461 return QualType();
4462 }
4463
4464 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4465 NewTL.setKWLoc(TL.getKWLoc());
4466 NewTL.setLParenLoc(TL.getLParenLoc());
4467 NewTL.setRParenLoc(TL.getRParenLoc());
4468
4469 return Result;
4470}
4471
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004472namespace {
4473 /// \brief Simple iterator that traverses the template arguments in a
4474 /// container that provides a \c getArgLoc() member function.
4475 ///
4476 /// This iterator is intended to be used with the iterator form of
4477 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4478 template<typename ArgLocContainer>
4479 class TemplateArgumentLocContainerIterator {
4480 ArgLocContainer *Container;
4481 unsigned Index;
4482
4483 public:
4484 typedef TemplateArgumentLoc value_type;
4485 typedef TemplateArgumentLoc reference;
4486 typedef int difference_type;
4487 typedef std::input_iterator_tag iterator_category;
4488
4489 class pointer {
4490 TemplateArgumentLoc Arg;
4491
4492 public:
4493 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4494
4495 const TemplateArgumentLoc *operator->() const {
4496 return &Arg;
4497 }
4498 };
4499
4500
4501 TemplateArgumentLocContainerIterator() {}
4502
4503 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4504 unsigned Index)
4505 : Container(&Container), Index(Index) { }
4506
4507 TemplateArgumentLocContainerIterator &operator++() {
4508 ++Index;
4509 return *this;
4510 }
4511
4512 TemplateArgumentLocContainerIterator operator++(int) {
4513 TemplateArgumentLocContainerIterator Old(*this);
4514 ++(*this);
4515 return Old;
4516 }
4517
4518 TemplateArgumentLoc operator*() const {
4519 return Container->getArgLoc(Index);
4520 }
4521
4522 pointer operator->() const {
4523 return pointer(Container->getArgLoc(Index));
4524 }
4525
4526 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004527 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004528 return X.Container == Y.Container && X.Index == Y.Index;
4529 }
4530
4531 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004532 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004533 return !(X == Y);
4534 }
4535 };
4536}
4537
4538
John McCall43fed0d2010-11-12 08:19:04 +00004539template <typename Derived>
4540QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4541 TypeLocBuilder &TLB,
4542 TemplateSpecializationTypeLoc TL,
4543 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004544 TemplateArgumentListInfo NewTemplateArgs;
4545 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4546 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004547 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4548 ArgIterator;
4549 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4550 ArgIterator(TL, TL.getNumArgs()),
4551 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004552 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004553
John McCall833ca992009-10-29 08:12:44 +00004554 // FIXME: maybe don't rebuild if all the template arguments are the same.
4555
4556 QualType Result =
4557 getDerived().RebuildTemplateSpecializationType(Template,
4558 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004559 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004560
4561 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004562 // Specializations of template template parameters are represented as
4563 // TemplateSpecializationTypes, and substitution of type alias templates
4564 // within a dependent context can transform them into
4565 // DependentTemplateSpecializationTypes.
4566 if (isa<DependentTemplateSpecializationType>(Result)) {
4567 DependentTemplateSpecializationTypeLoc NewTL
4568 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4569 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4570 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4571 NewTL.setNameLoc(TL.getTemplateNameLoc());
4572 NewTL.setLAngleLoc(TL.getLAngleLoc());
4573 NewTL.setRAngleLoc(TL.getRAngleLoc());
4574 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4575 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4576 return Result;
4577 }
4578
John McCall833ca992009-10-29 08:12:44 +00004579 TemplateSpecializationTypeLoc NewTL
4580 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4581 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4582 NewTL.setLAngleLoc(TL.getLAngleLoc());
4583 NewTL.setRAngleLoc(TL.getRAngleLoc());
4584 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4585 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004586 }
Mike Stump1eb44332009-09-09 15:08:12 +00004587
John McCall833ca992009-10-29 08:12:44 +00004588 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004589}
Mike Stump1eb44332009-09-09 15:08:12 +00004590
Douglas Gregora88f09f2011-02-28 17:23:35 +00004591template <typename Derived>
4592QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4593 TypeLocBuilder &TLB,
4594 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004595 TemplateName Template,
4596 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004597 TemplateArgumentListInfo NewTemplateArgs;
4598 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4599 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4600 typedef TemplateArgumentLocContainerIterator<
4601 DependentTemplateSpecializationTypeLoc> ArgIterator;
4602 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4603 ArgIterator(TL, TL.getNumArgs()),
4604 NewTemplateArgs))
4605 return QualType();
4606
4607 // FIXME: maybe don't rebuild if all the template arguments are the same.
4608
4609 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4610 QualType Result
4611 = getSema().Context.getDependentTemplateSpecializationType(
4612 TL.getTypePtr()->getKeyword(),
4613 DTN->getQualifier(),
4614 DTN->getIdentifier(),
4615 NewTemplateArgs);
4616
4617 DependentTemplateSpecializationTypeLoc NewTL
4618 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4619 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004620
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004621 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregora88f09f2011-02-28 17:23:35 +00004622 NewTL.setNameLoc(TL.getNameLoc());
4623 NewTL.setLAngleLoc(TL.getLAngleLoc());
4624 NewTL.setRAngleLoc(TL.getRAngleLoc());
4625 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4626 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4627 return Result;
4628 }
4629
4630 QualType Result
4631 = getDerived().RebuildTemplateSpecializationType(Template,
4632 TL.getNameLoc(),
4633 NewTemplateArgs);
4634
4635 if (!Result.isNull()) {
4636 /// FIXME: Wrap this in an elaborated-type-specifier?
4637 TemplateSpecializationTypeLoc NewTL
4638 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4639 NewTL.setTemplateNameLoc(TL.getNameLoc());
4640 NewTL.setLAngleLoc(TL.getLAngleLoc());
4641 NewTL.setRAngleLoc(TL.getRAngleLoc());
4642 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4643 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4644 }
4645
4646 return Result;
4647}
4648
Mike Stump1eb44332009-09-09 15:08:12 +00004649template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004650QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004651TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004652 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004653 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004654
Douglas Gregor9e876872011-03-01 18:12:44 +00004655 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004656 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004657 if (TL.getQualifierLoc()) {
4658 QualifierLoc
4659 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4660 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004661 return QualType();
4662 }
Mike Stump1eb44332009-09-09 15:08:12 +00004663
John McCall43fed0d2010-11-12 08:19:04 +00004664 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4665 if (NamedT.isNull())
4666 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004667
Richard Smith3e4c6c42011-05-05 21:57:07 +00004668 // C++0x [dcl.type.elab]p2:
4669 // If the identifier resolves to a typedef-name or the simple-template-id
4670 // resolves to an alias template specialization, the
4671 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004672 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4673 if (const TemplateSpecializationType *TST =
4674 NamedT->getAs<TemplateSpecializationType>()) {
4675 TemplateName Template = TST->getTemplateName();
4676 if (TypeAliasTemplateDecl *TAT =
4677 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4678 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4679 diag::err_tag_reference_non_tag) << 4;
4680 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4681 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004682 }
4683 }
4684
John McCalla2becad2009-10-21 00:40:46 +00004685 QualType Result = TL.getType();
4686 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004687 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004688 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004689 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004690 T->getKeyword(),
4691 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004692 if (Result.isNull())
4693 return QualType();
4694 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004695
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004696 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004697 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004698 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004699 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004700}
Mike Stump1eb44332009-09-09 15:08:12 +00004701
4702template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004703QualType TreeTransform<Derived>::TransformAttributedType(
4704 TypeLocBuilder &TLB,
4705 AttributedTypeLoc TL) {
4706 const AttributedType *oldType = TL.getTypePtr();
4707 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4708 if (modifiedType.isNull())
4709 return QualType();
4710
4711 QualType result = TL.getType();
4712
4713 // FIXME: dependent operand expressions?
4714 if (getDerived().AlwaysRebuild() ||
4715 modifiedType != oldType->getModifiedType()) {
4716 // TODO: this is really lame; we should really be rebuilding the
4717 // equivalent type from first principles.
4718 QualType equivalentType
4719 = getDerived().TransformType(oldType->getEquivalentType());
4720 if (equivalentType.isNull())
4721 return QualType();
4722 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4723 modifiedType,
4724 equivalentType);
4725 }
4726
4727 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4728 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4729 if (TL.hasAttrOperand())
4730 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4731 if (TL.hasAttrExprOperand())
4732 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4733 else if (TL.hasAttrEnumOperand())
4734 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4735
4736 return result;
4737}
4738
4739template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004740QualType
4741TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4742 ParenTypeLoc TL) {
4743 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4744 if (Inner.isNull())
4745 return QualType();
4746
4747 QualType Result = TL.getType();
4748 if (getDerived().AlwaysRebuild() ||
4749 Inner != TL.getInnerLoc().getType()) {
4750 Result = getDerived().RebuildParenType(Inner);
4751 if (Result.isNull())
4752 return QualType();
4753 }
4754
4755 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4756 NewTL.setLParenLoc(TL.getLParenLoc());
4757 NewTL.setRParenLoc(TL.getRParenLoc());
4758 return Result;
4759}
4760
4761template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004762QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004763 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004764 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004765
Douglas Gregor2494dd02011-03-01 01:34:45 +00004766 NestedNameSpecifierLoc QualifierLoc
4767 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4768 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004769 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004770
John McCall33500952010-06-11 00:33:02 +00004771 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004772 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCall33500952010-06-11 00:33:02 +00004773 TL.getKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004774 QualifierLoc,
4775 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004776 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004777 if (Result.isNull())
4778 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004779
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004780 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4781 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004782 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4783
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004784 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4785 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004786 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004787 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004788 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4789 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004790 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004791 NewTL.setNameLoc(TL.getNameLoc());
4792 }
John McCalla2becad2009-10-21 00:40:46 +00004793 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004794}
Mike Stump1eb44332009-09-09 15:08:12 +00004795
Douglas Gregor577f75a2009-08-04 16:50:30 +00004796template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004797QualType TreeTransform<Derived>::
4798 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004799 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004800 NestedNameSpecifierLoc QualifierLoc;
4801 if (TL.getQualifierLoc()) {
4802 QualifierLoc
4803 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4804 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004805 return QualType();
4806 }
4807
John McCall43fed0d2010-11-12 08:19:04 +00004808 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004809 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004810}
4811
4812template<typename Derived>
4813QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004814TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4815 DependentTemplateSpecializationTypeLoc TL,
4816 NestedNameSpecifierLoc QualifierLoc) {
4817 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4818
4819 TemplateArgumentListInfo NewTemplateArgs;
4820 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4821 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4822
4823 typedef TemplateArgumentLocContainerIterator<
4824 DependentTemplateSpecializationTypeLoc> ArgIterator;
4825 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4826 ArgIterator(TL, TL.getNumArgs()),
4827 NewTemplateArgs))
4828 return QualType();
4829
4830 QualType Result
4831 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4832 QualifierLoc,
4833 T->getIdentifier(),
4834 TL.getNameLoc(),
4835 NewTemplateArgs);
4836 if (Result.isNull())
4837 return QualType();
4838
4839 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4840 QualType NamedT = ElabT->getNamedType();
4841
4842 // Copy information relevant to the template specialization.
4843 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004844 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004845 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004846 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4847 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004848 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004849 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004850
4851 // Copy information relevant to the elaborated type.
4852 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4853 NewTL.setKeywordLoc(TL.getKeywordLoc());
4854 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004855 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4856 DependentTemplateSpecializationTypeLoc SpecTL
4857 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor944cdae2011-03-07 15:13:34 +00004858 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004859 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004860 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004861 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4862 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004863 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004864 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004865 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004866 TemplateSpecializationTypeLoc SpecTL
4867 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004868 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004869 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4870 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004871 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004872 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004873 }
4874 return Result;
4875}
4876
4877template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004878QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4879 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004880 QualType Pattern
4881 = getDerived().TransformType(TLB, TL.getPatternLoc());
4882 if (Pattern.isNull())
4883 return QualType();
4884
4885 QualType Result = TL.getType();
4886 if (getDerived().AlwaysRebuild() ||
4887 Pattern != TL.getPatternLoc().getType()) {
4888 Result = getDerived().RebuildPackExpansionType(Pattern,
4889 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004890 TL.getEllipsisLoc(),
4891 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004892 if (Result.isNull())
4893 return QualType();
4894 }
4895
4896 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4897 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4898 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004899}
4900
4901template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004902QualType
4903TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004904 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004905 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004906 TLB.pushFullCopy(TL);
4907 return TL.getType();
4908}
4909
4910template<typename Derived>
4911QualType
4912TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004913 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004914 // ObjCObjectType is never dependent.
4915 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004916 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004917}
Mike Stump1eb44332009-09-09 15:08:12 +00004918
4919template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004920QualType
4921TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004922 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004923 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004924 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004925 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004926}
4927
Douglas Gregor577f75a2009-08-04 16:50:30 +00004928//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004929// Statement transformation
4930//===----------------------------------------------------------------------===//
4931template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004932StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004933TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004934 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004935}
4936
4937template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004938StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004939TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4940 return getDerived().TransformCompoundStmt(S, false);
4941}
4942
4943template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004944StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004945TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004946 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004947 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004948 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004949 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004950 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4951 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004952 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004953 if (Result.isInvalid()) {
4954 // Immediately fail if this was a DeclStmt, since it's very
4955 // likely that this will cause problems for future statements.
4956 if (isa<DeclStmt>(*B))
4957 return StmtError();
4958
4959 // Otherwise, just keep processing substatements and fail later.
4960 SubStmtInvalid = true;
4961 continue;
4962 }
Mike Stump1eb44332009-09-09 15:08:12 +00004963
Douglas Gregor43959a92009-08-20 07:17:43 +00004964 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4965 Statements.push_back(Result.takeAs<Stmt>());
4966 }
Mike Stump1eb44332009-09-09 15:08:12 +00004967
John McCall7114cba2010-08-27 19:56:05 +00004968 if (SubStmtInvalid)
4969 return StmtError();
4970
Douglas Gregor43959a92009-08-20 07:17:43 +00004971 if (!getDerived().AlwaysRebuild() &&
4972 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004973 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004974
4975 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4976 move_arg(Statements),
4977 S->getRBracLoc(),
4978 IsStmtExpr);
4979}
Mike Stump1eb44332009-09-09 15:08:12 +00004980
Douglas Gregor43959a92009-08-20 07:17:43 +00004981template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004982StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004983TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004984 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004985 {
4986 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004987 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004988
Eli Friedman264c1f82009-11-19 03:14:00 +00004989 // Transform the left-hand case value.
4990 LHS = getDerived().TransformExpr(S->getLHS());
4991 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004992 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004993
Eli Friedman264c1f82009-11-19 03:14:00 +00004994 // Transform the right-hand case value (for the GNU case-range extension).
4995 RHS = getDerived().TransformExpr(S->getRHS());
4996 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004997 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004998 }
Mike Stump1eb44332009-09-09 15:08:12 +00004999
Douglas Gregor43959a92009-08-20 07:17:43 +00005000 // Build the case statement.
5001 // Case statements are always rebuilt so that they will attached to their
5002 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005003 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005004 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005005 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005006 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005007 S->getColonLoc());
5008 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005009 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005010
Douglas Gregor43959a92009-08-20 07:17:43 +00005011 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005012 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005013 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005014 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005015
Douglas Gregor43959a92009-08-20 07:17:43 +00005016 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005017 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005018}
5019
5020template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005021StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005022TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005023 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005024 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005025 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005026 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005027
Douglas Gregor43959a92009-08-20 07:17:43 +00005028 // Default statements are always rebuilt
5029 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005030 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005031}
Mike Stump1eb44332009-09-09 15:08:12 +00005032
Douglas Gregor43959a92009-08-20 07:17:43 +00005033template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005034StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005035TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005036 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005037 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005038 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005039
Chris Lattner57ad3782011-02-17 20:34:02 +00005040 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5041 S->getDecl());
5042 if (!LD)
5043 return StmtError();
5044
5045
Douglas Gregor43959a92009-08-20 07:17:43 +00005046 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005047 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005048 cast<LabelDecl>(LD), SourceLocation(),
5049 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005050}
Mike Stump1eb44332009-09-09 15:08:12 +00005051
Douglas Gregor43959a92009-08-20 07:17:43 +00005052template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005053StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005054TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005055 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005056 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005057 VarDecl *ConditionVar = 0;
5058 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005059 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005060 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005061 getDerived().TransformDefinition(
5062 S->getConditionVariable()->getLocation(),
5063 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005064 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005065 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005066 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005067 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005068
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005069 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005070 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005071
5072 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005073 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005074 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5075 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005076 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005077 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005078
John McCall9ae2f072010-08-23 23:25:46 +00005079 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005080 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005081 }
Sean Huntc3021132010-05-05 15:23:54 +00005082
John McCall9ae2f072010-08-23 23:25:46 +00005083 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5084 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005085 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005086
Douglas Gregor43959a92009-08-20 07:17:43 +00005087 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005088 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005089 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005090 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005091
Douglas Gregor43959a92009-08-20 07:17:43 +00005092 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005093 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005094 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005095 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005096
Douglas Gregor43959a92009-08-20 07:17:43 +00005097 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005098 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005099 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005100 Then.get() == S->getThen() &&
5101 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005102 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005103
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005104 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005105 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005106 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005107}
5108
5109template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005110StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005111TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005112 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005113 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005114 VarDecl *ConditionVar = 0;
5115 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005116 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005117 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005118 getDerived().TransformDefinition(
5119 S->getConditionVariable()->getLocation(),
5120 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005121 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005122 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005123 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005124 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005125
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005126 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005127 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005128 }
Mike Stump1eb44332009-09-09 15:08:12 +00005129
Douglas Gregor43959a92009-08-20 07:17:43 +00005130 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005131 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005132 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005133 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005134 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005135 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005136
Douglas Gregor43959a92009-08-20 07:17:43 +00005137 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005138 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005139 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005140 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005141
Douglas Gregor43959a92009-08-20 07:17:43 +00005142 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005143 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5144 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005145}
Mike Stump1eb44332009-09-09 15:08:12 +00005146
Douglas Gregor43959a92009-08-20 07:17:43 +00005147template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005148StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005149TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005150 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005151 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005152 VarDecl *ConditionVar = 0;
5153 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005154 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005155 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005156 getDerived().TransformDefinition(
5157 S->getConditionVariable()->getLocation(),
5158 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005159 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005160 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005161 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005162 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005163
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005164 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005165 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005166
5167 if (S->getCond()) {
5168 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005169 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5170 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005171 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005172 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005173 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005174 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005175 }
Mike Stump1eb44332009-09-09 15:08:12 +00005176
John McCall9ae2f072010-08-23 23:25:46 +00005177 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5178 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005179 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005180
Douglas Gregor43959a92009-08-20 07:17:43 +00005181 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005182 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005183 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005184 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005185
Douglas Gregor43959a92009-08-20 07:17:43 +00005186 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005187 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005188 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005189 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005190 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005191
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005192 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005193 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005194}
Mike Stump1eb44332009-09-09 15:08:12 +00005195
Douglas Gregor43959a92009-08-20 07:17:43 +00005196template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005197StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005198TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005199 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005200 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005201 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005202 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005203
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005204 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005205 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005206 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005207 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005208
Douglas Gregor43959a92009-08-20 07:17:43 +00005209 if (!getDerived().AlwaysRebuild() &&
5210 Cond.get() == S->getCond() &&
5211 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005212 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005213
John McCall9ae2f072010-08-23 23:25:46 +00005214 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5215 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005216 S->getRParenLoc());
5217}
Mike Stump1eb44332009-09-09 15:08:12 +00005218
Douglas Gregor43959a92009-08-20 07:17:43 +00005219template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005220StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005221TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005222 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005223 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005224 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005225 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005226
Douglas Gregor43959a92009-08-20 07:17:43 +00005227 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005228 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005229 VarDecl *ConditionVar = 0;
5230 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005231 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005232 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005233 getDerived().TransformDefinition(
5234 S->getConditionVariable()->getLocation(),
5235 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005236 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005237 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005238 } else {
5239 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005240
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005241 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005242 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005243
5244 if (S->getCond()) {
5245 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005246 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5247 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005248 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005249 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005250
John McCall9ae2f072010-08-23 23:25:46 +00005251 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005252 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005253 }
Mike Stump1eb44332009-09-09 15:08:12 +00005254
John McCall9ae2f072010-08-23 23:25:46 +00005255 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5256 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005257 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005258
Douglas Gregor43959a92009-08-20 07:17:43 +00005259 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005260 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005261 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005262 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005263
John McCall9ae2f072010-08-23 23:25:46 +00005264 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5265 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005266 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005267
Douglas Gregor43959a92009-08-20 07:17:43 +00005268 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005269 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005270 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005271 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005272
Douglas Gregor43959a92009-08-20 07:17:43 +00005273 if (!getDerived().AlwaysRebuild() &&
5274 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005275 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005276 Inc.get() == S->getInc() &&
5277 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005278 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005279
Douglas Gregor43959a92009-08-20 07:17:43 +00005280 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005281 Init.get(), FullCond, ConditionVar,
5282 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005283}
5284
5285template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005286StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005287TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005288 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5289 S->getLabel());
5290 if (!LD)
5291 return StmtError();
5292
Douglas Gregor43959a92009-08-20 07:17:43 +00005293 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005294 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005295 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005296}
5297
5298template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005299StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005300TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005301 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005302 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005303 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005304
Douglas Gregor43959a92009-08-20 07:17:43 +00005305 if (!getDerived().AlwaysRebuild() &&
5306 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005307 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005308
5309 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005310 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005311}
5312
5313template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005314StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005315TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005316 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005317}
Mike Stump1eb44332009-09-09 15:08:12 +00005318
Douglas Gregor43959a92009-08-20 07:17:43 +00005319template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005320StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005321TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005322 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005323}
Mike Stump1eb44332009-09-09 15:08:12 +00005324
Douglas Gregor43959a92009-08-20 07:17:43 +00005325template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005326StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005327TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005328 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005329 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005330 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005331
Mike Stump1eb44332009-09-09 15:08:12 +00005332 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005333 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005334 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005335}
Mike Stump1eb44332009-09-09 15:08:12 +00005336
Douglas Gregor43959a92009-08-20 07:17:43 +00005337template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005338StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005339TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005340 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005341 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005342 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5343 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005344 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5345 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005346 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005347 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005348
Douglas Gregor43959a92009-08-20 07:17:43 +00005349 if (Transformed != *D)
5350 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005351
Douglas Gregor43959a92009-08-20 07:17:43 +00005352 Decls.push_back(Transformed);
5353 }
Mike Stump1eb44332009-09-09 15:08:12 +00005354
Douglas Gregor43959a92009-08-20 07:17:43 +00005355 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005356 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005357
5358 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005359 S->getStartLoc(), S->getEndLoc());
5360}
Mike Stump1eb44332009-09-09 15:08:12 +00005361
Douglas Gregor43959a92009-08-20 07:17:43 +00005362template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005363StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005364TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005365
John McCallca0408f2010-08-23 06:44:23 +00005366 ASTOwningVector<Expr*> Constraints(getSema());
5367 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005368 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005369
John McCall60d7b3a2010-08-24 06:29:42 +00005370 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005371 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005372
5373 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005374
Anders Carlsson703e3942010-01-24 05:50:09 +00005375 // Go through the outputs.
5376 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005377 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005378
Anders Carlsson703e3942010-01-24 05:50:09 +00005379 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005380 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005381
Anders Carlsson703e3942010-01-24 05:50:09 +00005382 // Transform the output expr.
5383 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005384 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005385 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005386 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005387
Anders Carlsson703e3942010-01-24 05:50:09 +00005388 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005389
John McCall9ae2f072010-08-23 23:25:46 +00005390 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005391 }
Sean Huntc3021132010-05-05 15:23:54 +00005392
Anders Carlsson703e3942010-01-24 05:50:09 +00005393 // Go through the inputs.
5394 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005395 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005396
Anders Carlsson703e3942010-01-24 05:50:09 +00005397 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005398 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005399
Anders Carlsson703e3942010-01-24 05:50:09 +00005400 // Transform the input expr.
5401 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005402 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005403 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005404 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005405
Anders Carlsson703e3942010-01-24 05:50:09 +00005406 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005407
John McCall9ae2f072010-08-23 23:25:46 +00005408 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005409 }
Sean Huntc3021132010-05-05 15:23:54 +00005410
Anders Carlsson703e3942010-01-24 05:50:09 +00005411 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005412 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005413
5414 // Go through the clobbers.
5415 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005416 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005417
5418 // No need to transform the asm string literal.
5419 AsmString = SemaRef.Owned(S->getAsmString());
5420
5421 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5422 S->isSimple(),
5423 S->isVolatile(),
5424 S->getNumOutputs(),
5425 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005426 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005427 move_arg(Constraints),
5428 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005429 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005430 move_arg(Clobbers),
5431 S->getRParenLoc(),
5432 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005433}
5434
5435
5436template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005437StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005438TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005439 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005440 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005441 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005442 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005443
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005444 // Transform the @catch statements (if present).
5445 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005446 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005447 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005448 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005449 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005450 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005451 if (Catch.get() != S->getCatchStmt(I))
5452 AnyCatchChanged = true;
5453 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005454 }
Sean Huntc3021132010-05-05 15:23:54 +00005455
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005456 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005457 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005458 if (S->getFinallyStmt()) {
5459 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5460 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005461 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005462 }
5463
5464 // If nothing changed, just retain this statement.
5465 if (!getDerived().AlwaysRebuild() &&
5466 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005467 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005468 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005469 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005470
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005471 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005472 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5473 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005474}
Mike Stump1eb44332009-09-09 15:08:12 +00005475
Douglas Gregor43959a92009-08-20 07:17:43 +00005476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005477StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005478TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005479 // Transform the @catch parameter, if there is one.
5480 VarDecl *Var = 0;
5481 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5482 TypeSourceInfo *TSInfo = 0;
5483 if (FromVar->getTypeSourceInfo()) {
5484 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5485 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005486 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005487 }
Sean Huntc3021132010-05-05 15:23:54 +00005488
Douglas Gregorbe270a02010-04-26 17:57:08 +00005489 QualType T;
5490 if (TSInfo)
5491 T = TSInfo->getType();
5492 else {
5493 T = getDerived().TransformType(FromVar->getType());
5494 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005495 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005496 }
Sean Huntc3021132010-05-05 15:23:54 +00005497
Douglas Gregorbe270a02010-04-26 17:57:08 +00005498 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5499 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005500 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005501 }
Sean Huntc3021132010-05-05 15:23:54 +00005502
John McCall60d7b3a2010-08-24 06:29:42 +00005503 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005504 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005505 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005506
5507 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005508 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005509 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005510}
Mike Stump1eb44332009-09-09 15:08:12 +00005511
Douglas Gregor43959a92009-08-20 07:17:43 +00005512template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005513StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005514TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005515 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005516 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005517 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005518 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005519
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005520 // If nothing changed, just retain this statement.
5521 if (!getDerived().AlwaysRebuild() &&
5522 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005523 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005524
5525 // Build a new statement.
5526 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005527 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005528}
Mike Stump1eb44332009-09-09 15:08:12 +00005529
Douglas Gregor43959a92009-08-20 07:17:43 +00005530template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005531StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005532TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005533 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005534 if (S->getThrowExpr()) {
5535 Operand = getDerived().TransformExpr(S->getThrowExpr());
5536 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005537 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005538 }
Sean Huntc3021132010-05-05 15:23:54 +00005539
Douglas Gregord1377b22010-04-22 21:44:01 +00005540 if (!getDerived().AlwaysRebuild() &&
5541 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005542 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005543
John McCall9ae2f072010-08-23 23:25:46 +00005544 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005545}
Mike Stump1eb44332009-09-09 15:08:12 +00005546
Douglas Gregor43959a92009-08-20 07:17:43 +00005547template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005548StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005549TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005550 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005551 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005552 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005553 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005554 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005555 Object =
5556 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5557 Object.get());
5558 if (Object.isInvalid())
5559 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005560
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005561 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005562 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005563 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005564 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005565
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005566 // If nothing change, just retain the current statement.
5567 if (!getDerived().AlwaysRebuild() &&
5568 Object.get() == S->getSynchExpr() &&
5569 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005570 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005571
5572 // Build a new statement.
5573 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005574 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005575}
5576
5577template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005578StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005579TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5580 ObjCAutoreleasePoolStmt *S) {
5581 // Transform the body.
5582 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5583 if (Body.isInvalid())
5584 return StmtError();
5585
5586 // If nothing changed, just retain this statement.
5587 if (!getDerived().AlwaysRebuild() &&
5588 Body.get() == S->getSubStmt())
5589 return SemaRef.Owned(S);
5590
5591 // Build a new statement.
5592 return getDerived().RebuildObjCAutoreleasePoolStmt(
5593 S->getAtLoc(), Body.get());
5594}
5595
5596template<typename Derived>
5597StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005598TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005599 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005600 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005601 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005602 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005603 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005604
Douglas Gregorc3203e72010-04-22 23:10:45 +00005605 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005606 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005607 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005608 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005609 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5610 Collection.take());
5611 if (Collection.isInvalid())
5612 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005613
Douglas Gregorc3203e72010-04-22 23:10:45 +00005614 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005615 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005616 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005617 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005618
Douglas Gregorc3203e72010-04-22 23:10:45 +00005619 // If nothing changed, just retain this statement.
5620 if (!getDerived().AlwaysRebuild() &&
5621 Element.get() == S->getElement() &&
5622 Collection.get() == S->getCollection() &&
5623 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005624 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005625
Douglas Gregorc3203e72010-04-22 23:10:45 +00005626 // Build a new statement.
5627 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5628 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005629 Element.get(),
5630 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005631 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005632 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005633}
5634
5635
5636template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005637StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005638TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5639 // Transform the exception declaration, if any.
5640 VarDecl *Var = 0;
5641 if (S->getExceptionDecl()) {
5642 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005643 TypeSourceInfo *T = getDerived().TransformType(
5644 ExceptionDecl->getTypeSourceInfo());
5645 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005646 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005647
Douglas Gregor83cb9422010-09-09 17:09:21 +00005648 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005649 ExceptionDecl->getInnerLocStart(),
5650 ExceptionDecl->getLocation(),
5651 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005652 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005653 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005654 }
Mike Stump1eb44332009-09-09 15:08:12 +00005655
Douglas Gregor43959a92009-08-20 07:17:43 +00005656 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005657 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005658 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005659 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005660
Douglas Gregor43959a92009-08-20 07:17:43 +00005661 if (!getDerived().AlwaysRebuild() &&
5662 !Var &&
5663 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005664 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005665
5666 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5667 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005668 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005669}
Mike Stump1eb44332009-09-09 15:08:12 +00005670
Douglas Gregor43959a92009-08-20 07:17:43 +00005671template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005672StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005673TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5674 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005675 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005676 = getDerived().TransformCompoundStmt(S->getTryBlock());
5677 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005678 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005679
Douglas Gregor43959a92009-08-20 07:17:43 +00005680 // Transform the handlers.
5681 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005682 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005683 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005684 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005685 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5686 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005687 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005688
Douglas Gregor43959a92009-08-20 07:17:43 +00005689 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5690 Handlers.push_back(Handler.takeAs<Stmt>());
5691 }
Mike Stump1eb44332009-09-09 15:08:12 +00005692
Douglas Gregor43959a92009-08-20 07:17:43 +00005693 if (!getDerived().AlwaysRebuild() &&
5694 TryBlock.get() == S->getTryBlock() &&
5695 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005696 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005697
John McCall9ae2f072010-08-23 23:25:46 +00005698 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005699 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005700}
Mike Stump1eb44332009-09-09 15:08:12 +00005701
Richard Smithad762fc2011-04-14 22:09:26 +00005702template<typename Derived>
5703StmtResult
5704TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5705 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5706 if (Range.isInvalid())
5707 return StmtError();
5708
5709 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5710 if (BeginEnd.isInvalid())
5711 return StmtError();
5712
5713 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5714 if (Cond.isInvalid())
5715 return StmtError();
5716
5717 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5718 if (Inc.isInvalid())
5719 return StmtError();
5720
5721 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5722 if (LoopVar.isInvalid())
5723 return StmtError();
5724
5725 StmtResult NewStmt = S;
5726 if (getDerived().AlwaysRebuild() ||
5727 Range.get() != S->getRangeStmt() ||
5728 BeginEnd.get() != S->getBeginEndStmt() ||
5729 Cond.get() != S->getCond() ||
5730 Inc.get() != S->getInc() ||
5731 LoopVar.get() != S->getLoopVarStmt())
5732 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5733 S->getColonLoc(), Range.get(),
5734 BeginEnd.get(), Cond.get(),
5735 Inc.get(), LoopVar.get(),
5736 S->getRParenLoc());
5737
5738 StmtResult Body = getDerived().TransformStmt(S->getBody());
5739 if (Body.isInvalid())
5740 return StmtError();
5741
5742 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5743 // it now so we have a new statement to attach the body to.
5744 if (Body.get() != S->getBody() && NewStmt.get() == S)
5745 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5746 S->getColonLoc(), Range.get(),
5747 BeginEnd.get(), Cond.get(),
5748 Inc.get(), LoopVar.get(),
5749 S->getRParenLoc());
5750
5751 if (NewStmt.get() == S)
5752 return SemaRef.Owned(S);
5753
5754 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5755}
5756
John Wiegley28bbe4b2011-04-28 01:08:34 +00005757template<typename Derived>
5758StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005759TreeTransform<Derived>::TransformMSDependentExistsStmt(
5760 MSDependentExistsStmt *S) {
5761 // Transform the nested-name-specifier, if any.
5762 NestedNameSpecifierLoc QualifierLoc;
5763 if (S->getQualifierLoc()) {
5764 QualifierLoc
5765 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5766 if (!QualifierLoc)
5767 return StmtError();
5768 }
5769
5770 // Transform the declaration name.
5771 DeclarationNameInfo NameInfo = S->getNameInfo();
5772 if (NameInfo.getName()) {
5773 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5774 if (!NameInfo.getName())
5775 return StmtError();
5776 }
5777
5778 // Check whether anything changed.
5779 if (!getDerived().AlwaysRebuild() &&
5780 QualifierLoc == S->getQualifierLoc() &&
5781 NameInfo.getName() == S->getNameInfo().getName())
5782 return S;
5783
5784 // Determine whether this name exists, if we can.
5785 CXXScopeSpec SS;
5786 SS.Adopt(QualifierLoc);
5787 bool Dependent = false;
5788 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5789 case Sema::IER_Exists:
5790 if (S->isIfExists())
5791 break;
5792
5793 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5794
5795 case Sema::IER_DoesNotExist:
5796 if (S->isIfNotExists())
5797 break;
5798
5799 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5800
5801 case Sema::IER_Dependent:
5802 Dependent = true;
5803 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005804
5805 case Sema::IER_Error:
5806 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005807 }
5808
5809 // We need to continue with the instantiation, so do so now.
5810 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5811 if (SubStmt.isInvalid())
5812 return StmtError();
5813
5814 // If we have resolved the name, just transform to the substatement.
5815 if (!Dependent)
5816 return SubStmt;
5817
5818 // The name is still dependent, so build a dependent expression again.
5819 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5820 S->isIfExists(),
5821 QualifierLoc,
5822 NameInfo,
5823 SubStmt.get());
5824}
5825
5826template<typename Derived>
5827StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005828TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5829 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5830 if(TryBlock.isInvalid()) return StmtError();
5831
5832 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5833 if(!getDerived().AlwaysRebuild() &&
5834 TryBlock.get() == S->getTryBlock() &&
5835 Handler.get() == S->getHandler())
5836 return SemaRef.Owned(S);
5837
5838 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5839 S->getTryLoc(),
5840 TryBlock.take(),
5841 Handler.take());
5842}
5843
5844template<typename Derived>
5845StmtResult
5846TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5847 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5848 if(Block.isInvalid()) return StmtError();
5849
5850 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5851 Block.take());
5852}
5853
5854template<typename Derived>
5855StmtResult
5856TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5857 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5858 if(FilterExpr.isInvalid()) return StmtError();
5859
5860 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5861 if(Block.isInvalid()) return StmtError();
5862
5863 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5864 FilterExpr.take(),
5865 Block.take());
5866}
5867
5868template<typename Derived>
5869StmtResult
5870TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5871 if(isa<SEHFinallyStmt>(Handler))
5872 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5873 else
5874 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5875}
5876
Douglas Gregor43959a92009-08-20 07:17:43 +00005877//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005878// Expression transformation
5879//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005880template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005881ExprResult
John McCall454feb92009-12-08 09:21:05 +00005882TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005883 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005884}
Mike Stump1eb44332009-09-09 15:08:12 +00005885
5886template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005887ExprResult
John McCall454feb92009-12-08 09:21:05 +00005888TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005889 NestedNameSpecifierLoc QualifierLoc;
5890 if (E->getQualifierLoc()) {
5891 QualifierLoc
5892 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5893 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005894 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005895 }
John McCalldbd872f2009-12-08 09:08:17 +00005896
5897 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005898 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5899 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005900 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005901 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005902
John McCallec8045d2010-08-17 21:27:17 +00005903 DeclarationNameInfo NameInfo = E->getNameInfo();
5904 if (NameInfo.getName()) {
5905 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5906 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005907 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005908 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005909
5910 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005911 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005912 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005913 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005914 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005915
5916 // Mark it referenced in the new context regardless.
5917 // FIXME: this is a bit instantiation-specific.
5918 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5919
John McCall3fa5cae2010-10-26 07:05:15 +00005920 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005921 }
John McCalldbd872f2009-12-08 09:08:17 +00005922
5923 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005924 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005925 TemplateArgs = &TransArgs;
5926 TransArgs.setLAngleLoc(E->getLAngleLoc());
5927 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005928 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5929 E->getNumTemplateArgs(),
5930 TransArgs))
5931 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005932 }
5933
Douglas Gregor40d96a62011-02-28 21:54:11 +00005934 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5935 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005936}
Mike Stump1eb44332009-09-09 15:08:12 +00005937
Douglas Gregorb98b1992009-08-11 05:31:07 +00005938template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005939ExprResult
John McCall454feb92009-12-08 09:21:05 +00005940TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005941 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005942}
Mike Stump1eb44332009-09-09 15:08:12 +00005943
Douglas Gregorb98b1992009-08-11 05:31:07 +00005944template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005945ExprResult
John McCall454feb92009-12-08 09:21:05 +00005946TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005947 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005948}
Mike Stump1eb44332009-09-09 15:08:12 +00005949
Douglas Gregorb98b1992009-08-11 05:31:07 +00005950template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005951ExprResult
John McCall454feb92009-12-08 09:21:05 +00005952TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005953 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005954}
Mike Stump1eb44332009-09-09 15:08:12 +00005955
Douglas Gregorb98b1992009-08-11 05:31:07 +00005956template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005957ExprResult
John McCall454feb92009-12-08 09:21:05 +00005958TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005959 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005960}
Mike Stump1eb44332009-09-09 15:08:12 +00005961
Douglas Gregorb98b1992009-08-11 05:31:07 +00005962template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005963ExprResult
John McCall454feb92009-12-08 09:21:05 +00005964TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005965 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005966}
5967
5968template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005969ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00005970TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5971 ExprResult ControllingExpr =
5972 getDerived().TransformExpr(E->getControllingExpr());
5973 if (ControllingExpr.isInvalid())
5974 return ExprError();
5975
Chris Lattner686775d2011-07-20 06:58:45 +00005976 SmallVector<Expr *, 4> AssocExprs;
5977 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00005978 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5979 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5980 if (TS) {
5981 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5982 if (!AssocType)
5983 return ExprError();
5984 AssocTypes.push_back(AssocType);
5985 } else {
5986 AssocTypes.push_back(0);
5987 }
5988
5989 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5990 if (AssocExpr.isInvalid())
5991 return ExprError();
5992 AssocExprs.push_back(AssocExpr.release());
5993 }
5994
5995 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5996 E->getDefaultLoc(),
5997 E->getRParenLoc(),
5998 ControllingExpr.release(),
5999 AssocTypes.data(),
6000 AssocExprs.data(),
6001 E->getNumAssocs());
6002}
6003
6004template<typename Derived>
6005ExprResult
John McCall454feb92009-12-08 09:21:05 +00006006TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006007 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006008 if (SubExpr.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() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006012 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006013
John McCall9ae2f072010-08-23 23:25:46 +00006014 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006015 E->getRParen());
6016}
6017
Mike Stump1eb44332009-09-09 15:08:12 +00006018template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006019ExprResult
John McCall454feb92009-12-08 09:21:05 +00006020TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006021 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006022 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006023 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006024
Douglas Gregorb98b1992009-08-11 05:31:07 +00006025 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006026 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006027
Douglas Gregorb98b1992009-08-11 05:31:07 +00006028 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6029 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006030 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006031}
Mike Stump1eb44332009-09-09 15:08:12 +00006032
Douglas Gregorb98b1992009-08-11 05:31:07 +00006033template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006034ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006035TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6036 // Transform the type.
6037 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6038 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006039 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006040
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006041 // Transform all of the components into components similar to what the
6042 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006043 // FIXME: It would be slightly more efficient in the non-dependent case to
6044 // just map FieldDecls, rather than requiring the rebuilder to look for
6045 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006046 // template code that we don't care.
6047 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006048 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006049 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006050 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006051 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6052 const Node &ON = E->getComponent(I);
6053 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006054 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006055 Comp.LocStart = ON.getSourceRange().getBegin();
6056 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006057 switch (ON.getKind()) {
6058 case Node::Array: {
6059 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006060 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006061 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006062 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006063
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006064 ExprChanged = ExprChanged || Index.get() != FromIndex;
6065 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006066 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006067 break;
6068 }
Sean Huntc3021132010-05-05 15:23:54 +00006069
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006070 case Node::Field:
6071 case Node::Identifier:
6072 Comp.isBrackets = false;
6073 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006074 if (!Comp.U.IdentInfo)
6075 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006076
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006077 break;
Sean Huntc3021132010-05-05 15:23:54 +00006078
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006079 case Node::Base:
6080 // Will be recomputed during the rebuild.
6081 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006082 }
Sean Huntc3021132010-05-05 15:23:54 +00006083
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006084 Components.push_back(Comp);
6085 }
Sean Huntc3021132010-05-05 15:23:54 +00006086
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006087 // If nothing changed, retain the existing expression.
6088 if (!getDerived().AlwaysRebuild() &&
6089 Type == E->getTypeSourceInfo() &&
6090 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006091 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006092
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006093 // Build a new offsetof expression.
6094 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6095 Components.data(), Components.size(),
6096 E->getRParenLoc());
6097}
6098
6099template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006100ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006101TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6102 assert(getDerived().AlreadyTransformed(E->getType()) &&
6103 "opaque value expression requires transformation");
6104 return SemaRef.Owned(E);
6105}
6106
6107template<typename Derived>
6108ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006109TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006110 // Rebuild the syntactic form. The original syntactic form has
6111 // opaque-value expressions in it, so strip those away and rebuild
6112 // the result. This is a really awful way of doing this, but the
6113 // better solution (rebuilding the semantic expressions and
6114 // rebinding OVEs as necessary) doesn't work; we'd need
6115 // TreeTransform to not strip away implicit conversions.
6116 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6117 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006118 if (result.isInvalid()) return ExprError();
6119
6120 // If that gives us a pseudo-object result back, the pseudo-object
6121 // expression must have been an lvalue-to-rvalue conversion which we
6122 // should reapply.
6123 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6124 result = SemaRef.checkPseudoObjectRValue(result.take());
6125
6126 return result;
6127}
6128
6129template<typename Derived>
6130ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006131TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6132 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006133 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006134 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006135
John McCalla93c9342009-12-07 02:54:59 +00006136 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006137 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006138 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006139
John McCall5ab75172009-11-04 07:28:41 +00006140 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006141 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006142
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006143 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6144 E->getKind(),
6145 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006146 }
Mike Stump1eb44332009-09-09 15:08:12 +00006147
John McCall60d7b3a2010-08-24 06:29:42 +00006148 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00006149 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006150 // C++0x [expr.sizeof]p1:
6151 // The operand is either an expression, which is an unevaluated operand
6152 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00006153 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006154
Douglas Gregorb98b1992009-08-11 05:31:07 +00006155 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6156 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006157 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006158
Douglas Gregorb98b1992009-08-11 05:31:07 +00006159 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006160 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006161 }
Mike Stump1eb44332009-09-09 15:08:12 +00006162
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006163 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6164 E->getOperatorLoc(),
6165 E->getKind(),
6166 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006167}
Mike Stump1eb44332009-09-09 15:08:12 +00006168
Douglas Gregorb98b1992009-08-11 05:31:07 +00006169template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006170ExprResult
John McCall454feb92009-12-08 09:21:05 +00006171TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006172 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006173 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006174 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006175
John McCall60d7b3a2010-08-24 06:29:42 +00006176 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006177 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006178 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006179
6180
Douglas Gregorb98b1992009-08-11 05:31:07 +00006181 if (!getDerived().AlwaysRebuild() &&
6182 LHS.get() == E->getLHS() &&
6183 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006184 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006185
John McCall9ae2f072010-08-23 23:25:46 +00006186 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006187 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006188 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006189 E->getRBracketLoc());
6190}
Mike Stump1eb44332009-09-09 15:08:12 +00006191
6192template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006193ExprResult
John McCall454feb92009-12-08 09:21:05 +00006194TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006195 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006196 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006197 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006198 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006199
6200 // Transform arguments.
6201 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006202 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006203 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6204 &ArgChanged))
6205 return ExprError();
6206
Douglas Gregorb98b1992009-08-11 05:31:07 +00006207 if (!getDerived().AlwaysRebuild() &&
6208 Callee.get() == E->getCallee() &&
6209 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006210 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006211
Douglas Gregorb98b1992009-08-11 05:31:07 +00006212 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006213 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006214 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006215 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006216 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217 E->getRParenLoc());
6218}
Mike Stump1eb44332009-09-09 15:08:12 +00006219
6220template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006221ExprResult
John McCall454feb92009-12-08 09:21:05 +00006222TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006223 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006224 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006225 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006226
Douglas Gregor40d96a62011-02-28 21:54:11 +00006227 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006228 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006229 QualifierLoc
6230 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6231
6232 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006233 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006234 }
Mike Stump1eb44332009-09-09 15:08:12 +00006235
Eli Friedmanf595cc42009-12-04 06:40:45 +00006236 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006237 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6238 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006239 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006240 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006241
John McCall6bb80172010-03-30 21:47:33 +00006242 NamedDecl *FoundDecl = E->getFoundDecl();
6243 if (FoundDecl == E->getMemberDecl()) {
6244 FoundDecl = Member;
6245 } else {
6246 FoundDecl = cast_or_null<NamedDecl>(
6247 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6248 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006249 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006250 }
6251
Douglas Gregorb98b1992009-08-11 05:31:07 +00006252 if (!getDerived().AlwaysRebuild() &&
6253 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006254 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006255 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006256 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006257 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006258
Anders Carlsson1f240322009-12-22 05:24:09 +00006259 // Mark it referenced in the new context regardless.
6260 // FIXME: this is a bit instantiation-specific.
6261 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00006262 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006263 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006264
John McCalld5532b62009-11-23 01:53:49 +00006265 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006266 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006267 TransArgs.setLAngleLoc(E->getLAngleLoc());
6268 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006269 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6270 E->getNumTemplateArgs(),
6271 TransArgs))
6272 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006273 }
Sean Huntc3021132010-05-05 15:23:54 +00006274
Douglas Gregorb98b1992009-08-11 05:31:07 +00006275 // FIXME: Bogus source location for the operator
6276 SourceLocation FakeOperatorLoc
6277 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6278
John McCallc2233c52010-01-15 08:34:02 +00006279 // FIXME: to do this check properly, we will need to preserve the
6280 // first-qualifier-in-scope here, just in case we had a dependent
6281 // base (and therefore couldn't do the check) and a
6282 // nested-name-qualifier (and therefore could do the lookup).
6283 NamedDecl *FirstQualifierInScope = 0;
6284
John McCall9ae2f072010-08-23 23:25:46 +00006285 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006286 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006287 QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006288 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006289 Member,
John McCall6bb80172010-03-30 21:47:33 +00006290 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006291 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006292 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006293 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006294}
Mike Stump1eb44332009-09-09 15:08:12 +00006295
Douglas Gregorb98b1992009-08-11 05:31:07 +00006296template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006297ExprResult
John McCall454feb92009-12-08 09:21:05 +00006298TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006299 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006300 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006301 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006302
John McCall60d7b3a2010-08-24 06:29:42 +00006303 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006304 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006305 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006306
Douglas Gregorb98b1992009-08-11 05:31:07 +00006307 if (!getDerived().AlwaysRebuild() &&
6308 LHS.get() == E->getLHS() &&
6309 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006310 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006311
Douglas Gregorb98b1992009-08-11 05:31:07 +00006312 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006313 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006314}
6315
Mike Stump1eb44332009-09-09 15:08:12 +00006316template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006317ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006318TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006319 CompoundAssignOperator *E) {
6320 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006321}
Mike Stump1eb44332009-09-09 15:08:12 +00006322
Douglas Gregorb98b1992009-08-11 05:31:07 +00006323template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006324ExprResult TreeTransform<Derived>::
6325TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6326 // Just rebuild the common and RHS expressions and see whether we
6327 // get any changes.
6328
6329 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6330 if (commonExpr.isInvalid())
6331 return ExprError();
6332
6333 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6334 if (rhs.isInvalid())
6335 return ExprError();
6336
6337 if (!getDerived().AlwaysRebuild() &&
6338 commonExpr.get() == e->getCommon() &&
6339 rhs.get() == e->getFalseExpr())
6340 return SemaRef.Owned(e);
6341
6342 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6343 e->getQuestionLoc(),
6344 0,
6345 e->getColonLoc(),
6346 rhs.get());
6347}
6348
6349template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006350ExprResult
John McCall454feb92009-12-08 09:21:05 +00006351TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006352 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006353 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006354 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006355
John McCall60d7b3a2010-08-24 06:29:42 +00006356 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006357 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006358 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006359
John McCall60d7b3a2010-08-24 06:29:42 +00006360 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006361 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006362 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006363
Douglas Gregorb98b1992009-08-11 05:31:07 +00006364 if (!getDerived().AlwaysRebuild() &&
6365 Cond.get() == E->getCond() &&
6366 LHS.get() == E->getLHS() &&
6367 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006368 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006369
John McCall9ae2f072010-08-23 23:25:46 +00006370 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006371 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006372 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006373 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006374 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006375}
Mike Stump1eb44332009-09-09 15:08:12 +00006376
6377template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006378ExprResult
John McCall454feb92009-12-08 09:21:05 +00006379TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006380 // Implicit casts are eliminated during transformation, since they
6381 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006382 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006383}
Mike Stump1eb44332009-09-09 15:08:12 +00006384
Douglas Gregorb98b1992009-08-11 05:31:07 +00006385template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006386ExprResult
John McCall454feb92009-12-08 09:21:05 +00006387TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006388 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6389 if (!Type)
6390 return ExprError();
6391
John McCall60d7b3a2010-08-24 06:29:42 +00006392 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006393 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006394 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006395 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006396
Douglas Gregorb98b1992009-08-11 05:31:07 +00006397 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006398 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006399 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006400 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006401
John McCall9d125032010-01-15 18:39:57 +00006402 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006403 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006404 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006405 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006406}
Mike Stump1eb44332009-09-09 15:08:12 +00006407
Douglas Gregorb98b1992009-08-11 05:31:07 +00006408template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006409ExprResult
John McCall454feb92009-12-08 09:21:05 +00006410TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006411 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6412 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6413 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006414 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006415
John McCall60d7b3a2010-08-24 06:29:42 +00006416 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006417 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006418 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006419
Douglas Gregorb98b1992009-08-11 05:31:07 +00006420 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006421 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006422 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006423 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006424
John McCall1d7d8d62010-01-19 22:33:45 +00006425 // Note: the expression type doesn't necessarily match the
6426 // type-as-written, but that's okay, because it should always be
6427 // derivable from the initializer.
6428
John McCall42f56b52010-01-18 19:35:47 +00006429 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006430 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006431 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006432}
Mike Stump1eb44332009-09-09 15:08:12 +00006433
Douglas Gregorb98b1992009-08-11 05:31:07 +00006434template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006435ExprResult
John McCall454feb92009-12-08 09:21:05 +00006436TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006437 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006439 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006440
Douglas Gregorb98b1992009-08-11 05:31:07 +00006441 if (!getDerived().AlwaysRebuild() &&
6442 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006443 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006444
Douglas Gregorb98b1992009-08-11 05:31:07 +00006445 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006446 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006447 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006448 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449 E->getAccessorLoc(),
6450 E->getAccessor());
6451}
Mike Stump1eb44332009-09-09 15:08:12 +00006452
Douglas Gregorb98b1992009-08-11 05:31:07 +00006453template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006454ExprResult
John McCall454feb92009-12-08 09:21:05 +00006455TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006456 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006457
John McCallca0408f2010-08-23 06:44:23 +00006458 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006459 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6460 Inits, &InitChanged))
6461 return ExprError();
6462
Douglas Gregorb98b1992009-08-11 05:31:07 +00006463 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006464 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006465
Douglas Gregorb98b1992009-08-11 05:31:07 +00006466 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006467 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006468}
Mike Stump1eb44332009-09-09 15:08:12 +00006469
Douglas Gregorb98b1992009-08-11 05:31:07 +00006470template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006471ExprResult
John McCall454feb92009-12-08 09:21:05 +00006472TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006473 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006474
Douglas Gregor43959a92009-08-20 07:17:43 +00006475 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006476 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006477 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006478 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006479
Douglas Gregor43959a92009-08-20 07:17:43 +00006480 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006481 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482 bool ExprChanged = false;
6483 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6484 DEnd = E->designators_end();
6485 D != DEnd; ++D) {
6486 if (D->isFieldDesignator()) {
6487 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6488 D->getDotLoc(),
6489 D->getFieldLoc()));
6490 continue;
6491 }
Mike Stump1eb44332009-09-09 15:08:12 +00006492
Douglas Gregorb98b1992009-08-11 05:31:07 +00006493 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006494 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006495 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006496 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006497
6498 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006499 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006500
Douglas Gregorb98b1992009-08-11 05:31:07 +00006501 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6502 ArrayExprs.push_back(Index.release());
6503 continue;
6504 }
Mike Stump1eb44332009-09-09 15:08:12 +00006505
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006507 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006508 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6509 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006510 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006511
John McCall60d7b3a2010-08-24 06:29:42 +00006512 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006513 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006514 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006515
6516 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517 End.get(),
6518 D->getLBracketLoc(),
6519 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006520
Douglas Gregorb98b1992009-08-11 05:31:07 +00006521 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6522 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006523
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524 ArrayExprs.push_back(Start.release());
6525 ArrayExprs.push_back(End.release());
6526 }
Mike Stump1eb44332009-09-09 15:08:12 +00006527
Douglas Gregorb98b1992009-08-11 05:31:07 +00006528 if (!getDerived().AlwaysRebuild() &&
6529 Init.get() == E->getInit() &&
6530 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006531 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006532
Douglas Gregorb98b1992009-08-11 05:31:07 +00006533 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6534 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006535 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006536}
Mike Stump1eb44332009-09-09 15:08:12 +00006537
Douglas Gregorb98b1992009-08-11 05:31:07 +00006538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006539ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006540TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006541 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006542 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006543
Douglas Gregor5557b252009-10-28 00:29:27 +00006544 // FIXME: Will we ever have proper type location here? Will we actually
6545 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006546 QualType T = getDerived().TransformType(E->getType());
6547 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006548 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006549
Douglas Gregorb98b1992009-08-11 05:31:07 +00006550 if (!getDerived().AlwaysRebuild() &&
6551 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006552 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006553
Douglas Gregorb98b1992009-08-11 05:31:07 +00006554 return getDerived().RebuildImplicitValueInitExpr(T);
6555}
Mike Stump1eb44332009-09-09 15:08:12 +00006556
Douglas Gregorb98b1992009-08-11 05:31:07 +00006557template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006558ExprResult
John McCall454feb92009-12-08 09:21:05 +00006559TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006560 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6561 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006562 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006563
John McCall60d7b3a2010-08-24 06:29:42 +00006564 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006566 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006567
Douglas Gregorb98b1992009-08-11 05:31:07 +00006568 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006569 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006570 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006571 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006572
John McCall9ae2f072010-08-23 23:25:46 +00006573 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006574 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006575}
6576
6577template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006578ExprResult
John McCall454feb92009-12-08 09:21:05 +00006579TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006581 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006582 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6583 &ArgumentChanged))
6584 return ExprError();
6585
Douglas Gregorb98b1992009-08-11 05:31:07 +00006586 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6587 move_arg(Inits),
6588 E->getRParenLoc());
6589}
Mike Stump1eb44332009-09-09 15:08:12 +00006590
Douglas Gregorb98b1992009-08-11 05:31:07 +00006591/// \brief Transform an address-of-label expression.
6592///
6593/// By default, the transformation of an address-of-label expression always
6594/// rebuilds the expression, so that the label identifier can be resolved to
6595/// the corresponding label statement by semantic analysis.
6596template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006597ExprResult
John McCall454feb92009-12-08 09:21:05 +00006598TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006599 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6600 E->getLabel());
6601 if (!LD)
6602 return ExprError();
6603
Douglas Gregorb98b1992009-08-11 05:31:07 +00006604 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006605 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006606}
Mike Stump1eb44332009-09-09 15:08:12 +00006607
6608template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006609ExprResult
John McCall454feb92009-12-08 09:21:05 +00006610TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006611 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006612 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6613 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006614 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006615
Douglas Gregorb98b1992009-08-11 05:31:07 +00006616 if (!getDerived().AlwaysRebuild() &&
6617 SubStmt.get() == E->getSubStmt())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006618 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006619
6620 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006621 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006622 E->getRParenLoc());
6623}
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>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006628 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006630 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006631
John McCall60d7b3a2010-08-24 06:29:42 +00006632 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006633 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006634 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006635
John McCall60d7b3a2010-08-24 06:29:42 +00006636 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006638 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006639
Douglas Gregorb98b1992009-08-11 05:31:07 +00006640 if (!getDerived().AlwaysRebuild() &&
6641 Cond.get() == E->getCond() &&
6642 LHS.get() == E->getLHS() &&
6643 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006644 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006645
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006647 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006648 E->getRParenLoc());
6649}
Mike Stump1eb44332009-09-09 15:08:12 +00006650
Douglas Gregorb98b1992009-08-11 05:31:07 +00006651template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006652ExprResult
John McCall454feb92009-12-08 09:21:05 +00006653TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006654 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655}
6656
6657template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006658ExprResult
John McCall454feb92009-12-08 09:21:05 +00006659TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006660 switch (E->getOperator()) {
6661 case OO_New:
6662 case OO_Delete:
6663 case OO_Array_New:
6664 case OO_Array_Delete:
6665 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006666 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006667
Douglas Gregor668d6d92009-12-13 20:44:55 +00006668 case OO_Call: {
6669 // This is a call to an object's operator().
6670 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6671
6672 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006673 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006674 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006675 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006676
6677 // FIXME: Poor location information
6678 SourceLocation FakeLParenLoc
6679 = SemaRef.PP.getLocForEndOfToken(
6680 static_cast<Expr *>(Object.get())->getLocEnd());
6681
6682 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006683 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006684 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6685 Args))
6686 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006687
John McCall9ae2f072010-08-23 23:25:46 +00006688 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006689 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006690 E->getLocEnd());
6691 }
6692
6693#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6694 case OO_##Name:
6695#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6696#include "clang/Basic/OperatorKinds.def"
6697 case OO_Subscript:
6698 // Handled below.
6699 break;
6700
6701 case OO_Conditional:
6702 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006703 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006704
6705 case OO_None:
6706 case NUM_OVERLOADED_OPERATORS:
6707 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006708 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006709 }
6710
John McCall60d7b3a2010-08-24 06:29:42 +00006711 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006713 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006714
John McCall60d7b3a2010-08-24 06:29:42 +00006715 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006716 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006717 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718
John McCall60d7b3a2010-08-24 06:29:42 +00006719 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006720 if (E->getNumArgs() == 2) {
6721 Second = getDerived().TransformExpr(E->getArg(1));
6722 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006723 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006724 }
Mike Stump1eb44332009-09-09 15:08:12 +00006725
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726 if (!getDerived().AlwaysRebuild() &&
6727 Callee.get() == E->getCallee() &&
6728 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006729 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006730 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006731
Douglas Gregorb98b1992009-08-11 05:31:07 +00006732 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6733 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006734 Callee.get(),
6735 First.get(),
6736 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737}
Mike Stump1eb44332009-09-09 15:08:12 +00006738
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006740ExprResult
John McCall454feb92009-12-08 09:21:05 +00006741TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6742 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006743}
Mike Stump1eb44332009-09-09 15:08:12 +00006744
Douglas Gregorb98b1992009-08-11 05:31:07 +00006745template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006746ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006747TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6748 // Transform the callee.
6749 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6750 if (Callee.isInvalid())
6751 return ExprError();
6752
6753 // Transform exec config.
6754 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6755 if (EC.isInvalid())
6756 return ExprError();
6757
6758 // Transform arguments.
6759 bool ArgChanged = false;
6760 ASTOwningVector<Expr*> Args(SemaRef);
6761 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6762 &ArgChanged))
6763 return ExprError();
6764
6765 if (!getDerived().AlwaysRebuild() &&
6766 Callee.get() == E->getCallee() &&
6767 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006768 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006769
6770 // FIXME: Wrong source location information for the '('.
6771 SourceLocation FakeLParenLoc
6772 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6773 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6774 move_arg(Args),
6775 E->getRParenLoc(), EC.get());
6776}
6777
6778template<typename Derived>
6779ExprResult
John McCall454feb92009-12-08 09:21:05 +00006780TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006781 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6782 if (!Type)
6783 return ExprError();
6784
John McCall60d7b3a2010-08-24 06:29:42 +00006785 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006786 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006787 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006788 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006789
Douglas Gregorb98b1992009-08-11 05:31:07 +00006790 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006791 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006792 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006793 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006794
Douglas Gregorb98b1992009-08-11 05:31:07 +00006795 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006796 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006797 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6798 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6799 SourceLocation FakeRParenLoc
6800 = SemaRef.PP.getLocForEndOfToken(
6801 E->getSubExpr()->getSourceRange().getEnd());
6802 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006803 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006804 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006805 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006806 FakeRAngleLoc,
6807 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006808 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006809 FakeRParenLoc);
6810}
Mike Stump1eb44332009-09-09 15:08:12 +00006811
Douglas Gregorb98b1992009-08-11 05:31:07 +00006812template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006813ExprResult
John McCall454feb92009-12-08 09:21:05 +00006814TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6815 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006816}
Mike Stump1eb44332009-09-09 15:08:12 +00006817
6818template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006819ExprResult
John McCall454feb92009-12-08 09:21:05 +00006820TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6821 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006822}
6823
Douglas Gregorb98b1992009-08-11 05:31:07 +00006824template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006825ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006826TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006827 CXXReinterpretCastExpr *E) {
6828 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006829}
Mike Stump1eb44332009-09-09 15:08:12 +00006830
Douglas Gregorb98b1992009-08-11 05:31:07 +00006831template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006832ExprResult
John McCall454feb92009-12-08 09:21:05 +00006833TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6834 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006835}
Mike Stump1eb44332009-09-09 15:08:12 +00006836
Douglas Gregorb98b1992009-08-11 05:31:07 +00006837template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006838ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006839TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006840 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006841 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6842 if (!Type)
6843 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006844
John McCall60d7b3a2010-08-24 06:29:42 +00006845 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006846 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006847 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006848 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006849
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006851 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006852 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006853 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006854
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006855 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006856 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006857 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006858 E->getRParenLoc());
6859}
Mike Stump1eb44332009-09-09 15:08:12 +00006860
Douglas Gregorb98b1992009-08-11 05:31:07 +00006861template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006862ExprResult
John McCall454feb92009-12-08 09:21:05 +00006863TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006864 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006865 TypeSourceInfo *TInfo
6866 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6867 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006868 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006869
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006871 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006872 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006873
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006874 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6875 E->getLocStart(),
6876 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006877 E->getLocEnd());
6878 }
Mike Stump1eb44332009-09-09 15:08:12 +00006879
Douglas Gregorb98b1992009-08-11 05:31:07 +00006880 // We don't know whether the expression is potentially evaluated until
6881 // after we perform semantic analysis, so the expression is potentially
6882 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006883 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006884 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006885
John McCall60d7b3a2010-08-24 06:29:42 +00006886 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006887 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006888 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006889
Douglas Gregorb98b1992009-08-11 05:31:07 +00006890 if (!getDerived().AlwaysRebuild() &&
6891 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006892 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006893
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006894 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6895 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006896 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006897 E->getLocEnd());
6898}
6899
6900template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006901ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006902TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6903 if (E->isTypeOperand()) {
6904 TypeSourceInfo *TInfo
6905 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6906 if (!TInfo)
6907 return ExprError();
6908
6909 if (!getDerived().AlwaysRebuild() &&
6910 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006911 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006912
Douglas Gregor3c52a212011-03-06 17:40:41 +00006913 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006914 E->getLocStart(),
6915 TInfo,
6916 E->getLocEnd());
6917 }
6918
Francois Pichet01b7c302010-09-08 12:20:18 +00006919 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6920
6921 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6922 if (SubExpr.isInvalid())
6923 return ExprError();
6924
6925 if (!getDerived().AlwaysRebuild() &&
6926 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006927 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006928
6929 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6930 E->getLocStart(),
6931 SubExpr.get(),
6932 E->getLocEnd());
6933}
6934
6935template<typename Derived>
6936ExprResult
John McCall454feb92009-12-08 09:21:05 +00006937TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006938 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006939}
Mike Stump1eb44332009-09-09 15:08:12 +00006940
Douglas Gregorb98b1992009-08-11 05:31:07 +00006941template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006942ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006943TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006944 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006945 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006946}
Mike Stump1eb44332009-09-09 15:08:12 +00006947
Douglas Gregorb98b1992009-08-11 05:31:07 +00006948template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006949ExprResult
John McCall454feb92009-12-08 09:21:05 +00006950TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006951 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00006952 QualType T;
6953 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6954 T = MD->getThisType(getSema().Context);
6955 else
6956 T = getSema().Context.getPointerType(
6957 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00006958
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006959 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006960 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006961
Douglas Gregor828a1972010-01-07 23:12:05 +00006962 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006963}
Mike Stump1eb44332009-09-09 15:08:12 +00006964
Douglas Gregorb98b1992009-08-11 05:31:07 +00006965template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006966ExprResult
John McCall454feb92009-12-08 09:21:05 +00006967TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006968 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006969 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006970 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006971
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972 if (!getDerived().AlwaysRebuild() &&
6973 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006974 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006975
Douglas Gregorbca01b42011-07-06 22:04:06 +00006976 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6977 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006978}
Mike Stump1eb44332009-09-09 15:08:12 +00006979
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006981ExprResult
John McCall454feb92009-12-08 09:21:05 +00006982TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006983 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006984 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6985 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006986 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006987 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006988
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006989 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006990 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006991 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006992
Douglas Gregor036aed12009-12-23 23:03:06 +00006993 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006994}
Mike Stump1eb44332009-09-09 15:08:12 +00006995
Douglas Gregorb98b1992009-08-11 05:31:07 +00006996template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006997ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006998TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6999 CXXScalarValueInitExpr *E) {
7000 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7001 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007002 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007003
Douglas Gregorb98b1992009-08-11 05:31:07 +00007004 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007005 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007006 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007007
Douglas Gregorab6677e2010-09-08 00:15:04 +00007008 return getDerived().RebuildCXXScalarValueInitExpr(T,
7009 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007010 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007011}
Mike Stump1eb44332009-09-09 15:08:12 +00007012
Douglas Gregorb98b1992009-08-11 05:31:07 +00007013template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007014ExprResult
John McCall454feb92009-12-08 09:21:05 +00007015TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007016 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007017 TypeSourceInfo *AllocTypeInfo
7018 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7019 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007020 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007021
Douglas Gregorb98b1992009-08-11 05:31:07 +00007022 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007023 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007025 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007026
Douglas Gregorb98b1992009-08-11 05:31:07 +00007027 // Transform the placement arguments (if any).
7028 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007029 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007030 if (getDerived().TransformExprs(E->getPlacementArgs(),
7031 E->getNumPlacementArgs(), true,
7032 PlacementArgs, &ArgumentChanged))
7033 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007034
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007035 // Transform the constructor arguments (if any).
7036 // As an annoying corner case, we may have introduced an implicit value-
7037 // initialization expression when allocating a new array, which we implicitly
7038 // drop. It will be re-created during type checking.
John McCallca0408f2010-08-23 06:44:23 +00007039 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007040 if (!(E->isArray() && E->getNumConstructorArgs() == 1 &&
7041 isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) &&
7042 TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007043 ConstructorArgs, &ArgumentChanged))
7044 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007045
Douglas Gregor1af74512010-02-26 00:38:10 +00007046 // Transform constructor, new operator, and delete operator.
7047 CXXConstructorDecl *Constructor = 0;
7048 if (E->getConstructor()) {
7049 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007050 getDerived().TransformDecl(E->getLocStart(),
7051 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007052 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007053 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007054 }
7055
7056 FunctionDecl *OperatorNew = 0;
7057 if (E->getOperatorNew()) {
7058 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007059 getDerived().TransformDecl(E->getLocStart(),
7060 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007061 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007062 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007063 }
7064
7065 FunctionDecl *OperatorDelete = 0;
7066 if (E->getOperatorDelete()) {
7067 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007068 getDerived().TransformDecl(E->getLocStart(),
7069 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007070 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007071 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007072 }
Sean Huntc3021132010-05-05 15:23:54 +00007073
Douglas Gregorb98b1992009-08-11 05:31:07 +00007074 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007075 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007076 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007077 Constructor == E->getConstructor() &&
7078 OperatorNew == E->getOperatorNew() &&
7079 OperatorDelete == E->getOperatorDelete() &&
7080 !ArgumentChanged) {
7081 // Mark any declarations we need as referenced.
7082 // FIXME: instantiation-specific.
7083 if (Constructor)
7084 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
7085 if (OperatorNew)
7086 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
7087 if (OperatorDelete)
7088 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007089
7090 if (E->isArray() && Constructor &&
7091 !E->getAllocatedType()->isDependentType()) {
7092 QualType ElementType
7093 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7094 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7095 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7096 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
7097 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
7098 }
7099 }
7100 }
7101
John McCall3fa5cae2010-10-26 07:05:15 +00007102 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007103 }
Mike Stump1eb44332009-09-09 15:08:12 +00007104
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007105 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007106 if (!ArraySize.get()) {
7107 // If no array size was specified, but the new expression was
7108 // instantiated with an array type (e.g., "new T" where T is
7109 // instantiated with "int[4]"), extract the outer bound from the
7110 // array type as our array size. We do this with constant and
7111 // dependently-sized array types.
7112 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7113 if (!ArrayT) {
7114 // Do nothing
7115 } else if (const ConstantArrayType *ConsArrayT
7116 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007117 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007118 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7119 ConsArrayT->getSize(),
7120 SemaRef.Context.getSizeType(),
7121 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007122 AllocType = ConsArrayT->getElementType();
7123 } else if (const DependentSizedArrayType *DepArrayT
7124 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7125 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007126 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007127 AllocType = DepArrayT->getElementType();
7128 }
7129 }
7130 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007131
Douglas Gregorb98b1992009-08-11 05:31:07 +00007132 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7133 E->isGlobalNew(),
7134 /*FIXME:*/E->getLocStart(),
7135 move_arg(PlacementArgs),
7136 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007137 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007138 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007139 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007140 ArraySize.get(),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007141 E->getConstructorLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007142 move_arg(ConstructorArgs),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007143 E->getConstructorRParen());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007144}
Mike Stump1eb44332009-09-09 15:08:12 +00007145
Douglas Gregorb98b1992009-08-11 05:31:07 +00007146template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007147ExprResult
John McCall454feb92009-12-08 09:21:05 +00007148TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007149 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007150 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007151 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007152
Douglas Gregor1af74512010-02-26 00:38:10 +00007153 // Transform the delete operator, if known.
7154 FunctionDecl *OperatorDelete = 0;
7155 if (E->getOperatorDelete()) {
7156 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007157 getDerived().TransformDecl(E->getLocStart(),
7158 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007159 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007160 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007161 }
Sean Huntc3021132010-05-05 15:23:54 +00007162
Douglas Gregorb98b1992009-08-11 05:31:07 +00007163 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007164 Operand.get() == E->getArgument() &&
7165 OperatorDelete == E->getOperatorDelete()) {
7166 // Mark any declarations we need as referenced.
7167 // FIXME: instantiation-specific.
7168 if (OperatorDelete)
7169 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007170
7171 if (!E->getArgument()->isTypeDependent()) {
7172 QualType Destroyed = SemaRef.Context.getBaseElementType(
7173 E->getDestroyedType());
7174 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7175 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7176 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
7177 SemaRef.LookupDestructor(Record));
7178 }
7179 }
7180
John McCall3fa5cae2010-10-26 07:05:15 +00007181 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007182 }
Mike Stump1eb44332009-09-09 15:08:12 +00007183
Douglas Gregorb98b1992009-08-11 05:31:07 +00007184 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7185 E->isGlobalDelete(),
7186 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007187 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007188}
Mike Stump1eb44332009-09-09 15:08:12 +00007189
Douglas Gregorb98b1992009-08-11 05:31:07 +00007190template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007191ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007192TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007193 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007194 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007195 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007196 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007197
John McCallb3d87482010-08-24 05:47:05 +00007198 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007199 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007200 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007201 E->getOperatorLoc(),
7202 E->isArrow()? tok::arrow : tok::period,
7203 ObjectTypePtr,
7204 MayBePseudoDestructor);
7205 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007206 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007207
John McCallb3d87482010-08-24 05:47:05 +00007208 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007209 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7210 if (QualifierLoc) {
7211 QualifierLoc
7212 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7213 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007214 return ExprError();
7215 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007216 CXXScopeSpec SS;
7217 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007218
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007219 PseudoDestructorTypeStorage Destroyed;
7220 if (E->getDestroyedTypeInfo()) {
7221 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007222 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007223 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007224 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007225 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007226 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007227 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007228 // We aren't likely to be able to resolve the identifier down to a type
7229 // now anyway, so just retain the identifier.
7230 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7231 E->getDestroyedTypeLoc());
7232 } else {
7233 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007234 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007235 *E->getDestroyedTypeIdentifier(),
7236 E->getDestroyedTypeLoc(),
7237 /*Scope=*/0,
7238 SS, ObjectTypePtr,
7239 false);
7240 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007241 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007242
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007243 Destroyed
7244 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7245 E->getDestroyedTypeLoc());
7246 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007247
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007248 TypeSourceInfo *ScopeTypeInfo = 0;
7249 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007250 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007251 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007252 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007253 }
Sean Huntc3021132010-05-05 15:23:54 +00007254
John McCall9ae2f072010-08-23 23:25:46 +00007255 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007256 E->getOperatorLoc(),
7257 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007258 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007259 ScopeTypeInfo,
7260 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007261 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007262 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007263}
Mike Stump1eb44332009-09-09 15:08:12 +00007264
Douglas Gregora71d8192009-09-04 17:36:40 +00007265template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007266ExprResult
John McCallba135432009-11-21 08:51:07 +00007267TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007268 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007269 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7270 Sema::LookupOrdinaryName);
7271
7272 // Transform all the decls.
7273 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7274 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007275 NamedDecl *InstD = static_cast<NamedDecl*>(
7276 getDerived().TransformDecl(Old->getNameLoc(),
7277 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007278 if (!InstD) {
7279 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7280 // This can happen because of dependent hiding.
7281 if (isa<UsingShadowDecl>(*I))
7282 continue;
7283 else
John McCallf312b1e2010-08-26 23:41:50 +00007284 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007285 }
John McCallf7a1a742009-11-24 19:00:30 +00007286
7287 // Expand using declarations.
7288 if (isa<UsingDecl>(InstD)) {
7289 UsingDecl *UD = cast<UsingDecl>(InstD);
7290 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7291 E = UD->shadow_end(); I != E; ++I)
7292 R.addDecl(*I);
7293 continue;
7294 }
7295
7296 R.addDecl(InstD);
7297 }
7298
7299 // Resolve a kind, but don't do any further analysis. If it's
7300 // ambiguous, the callee needs to deal with it.
7301 R.resolveKind();
7302
7303 // Rebuild the nested-name qualifier, if present.
7304 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007305 if (Old->getQualifierLoc()) {
7306 NestedNameSpecifierLoc QualifierLoc
7307 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7308 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007309 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007310
Douglas Gregor4c9be892011-02-28 20:01:57 +00007311 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007312 }
7313
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007314 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007315 CXXRecordDecl *NamingClass
7316 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7317 Old->getNameLoc(),
7318 Old->getNamingClass()));
7319 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007320 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007321
Douglas Gregor66c45152010-04-27 16:10:10 +00007322 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007323 }
7324
7325 // If we have no template arguments, it's a normal declaration name.
7326 if (!Old->hasExplicitTemplateArgs())
7327 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7328
7329 // If we have template arguments, rebuild them, then rebuild the
7330 // templateid expression.
7331 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007332 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7333 Old->getNumTemplateArgs(),
7334 TransArgs))
7335 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007336
7337 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7338 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007339}
Mike Stump1eb44332009-09-09 15:08:12 +00007340
Douglas Gregorb98b1992009-08-11 05:31:07 +00007341template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007342ExprResult
John McCall454feb92009-12-08 09:21:05 +00007343TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007344 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7345 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007346 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007347
Douglas Gregorb98b1992009-08-11 05:31:07 +00007348 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007349 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007350 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007351
Mike Stump1eb44332009-09-09 15:08:12 +00007352 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007353 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007354 T,
7355 E->getLocEnd());
7356}
Mike Stump1eb44332009-09-09 15:08:12 +00007357
Douglas Gregorb98b1992009-08-11 05:31:07 +00007358template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007359ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007360TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7361 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7362 if (!LhsT)
7363 return ExprError();
7364
7365 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7366 if (!RhsT)
7367 return ExprError();
7368
7369 if (!getDerived().AlwaysRebuild() &&
7370 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7371 return SemaRef.Owned(E);
7372
7373 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7374 E->getLocStart(),
7375 LhsT, RhsT,
7376 E->getLocEnd());
7377}
7378
7379template<typename Derived>
7380ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007381TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7382 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7383 if (!T)
7384 return ExprError();
7385
7386 if (!getDerived().AlwaysRebuild() &&
7387 T == E->getQueriedTypeSourceInfo())
7388 return SemaRef.Owned(E);
7389
7390 ExprResult SubExpr;
7391 {
7392 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7393 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7394 if (SubExpr.isInvalid())
7395 return ExprError();
7396
7397 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7398 return SemaRef.Owned(E);
7399 }
7400
7401 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7402 E->getLocStart(),
7403 T,
7404 SubExpr.get(),
7405 E->getLocEnd());
7406}
7407
7408template<typename Derived>
7409ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007410TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7411 ExprResult SubExpr;
7412 {
7413 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7414 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7415 if (SubExpr.isInvalid())
7416 return ExprError();
7417
7418 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7419 return SemaRef.Owned(E);
7420 }
7421
7422 return getDerived().RebuildExpressionTrait(
7423 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7424}
7425
7426template<typename Derived>
7427ExprResult
John McCall865d4472009-11-19 22:55:06 +00007428TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007429 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007430 NestedNameSpecifierLoc QualifierLoc
7431 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7432 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007433 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007434
John McCall43fed0d2010-11-12 08:19:04 +00007435 // TODO: If this is a conversion-function-id, verify that the
7436 // destination type name (if present) resolves the same way after
7437 // instantiation as it did in the local scope.
7438
Abramo Bagnara25777432010-08-11 22:01:17 +00007439 DeclarationNameInfo NameInfo
7440 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7441 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007442 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007443
John McCallf7a1a742009-11-24 19:00:30 +00007444 if (!E->hasExplicitTemplateArgs()) {
7445 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007446 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007447 // Note: it is sufficient to compare the Name component of NameInfo:
7448 // if name has not changed, DNLoc has not changed either.
7449 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007450 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007451
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007452 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007453 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007454 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007455 }
John McCalld5532b62009-11-23 01:53:49 +00007456
7457 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007458 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7459 E->getNumTemplateArgs(),
7460 TransArgs))
7461 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007462
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007463 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007464 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007465 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007466}
7467
7468template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007469ExprResult
John McCall454feb92009-12-08 09:21:05 +00007470TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007471 // CXXConstructExprs are always implicit, so when we have a
7472 // 1-argument construction we just transform that argument.
7473 if (E->getNumArgs() == 1 ||
7474 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7475 return getDerived().TransformExpr(E->getArg(0));
7476
Douglas Gregorb98b1992009-08-11 05:31:07 +00007477 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7478
7479 QualType T = getDerived().TransformType(E->getType());
7480 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007481 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007482
7483 CXXConstructorDecl *Constructor
7484 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007485 getDerived().TransformDecl(E->getLocStart(),
7486 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007487 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007488 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007489
Douglas Gregorb98b1992009-08-11 05:31:07 +00007490 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007491 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007492 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7493 &ArgumentChanged))
7494 return ExprError();
7495
Douglas Gregorb98b1992009-08-11 05:31:07 +00007496 if (!getDerived().AlwaysRebuild() &&
7497 T == E->getType() &&
7498 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007499 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007500 // Mark the constructor as referenced.
7501 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00007502 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007503 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007504 }
Mike Stump1eb44332009-09-09 15:08:12 +00007505
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007506 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7507 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007508 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007509 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007510 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007511 E->getConstructionKind(),
7512 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007513}
Mike Stump1eb44332009-09-09 15:08:12 +00007514
Douglas Gregorb98b1992009-08-11 05:31:07 +00007515/// \brief Transform a C++ temporary-binding expression.
7516///
Douglas Gregor51326552009-12-24 18:51:59 +00007517/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7518/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007519template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007520ExprResult
John McCall454feb92009-12-08 09:21:05 +00007521TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007522 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007523}
Mike Stump1eb44332009-09-09 15:08:12 +00007524
John McCall4765fa02010-12-06 08:20:24 +00007525/// \brief Transform a C++ expression that contains cleanups that should
7526/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007527///
John McCall4765fa02010-12-06 08:20:24 +00007528/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007529/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007530template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007531ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007532TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007533 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007534}
Mike Stump1eb44332009-09-09 15:08:12 +00007535
Douglas Gregorb98b1992009-08-11 05:31:07 +00007536template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007537ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007538TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007539 CXXTemporaryObjectExpr *E) {
7540 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7541 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007542 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007543
Douglas Gregorb98b1992009-08-11 05:31:07 +00007544 CXXConstructorDecl *Constructor
7545 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007546 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007547 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007548 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007549 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007550
Douglas Gregorb98b1992009-08-11 05:31:07 +00007551 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007552 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007553 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007554 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7555 &ArgumentChanged))
7556 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007557
Douglas Gregorb98b1992009-08-11 05:31:07 +00007558 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007559 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007560 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007561 !ArgumentChanged) {
7562 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00007563 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007564 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007565 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007566
7567 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7568 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007569 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007570 E->getLocEnd());
7571}
Mike Stump1eb44332009-09-09 15:08:12 +00007572
Douglas Gregorb98b1992009-08-11 05:31:07 +00007573template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007574ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007575TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007576 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007577 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7578 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007579 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007580
Douglas Gregorb98b1992009-08-11 05:31:07 +00007581 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007582 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007583 Args.reserve(E->arg_size());
7584 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7585 &ArgumentChanged))
7586 return ExprError();
7587
Douglas Gregorb98b1992009-08-11 05:31:07 +00007588 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007589 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007590 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007591 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007592
Douglas Gregorb98b1992009-08-11 05:31:07 +00007593 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007594 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007595 E->getLParenLoc(),
7596 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007597 E->getRParenLoc());
7598}
Mike Stump1eb44332009-09-09 15:08:12 +00007599
Douglas Gregorb98b1992009-08-11 05:31:07 +00007600template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007601ExprResult
John McCall865d4472009-11-19 22:55:06 +00007602TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007603 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007604 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007605 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007606 Expr *OldBase;
7607 QualType BaseType;
7608 QualType ObjectType;
7609 if (!E->isImplicitAccess()) {
7610 OldBase = E->getBase();
7611 Base = getDerived().TransformExpr(OldBase);
7612 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007613 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007614
John McCallaa81e162009-12-01 22:10:20 +00007615 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007616 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007617 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007618 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007619 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007620 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007621 ObjectTy,
7622 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007623 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007624 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007625
John McCallb3d87482010-08-24 05:47:05 +00007626 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007627 BaseType = ((Expr*) Base.get())->getType();
7628 } else {
7629 OldBase = 0;
7630 BaseType = getDerived().TransformType(E->getBaseType());
7631 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7632 }
Mike Stump1eb44332009-09-09 15:08:12 +00007633
Douglas Gregor6cd21982009-10-20 05:58:46 +00007634 // Transform the first part of the nested-name-specifier that qualifies
7635 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007636 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007637 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007638 E->getFirstQualifierFoundInScope(),
7639 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007640
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007641 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007642 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007643 QualifierLoc
7644 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7645 ObjectType,
7646 FirstQualifierInScope);
7647 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007648 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007649 }
Mike Stump1eb44332009-09-09 15:08:12 +00007650
John McCall43fed0d2010-11-12 08:19:04 +00007651 // TODO: If this is a conversion-function-id, verify that the
7652 // destination type name (if present) resolves the same way after
7653 // instantiation as it did in the local scope.
7654
Abramo Bagnara25777432010-08-11 22:01:17 +00007655 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007656 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007657 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007658 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007659
John McCallaa81e162009-12-01 22:10:20 +00007660 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007661 // This is a reference to a member without an explicitly-specified
7662 // template argument list. Optimize for this common case.
7663 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007664 Base.get() == OldBase &&
7665 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007666 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007667 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007668 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007669 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007670
John McCall9ae2f072010-08-23 23:25:46 +00007671 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007672 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007673 E->isArrow(),
7674 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007675 QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00007676 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007677 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007678 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007679 }
7680
John McCalld5532b62009-11-23 01:53:49 +00007681 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007682 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7683 E->getNumTemplateArgs(),
7684 TransArgs))
7685 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007686
John McCall9ae2f072010-08-23 23:25:46 +00007687 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007688 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007689 E->isArrow(),
7690 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007691 QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007692 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007693 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007694 &TransArgs);
7695}
7696
7697template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007698ExprResult
John McCall454feb92009-12-08 09:21:05 +00007699TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007700 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007701 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007702 QualType BaseType;
7703 if (!Old->isImplicitAccess()) {
7704 Base = getDerived().TransformExpr(Old->getBase());
7705 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007706 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00007707 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
7708 Old->isArrow());
7709 if (Base.isInvalid())
7710 return ExprError();
7711 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00007712 } else {
7713 BaseType = getDerived().TransformType(Old->getBaseType());
7714 }
John McCall129e2df2009-11-30 22:42:35 +00007715
Douglas Gregor4c9be892011-02-28 20:01:57 +00007716 NestedNameSpecifierLoc QualifierLoc;
7717 if (Old->getQualifierLoc()) {
7718 QualifierLoc
7719 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7720 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007721 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007722 }
7723
Abramo Bagnara25777432010-08-11 22:01:17 +00007724 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007725 Sema::LookupOrdinaryName);
7726
7727 // Transform all the decls.
7728 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7729 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007730 NamedDecl *InstD = static_cast<NamedDecl*>(
7731 getDerived().TransformDecl(Old->getMemberLoc(),
7732 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007733 if (!InstD) {
7734 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7735 // This can happen because of dependent hiding.
7736 if (isa<UsingShadowDecl>(*I))
7737 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007738 else {
7739 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007740 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007741 }
John McCall9f54ad42009-12-10 09:41:52 +00007742 }
John McCall129e2df2009-11-30 22:42:35 +00007743
7744 // Expand using declarations.
7745 if (isa<UsingDecl>(InstD)) {
7746 UsingDecl *UD = cast<UsingDecl>(InstD);
7747 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7748 E = UD->shadow_end(); I != E; ++I)
7749 R.addDecl(*I);
7750 continue;
7751 }
7752
7753 R.addDecl(InstD);
7754 }
7755
7756 R.resolveKind();
7757
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007758 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007759 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007760 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007761 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007762 Old->getMemberLoc(),
7763 Old->getNamingClass()));
7764 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007765 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007766
Douglas Gregor66c45152010-04-27 16:10:10 +00007767 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007768 }
Sean Huntc3021132010-05-05 15:23:54 +00007769
John McCall129e2df2009-11-30 22:42:35 +00007770 TemplateArgumentListInfo TransArgs;
7771 if (Old->hasExplicitTemplateArgs()) {
7772 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7773 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007774 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7775 Old->getNumTemplateArgs(),
7776 TransArgs))
7777 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007778 }
John McCallc2233c52010-01-15 08:34:02 +00007779
7780 // FIXME: to do this check properly, we will need to preserve the
7781 // first-qualifier-in-scope here, just in case we had a dependent
7782 // base (and therefore couldn't do the check) and a
7783 // nested-name-qualifier (and therefore could do the lookup).
7784 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007785
John McCall9ae2f072010-08-23 23:25:46 +00007786 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007787 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007788 Old->getOperatorLoc(),
7789 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007790 QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00007791 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007792 R,
7793 (Old->hasExplicitTemplateArgs()
7794 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007795}
7796
7797template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007798ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007799TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00007800 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00007801 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7802 if (SubExpr.isInvalid())
7803 return ExprError();
7804
7805 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007806 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007807
7808 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7809}
7810
7811template<typename Derived>
7812ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007813TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007814 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7815 if (Pattern.isInvalid())
7816 return ExprError();
7817
7818 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7819 return SemaRef.Owned(E);
7820
Douglas Gregor67fd1252011-01-14 21:20:45 +00007821 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7822 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007823}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007824
7825template<typename Derived>
7826ExprResult
7827TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7828 // If E is not value-dependent, then nothing will change when we transform it.
7829 // Note: This is an instantiation-centric view.
7830 if (!E->isValueDependent())
7831 return SemaRef.Owned(E);
7832
7833 // Note: None of the implementations of TryExpandParameterPacks can ever
7834 // produce a diagnostic when given only a single unexpanded parameter pack,
7835 // so
7836 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7837 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007838 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007839 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007840 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00007841 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00007842 ShouldExpand, RetainExpansion,
7843 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007844 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007845
Douglas Gregor089e8932011-10-10 18:59:29 +00007846 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007847 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00007848
7849 NamedDecl *Pack = E->getPack();
7850 if (!ShouldExpand) {
7851 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
7852 Pack));
7853 if (!Pack)
7854 return ExprError();
7855 }
7856
Douglas Gregoree8aff02011-01-04 17:33:58 +00007857
7858 // We now know the length of the parameter pack, so build a new expression
7859 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00007860 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00007861 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00007862 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007863}
7864
Douglas Gregorbe230c32011-01-03 17:17:50 +00007865template<typename Derived>
7866ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007867TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7868 SubstNonTypeTemplateParmPackExpr *E) {
7869 // Default behavior is to do nothing with this transformation.
7870 return SemaRef.Owned(E);
7871}
7872
7873template<typename Derived>
7874ExprResult
John McCall91a57552011-07-15 05:09:51 +00007875TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7876 SubstNonTypeTemplateParmExpr *E) {
7877 // Default behavior is to do nothing with this transformation.
7878 return SemaRef.Owned(E);
7879}
7880
7881template<typename Derived>
7882ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00007883TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7884 MaterializeTemporaryExpr *E) {
7885 return getDerived().TransformExpr(E->GetTemporaryExpr());
7886}
7887
7888template<typename Derived>
7889ExprResult
John McCall454feb92009-12-08 09:21:05 +00007890TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007891 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007892}
7893
Mike Stump1eb44332009-09-09 15:08:12 +00007894template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007895ExprResult
John McCall454feb92009-12-08 09:21:05 +00007896TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007897 TypeSourceInfo *EncodedTypeInfo
7898 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7899 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007900 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007901
Douglas Gregorb98b1992009-08-11 05:31:07 +00007902 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007903 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007904 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007905
7906 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007907 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007908 E->getRParenLoc());
7909}
Mike Stump1eb44332009-09-09 15:08:12 +00007910
Douglas Gregorb98b1992009-08-11 05:31:07 +00007911template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00007912ExprResult TreeTransform<Derived>::
7913TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7914 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7915 if (result.isInvalid()) return ExprError();
7916 Expr *subExpr = result.take();
7917
7918 if (!getDerived().AlwaysRebuild() &&
7919 subExpr == E->getSubExpr())
7920 return SemaRef.Owned(E);
7921
7922 return SemaRef.Owned(new(SemaRef.Context)
7923 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7924}
7925
7926template<typename Derived>
7927ExprResult TreeTransform<Derived>::
7928TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7929 TypeSourceInfo *TSInfo
7930 = getDerived().TransformType(E->getTypeInfoAsWritten());
7931 if (!TSInfo)
7932 return ExprError();
7933
7934 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7935 if (Result.isInvalid())
7936 return ExprError();
7937
7938 if (!getDerived().AlwaysRebuild() &&
7939 TSInfo == E->getTypeInfoAsWritten() &&
7940 Result.get() == E->getSubExpr())
7941 return SemaRef.Owned(E);
7942
7943 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7944 E->getBridgeKeywordLoc(), TSInfo,
7945 Result.get());
7946}
7947
7948template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007949ExprResult
John McCall454feb92009-12-08 09:21:05 +00007950TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007951 // Transform arguments.
7952 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007953 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007954 Args.reserve(E->getNumArgs());
7955 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7956 &ArgChanged))
7957 return ExprError();
7958
Douglas Gregor92e986e2010-04-22 16:44:27 +00007959 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7960 // Class message: transform the receiver type.
7961 TypeSourceInfo *ReceiverTypeInfo
7962 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7963 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007964 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007965
Douglas Gregor92e986e2010-04-22 16:44:27 +00007966 // If nothing changed, just retain the existing message send.
7967 if (!getDerived().AlwaysRebuild() &&
7968 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007969 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007970
7971 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007972 SmallVector<SourceLocation, 16> SelLocs;
7973 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007974 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7975 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007976 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00007977 E->getMethodDecl(),
7978 E->getLeftLoc(),
7979 move_arg(Args),
7980 E->getRightLoc());
7981 }
7982
7983 // Instance message: transform the receiver
7984 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7985 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007986 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007987 = getDerived().TransformExpr(E->getInstanceReceiver());
7988 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007989 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007990
7991 // If nothing changed, just retain the existing message send.
7992 if (!getDerived().AlwaysRebuild() &&
7993 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00007994 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00007995
Douglas Gregor92e986e2010-04-22 16:44:27 +00007996 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007997 SmallVector<SourceLocation, 16> SelLocs;
7998 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00007999 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008000 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008001 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008002 E->getMethodDecl(),
8003 E->getLeftLoc(),
8004 move_arg(Args),
8005 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008006}
8007
Mike Stump1eb44332009-09-09 15:08:12 +00008008template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008009ExprResult
John McCall454feb92009-12-08 09:21:05 +00008010TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008011 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008012}
8013
Mike Stump1eb44332009-09-09 15:08:12 +00008014template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008015ExprResult
John McCall454feb92009-12-08 09:21:05 +00008016TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008017 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008018}
8019
Mike Stump1eb44332009-09-09 15:08:12 +00008020template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008021ExprResult
John McCall454feb92009-12-08 09:21:05 +00008022TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008023 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008024 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008025 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008026 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008027
8028 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008029
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008030 // If nothing changed, just retain the existing expression.
8031 if (!getDerived().AlwaysRebuild() &&
8032 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008033 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008034
John McCall9ae2f072010-08-23 23:25:46 +00008035 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008036 E->getLocation(),
8037 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008038}
8039
Mike Stump1eb44332009-09-09 15:08:12 +00008040template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008041ExprResult
John McCall454feb92009-12-08 09:21:05 +00008042TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008043 // 'super' and types never change. Property never changes. Just
8044 // retain the existing expression.
8045 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008046 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008047
Douglas Gregore3303542010-04-26 20:47:02 +00008048 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008049 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008050 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008051 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008052
Douglas Gregore3303542010-04-26 20:47:02 +00008053 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008054
Douglas Gregore3303542010-04-26 20:47:02 +00008055 // If nothing changed, just retain the existing expression.
8056 if (!getDerived().AlwaysRebuild() &&
8057 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008058 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008059
John McCall12f78a62010-12-02 01:19:52 +00008060 if (E->isExplicitProperty())
8061 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8062 E->getExplicitProperty(),
8063 E->getLocation());
8064
8065 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008066 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008067 E->getImplicitPropertyGetter(),
8068 E->getImplicitPropertySetter(),
8069 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008070}
8071
Mike Stump1eb44332009-09-09 15:08:12 +00008072template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008073ExprResult
John McCall454feb92009-12-08 09:21:05 +00008074TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008075 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008076 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008077 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008078 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008079
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008080 // If nothing changed, just retain the existing expression.
8081 if (!getDerived().AlwaysRebuild() &&
8082 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008083 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008084
John McCall9ae2f072010-08-23 23:25:46 +00008085 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008086 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008087}
8088
Mike Stump1eb44332009-09-09 15:08:12 +00008089template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008090ExprResult
John McCall454feb92009-12-08 09:21:05 +00008091TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008092 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008093 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008094 SubExprs.reserve(E->getNumSubExprs());
8095 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8096 SubExprs, &ArgumentChanged))
8097 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008098
Douglas Gregorb98b1992009-08-11 05:31:07 +00008099 if (!getDerived().AlwaysRebuild() &&
8100 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008101 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008102
Douglas Gregorb98b1992009-08-11 05:31:07 +00008103 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8104 move_arg(SubExprs),
8105 E->getRParenLoc());
8106}
8107
Mike Stump1eb44332009-09-09 15:08:12 +00008108template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008109ExprResult
John McCall454feb92009-12-08 09:21:05 +00008110TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008111 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008112
John McCallc6ac9c32011-02-04 18:33:18 +00008113 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8114 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8115
8116 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008117 // We built a new blockScopeInfo in call to ActOnBlockStart
8118 // in above, CapturesCXXThis need be set here from the block
8119 // expression.
8120 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
Fariborz Jahanian05865202011-12-03 17:47:53 +00008121 blockScope->TheDecl->setBlockMissingReturnType(
8122 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008123
Chris Lattner686775d2011-07-20 06:58:45 +00008124 SmallVector<ParmVarDecl*, 4> params;
8125 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008126
8127 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008128 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8129 oldBlock->param_begin(),
8130 oldBlock->param_size(),
8131 0, paramTypes, &params))
Douglas Gregor92be2a52011-12-10 00:23:21 +00008132 return ExprError();
John McCallc6ac9c32011-02-04 18:33:18 +00008133
8134 const FunctionType *exprFunctionType = E->getFunctionType();
8135 QualType exprResultType = exprFunctionType->getResultType();
8136 if (!exprResultType.isNull()) {
8137 if (!exprResultType->isDependentType())
8138 blockScope->ReturnType = exprResultType;
8139 else if (exprResultType != getSema().Context.DependentTy)
8140 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008141 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008142
8143 // If the return type has not been determined yet, leave it as a dependent
8144 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00008145 if (blockScope->ReturnType.isNull())
8146 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00008147
8148 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00008149 if (blockScope->ReturnType->isObjCObjectType()) {
8150 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008151 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00008152 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00008153 return ExprError();
8154 }
John McCall711c52b2011-01-05 12:14:39 +00008155
John McCallc6ac9c32011-02-04 18:33:18 +00008156 QualType functionType = getDerived().RebuildFunctionProtoType(
8157 blockScope->ReturnType,
8158 paramTypes.data(),
8159 paramTypes.size(),
8160 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00008161 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008162 exprFunctionType->getExtInfo());
8163 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008164
8165 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008166 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008167 blockScope->TheDecl->setParams(params);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008168
8169 // If the return type wasn't explicitly set, it will have been marked as a
8170 // dependent type (DependentTy); clear out the return type setting so
8171 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00008172 if (blockScope->ReturnType == getSema().Context.DependentTy)
8173 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00008174
John McCall711c52b2011-01-05 12:14:39 +00008175 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008176 StmtResult body = getDerived().TransformStmt(E->getBody());
8177 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00008178 return ExprError();
8179
John McCallc6ac9c32011-02-04 18:33:18 +00008180#ifndef NDEBUG
8181 // In builds with assertions, make sure that we captured everything we
8182 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008183 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8184 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8185 e = oldBlock->capture_end(); i != e; ++i) {
8186 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008187
Douglas Gregorfc921372011-05-20 15:32:55 +00008188 // Ignore parameter packs.
8189 if (isa<ParmVarDecl>(oldCapture) &&
8190 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8191 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008192
Douglas Gregorfc921372011-05-20 15:32:55 +00008193 VarDecl *newCapture =
8194 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8195 oldCapture));
8196 assert(blockScope->CaptureMap.count(newCapture));
8197 }
John McCallc6ac9c32011-02-04 18:33:18 +00008198 }
8199#endif
8200
8201 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8202 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008203}
8204
Mike Stump1eb44332009-09-09 15:08:12 +00008205template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008206ExprResult
John McCall454feb92009-12-08 09:21:05 +00008207TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008208 ValueDecl *ND
8209 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8210 E->getDecl()));
8211 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00008212 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00008213
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008214 if (!getDerived().AlwaysRebuild() &&
8215 ND == E->getDecl()) {
8216 // Mark it referenced in the new context regardless.
8217 // FIXME: this is a bit instantiation-specific.
8218 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8219
John McCall3fa5cae2010-10-26 07:05:15 +00008220 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008221 }
8222
Abramo Bagnara25777432010-08-11 22:01:17 +00008223 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00008224 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00008225 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008226}
Mike Stump1eb44332009-09-09 15:08:12 +00008227
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008228template<typename Derived>
8229ExprResult
8230TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008231 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008232}
Eli Friedman276b0612011-10-11 02:20:01 +00008233
8234template<typename Derived>
8235ExprResult
8236TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008237 QualType RetTy = getDerived().TransformType(E->getType());
8238 bool ArgumentChanged = false;
8239 ASTOwningVector<Expr*> SubExprs(SemaRef);
8240 SubExprs.reserve(E->getNumSubExprs());
8241 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8242 SubExprs, &ArgumentChanged))
8243 return ExprError();
8244
8245 if (!getDerived().AlwaysRebuild() &&
8246 !ArgumentChanged)
8247 return SemaRef.Owned(E);
8248
8249 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8250 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008251}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008252
Douglas Gregorb98b1992009-08-11 05:31:07 +00008253//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008254// Type reconstruction
8255//===----------------------------------------------------------------------===//
8256
Mike Stump1eb44332009-09-09 15:08:12 +00008257template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008258QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8259 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008260 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008261 getDerived().getBaseEntity());
8262}
8263
Mike Stump1eb44332009-09-09 15:08:12 +00008264template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008265QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8266 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008267 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008268 getDerived().getBaseEntity());
8269}
8270
Mike Stump1eb44332009-09-09 15:08:12 +00008271template<typename Derived>
8272QualType
John McCall85737a72009-10-30 00:06:24 +00008273TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8274 bool WrittenAsLValue,
8275 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008276 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008277 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008278}
8279
8280template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008281QualType
John McCall85737a72009-10-30 00:06:24 +00008282TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8283 QualType ClassType,
8284 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008285 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008286 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008287}
8288
8289template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008290QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008291TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8292 ArrayType::ArraySizeModifier SizeMod,
8293 const llvm::APInt *Size,
8294 Expr *SizeExpr,
8295 unsigned IndexTypeQuals,
8296 SourceRange BracketsRange) {
8297 if (SizeExpr || !Size)
8298 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8299 IndexTypeQuals, BracketsRange,
8300 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008301
8302 QualType Types[] = {
8303 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8304 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8305 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008306 };
8307 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8308 QualType SizeType;
8309 for (unsigned I = 0; I != NumTypes; ++I)
8310 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8311 SizeType = Types[I];
8312 break;
8313 }
Mike Stump1eb44332009-09-09 15:08:12 +00008314
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008315 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8316 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00008317 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008318 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008319 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008320}
Mike Stump1eb44332009-09-09 15:08:12 +00008321
Douglas Gregor577f75a2009-08-04 16:50:30 +00008322template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008323QualType
8324TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008325 ArrayType::ArraySizeModifier SizeMod,
8326 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008327 unsigned IndexTypeQuals,
8328 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008329 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008330 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008331}
8332
8333template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008334QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008335TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008336 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008337 unsigned IndexTypeQuals,
8338 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008339 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008340 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008341}
Mike Stump1eb44332009-09-09 15:08:12 +00008342
Douglas Gregor577f75a2009-08-04 16:50:30 +00008343template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008344QualType
8345TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008346 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008347 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008348 unsigned IndexTypeQuals,
8349 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008350 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008351 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008352 IndexTypeQuals, BracketsRange);
8353}
8354
8355template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008356QualType
8357TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008358 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008359 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008360 unsigned IndexTypeQuals,
8361 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008362 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008363 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008364 IndexTypeQuals, BracketsRange);
8365}
8366
8367template<typename Derived>
8368QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008369 unsigned NumElements,
8370 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008371 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008372 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008373}
Mike Stump1eb44332009-09-09 15:08:12 +00008374
Douglas Gregor577f75a2009-08-04 16:50:30 +00008375template<typename Derived>
8376QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8377 unsigned NumElements,
8378 SourceLocation AttributeLoc) {
8379 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8380 NumElements, true);
8381 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008382 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8383 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008384 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008385}
Mike Stump1eb44332009-09-09 15:08:12 +00008386
Douglas Gregor577f75a2009-08-04 16:50:30 +00008387template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008388QualType
8389TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008390 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008391 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008392 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008393}
Mike Stump1eb44332009-09-09 15:08:12 +00008394
Douglas Gregor577f75a2009-08-04 16:50:30 +00008395template<typename Derived>
8396QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008397 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008398 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008399 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00008400 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008401 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008402 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008403 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00008404 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008405 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008406 getDerived().getBaseEntity(),
8407 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008408}
Mike Stump1eb44332009-09-09 15:08:12 +00008409
Douglas Gregor577f75a2009-08-04 16:50:30 +00008410template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008411QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8412 return SemaRef.Context.getFunctionNoProtoType(T);
8413}
8414
8415template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008416QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8417 assert(D && "no decl found");
8418 if (D->isInvalidDecl()) return QualType();
8419
Douglas Gregor92e986e2010-04-22 16:44:27 +00008420 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008421 TypeDecl *Ty;
8422 if (isa<UsingDecl>(D)) {
8423 UsingDecl *Using = cast<UsingDecl>(D);
8424 assert(Using->isTypeName() &&
8425 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8426
8427 // A valid resolved using typename decl points to exactly one type decl.
8428 assert(++Using->shadow_begin() == Using->shadow_end());
8429 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008430
John McCalled976492009-12-04 22:46:56 +00008431 } else {
8432 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8433 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8434 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8435 }
8436
8437 return SemaRef.Context.getTypeDeclType(Ty);
8438}
8439
8440template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008441QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8442 SourceLocation Loc) {
8443 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008444}
8445
8446template<typename Derived>
8447QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8448 return SemaRef.Context.getTypeOfType(Underlying);
8449}
8450
8451template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008452QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8453 SourceLocation Loc) {
8454 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008455}
8456
8457template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008458QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8459 UnaryTransformType::UTTKind UKind,
8460 SourceLocation Loc) {
8461 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8462}
8463
8464template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008465QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008466 TemplateName Template,
8467 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008468 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008469 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008470}
Mike Stump1eb44332009-09-09 15:08:12 +00008471
Douglas Gregordcee1a12009-08-06 05:28:30 +00008472template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00008473QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8474 SourceLocation KWLoc) {
8475 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8476}
8477
8478template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008479TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008480TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008481 bool TemplateKW,
8482 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008483 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008484 Template);
8485}
8486
8487template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008488TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008489TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8490 const IdentifierInfo &Name,
8491 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008492 QualType ObjectType,
8493 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008494 UnqualifiedId TemplateName;
8495 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008496 Sema::TemplateTy Template;
8497 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008498 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008499 SS,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008500 TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008501 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008502 /*EnteringContext=*/false,
8503 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008504 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008505}
Mike Stump1eb44332009-09-09 15:08:12 +00008506
Douglas Gregorb98b1992009-08-11 05:31:07 +00008507template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008508TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008509TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008510 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008511 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008512 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008513 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008514 // FIXME: Bogus location information.
8515 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8516 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008517 Sema::TemplateTy Template;
8518 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008519 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008520 SS,
8521 Name,
John McCallb3d87482010-08-24 05:47:05 +00008522 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008523 /*EnteringContext=*/false,
8524 Template);
8525 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008526}
Sean Huntc3021132010-05-05 15:23:54 +00008527
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008528template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008529ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008530TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8531 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008532 Expr *OrigCallee,
8533 Expr *First,
8534 Expr *Second) {
8535 Expr *Callee = OrigCallee->IgnoreParenCasts();
8536 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008537
Douglas Gregorb98b1992009-08-11 05:31:07 +00008538 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008539 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008540 if (!First->getType()->isOverloadableType() &&
8541 !Second->getType()->isOverloadableType())
8542 return getSema().CreateBuiltinArraySubscriptExpr(First,
8543 Callee->getLocStart(),
8544 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008545 } else if (Op == OO_Arrow) {
8546 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008547 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8548 } else if (Second == 0 || isPostIncDec) {
8549 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008550 // The argument is not of overloadable type, so try to create a
8551 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008552 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008553 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008554
John McCall9ae2f072010-08-23 23:25:46 +00008555 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008556 }
8557 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008558 if (!First->getType()->isOverloadableType() &&
8559 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008560 // Neither of the arguments is an overloadable type, so try to
8561 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008562 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008563 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008564 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008565 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008566 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008567
Douglas Gregorb98b1992009-08-11 05:31:07 +00008568 return move(Result);
8569 }
8570 }
Mike Stump1eb44332009-09-09 15:08:12 +00008571
8572 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008573 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008574 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008575
John McCall9ae2f072010-08-23 23:25:46 +00008576 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008577 assert(ULE->requiresADL());
8578
8579 // FIXME: Do we have to check
8580 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008581 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008582 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008583 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008584 }
Mike Stump1eb44332009-09-09 15:08:12 +00008585
Douglas Gregorb98b1992009-08-11 05:31:07 +00008586 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008587 Expr *Args[2] = { First, Second };
8588 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008589
Douglas Gregorb98b1992009-08-11 05:31:07 +00008590 // Create the overloaded operator invocation for unary operators.
8591 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008592 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008593 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008594 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008595 }
Mike Stump1eb44332009-09-09 15:08:12 +00008596
Douglas Gregor5b8968c2011-07-15 16:25:15 +00008597 if (Op == OO_Subscript) {
8598 SourceLocation LBrace;
8599 SourceLocation RBrace;
8600
8601 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8602 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8603 LBrace = SourceLocation::getFromRawEncoding(
8604 NameLoc.CXXOperatorName.BeginOpNameLoc);
8605 RBrace = SourceLocation::getFromRawEncoding(
8606 NameLoc.CXXOperatorName.EndOpNameLoc);
8607 } else {
8608 LBrace = Callee->getLocStart();
8609 RBrace = OpLoc;
8610 }
8611
8612 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8613 First, Second);
8614 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00008615
Douglas Gregorb98b1992009-08-11 05:31:07 +00008616 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008617 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008618 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008619 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8620 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008621 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008622
Mike Stump1eb44332009-09-09 15:08:12 +00008623 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008624}
Mike Stump1eb44332009-09-09 15:08:12 +00008625
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008626template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008627ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008628TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008629 SourceLocation OperatorLoc,
8630 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008631 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008632 TypeSourceInfo *ScopeType,
8633 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008634 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008635 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008636 QualType BaseType = Base->getType();
8637 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008638 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008639 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008640 !BaseType->getAs<PointerType>()->getPointeeType()
8641 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008642 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008643 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008644 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008645 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008646 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008647 /*FIXME?*/true);
8648 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008649
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008650 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008651 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8652 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8653 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8654 NameInfo.setNamedTypeInfo(DestroyedType);
8655
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008656 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008657
John McCall9ae2f072010-08-23 23:25:46 +00008658 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008659 OperatorLoc, isArrow,
8660 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008661 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008662 /*TemplateArgs*/ 0);
8663}
8664
Douglas Gregor577f75a2009-08-04 16:50:30 +00008665} // end namespace clang
8666
8667#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H