blob: f55e2a706bbd0967b4d93586734542c87dd35eda [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(),
John McCallf312b1e2010-08-26 23:41:50 +00002901 Sema::Unevaluated);
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: {
2935 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002936 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002937 Sema::Unevaluated);
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) {
John McCalla2becad2009-10-21 00:40:46 +00003185 if (getDerived().AlreadyTransformed(DI->getType()))
3186 return DI;
3187
3188 TypeLocBuilder TLB;
3189
3190 TypeLoc TL = DI->getTypeLoc();
3191 TLB.reserve(TL.getFullDataSize());
3192
John McCall43fed0d2010-11-12 08:19:04 +00003193 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003194 if (Result.isNull())
3195 return 0;
3196
John McCalla93c9342009-12-07 02:54:59 +00003197 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003198}
3199
3200template<typename Derived>
3201QualType
John McCall43fed0d2010-11-12 08:19:04 +00003202TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003203 switch (T.getTypeLocClass()) {
3204#define ABSTRACT_TYPELOC(CLASS, PARENT)
3205#define TYPELOC(CLASS, PARENT) \
3206 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003207 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003208#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003209 }
Mike Stump1eb44332009-09-09 15:08:12 +00003210
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003211 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003212 return QualType();
3213}
3214
3215/// FIXME: By default, this routine adds type qualifiers only to types
3216/// that can have qualifiers, and silently suppresses those qualifiers
3217/// that are not permitted (e.g., qualifiers on reference or function
3218/// types). This is the right thing for template instantiation, but
3219/// probably not for other clients.
3220template<typename Derived>
3221QualType
3222TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003223 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003224 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003225
John McCall43fed0d2010-11-12 08:19:04 +00003226 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003227 if (Result.isNull())
3228 return QualType();
3229
3230 // Silently suppress qualifiers if the result type can't be qualified.
3231 // FIXME: this is the right thing for template instantiation, but
3232 // probably not for other clients.
3233 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003234 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003235
John McCallf85e1932011-06-15 23:02:42 +00003236 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003237 // resulting type.
3238 if (Quals.hasObjCLifetime()) {
3239 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3240 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003241 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003242 // Objective-C ARC:
3243 // A lifetime qualifier applied to a substituted template parameter
3244 // overrides the lifetime qualifier from the template argument.
3245 if (const SubstTemplateTypeParmType *SubstTypeParam
3246 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3247 QualType Replacement = SubstTypeParam->getReplacementType();
3248 Qualifiers Qs = Replacement.getQualifiers();
3249 Qs.removeObjCLifetime();
3250 Replacement
3251 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3252 Qs);
3253 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3254 SubstTypeParam->getReplacedParameter(),
3255 Replacement);
3256 TLB.TypeWasModifiedSafely(Result);
3257 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003258 // Otherwise, complain about the addition of a qualifier to an
3259 // already-qualified type.
3260 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003261 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003262 << Result << R;
3263
Douglas Gregore559ca12011-06-17 22:11:49 +00003264 Quals.removeObjCLifetime();
3265 }
3266 }
3267 }
John McCall28654742010-06-05 06:41:15 +00003268 if (!Quals.empty()) {
3269 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3270 TLB.push<QualifiedTypeLoc>(Result);
3271 // No location information to preserve.
3272 }
John McCalla2becad2009-10-21 00:40:46 +00003273
3274 return Result;
3275}
3276
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003277template<typename Derived>
3278TypeLoc
3279TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3280 QualType ObjectType,
3281 NamedDecl *UnqualLookup,
3282 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003283 QualType T = TL.getType();
3284 if (getDerived().AlreadyTransformed(T))
3285 return TL;
3286
3287 TypeLocBuilder TLB;
3288 QualType Result;
3289
3290 if (isa<TemplateSpecializationType>(T)) {
3291 TemplateSpecializationTypeLoc SpecTL
3292 = cast<TemplateSpecializationTypeLoc>(TL);
3293
3294 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003295 getDerived().TransformTemplateName(SS,
3296 SpecTL.getTypePtr()->getTemplateName(),
3297 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003298 ObjectType, UnqualLookup);
3299 if (Template.isNull())
3300 return TypeLoc();
3301
3302 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3303 Template);
3304 } else if (isa<DependentTemplateSpecializationType>(T)) {
3305 DependentTemplateSpecializationTypeLoc SpecTL
3306 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3307
Douglas Gregora88f09f2011-02-28 17:23:35 +00003308 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003309 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003310 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003311 SpecTL.getNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003312 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003313 if (Template.isNull())
3314 return TypeLoc();
3315
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003316 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003317 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003318 Template,
3319 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003320 } else {
3321 // Nothing special needs to be done for these.
3322 Result = getDerived().TransformType(TLB, TL);
3323 }
3324
3325 if (Result.isNull())
3326 return TypeLoc();
3327
3328 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3329}
3330
Douglas Gregorb71d8212011-03-02 18:32:08 +00003331template<typename Derived>
3332TypeSourceInfo *
3333TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3334 QualType ObjectType,
3335 NamedDecl *UnqualLookup,
3336 CXXScopeSpec &SS) {
3337 // FIXME: Painfully copy-paste from the above!
3338
3339 QualType T = TSInfo->getType();
3340 if (getDerived().AlreadyTransformed(T))
3341 return TSInfo;
3342
3343 TypeLocBuilder TLB;
3344 QualType Result;
3345
3346 TypeLoc TL = TSInfo->getTypeLoc();
3347 if (isa<TemplateSpecializationType>(T)) {
3348 TemplateSpecializationTypeLoc SpecTL
3349 = cast<TemplateSpecializationTypeLoc>(TL);
3350
3351 TemplateName Template
3352 = getDerived().TransformTemplateName(SS,
3353 SpecTL.getTypePtr()->getTemplateName(),
3354 SpecTL.getTemplateNameLoc(),
3355 ObjectType, UnqualLookup);
3356 if (Template.isNull())
3357 return 0;
3358
3359 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3360 Template);
3361 } else if (isa<DependentTemplateSpecializationType>(T)) {
3362 DependentTemplateSpecializationTypeLoc SpecTL
3363 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3364
3365 TemplateName Template
3366 = getDerived().RebuildTemplateName(SS,
3367 *SpecTL.getTypePtr()->getIdentifier(),
3368 SpecTL.getNameLoc(),
3369 ObjectType, UnqualLookup);
3370 if (Template.isNull())
3371 return 0;
3372
3373 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3374 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003375 Template,
3376 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003377 } else {
3378 // Nothing special needs to be done for these.
3379 Result = getDerived().TransformType(TLB, TL);
3380 }
3381
3382 if (Result.isNull())
3383 return 0;
3384
3385 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3386}
3387
John McCalla2becad2009-10-21 00:40:46 +00003388template <class TyLoc> static inline
3389QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3390 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3391 NewT.setNameLoc(T.getNameLoc());
3392 return T.getType();
3393}
3394
John McCalla2becad2009-10-21 00:40:46 +00003395template<typename Derived>
3396QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003397 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003398 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3399 NewT.setBuiltinLoc(T.getBuiltinLoc());
3400 if (T.needsExtraLocalData())
3401 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3402 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003403}
Mike Stump1eb44332009-09-09 15:08:12 +00003404
Douglas Gregor577f75a2009-08-04 16:50:30 +00003405template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003406QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003407 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003408 // FIXME: recurse?
3409 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003410}
Mike Stump1eb44332009-09-09 15:08:12 +00003411
Douglas Gregor577f75a2009-08-04 16:50:30 +00003412template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003413QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003414 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003415 QualType PointeeType
3416 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003417 if (PointeeType.isNull())
3418 return QualType();
3419
3420 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003421 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003422 // A dependent pointer type 'T *' has is being transformed such
3423 // that an Objective-C class type is being replaced for 'T'. The
3424 // resulting pointer type is an ObjCObjectPointerType, not a
3425 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003426 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003427
John McCallc12c5bb2010-05-15 11:32:37 +00003428 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3429 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003430 return Result;
3431 }
John McCall43fed0d2010-11-12 08:19:04 +00003432
Douglas Gregor92e986e2010-04-22 16:44:27 +00003433 if (getDerived().AlwaysRebuild() ||
3434 PointeeType != TL.getPointeeLoc().getType()) {
3435 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3436 if (Result.isNull())
3437 return QualType();
3438 }
John McCallf85e1932011-06-15 23:02:42 +00003439
3440 // Objective-C ARC can add lifetime qualifiers to the type that we're
3441 // pointing to.
3442 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3443
Douglas Gregor92e986e2010-04-22 16:44:27 +00003444 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3445 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003446 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003447}
Mike Stump1eb44332009-09-09 15:08:12 +00003448
3449template<typename Derived>
3450QualType
John McCalla2becad2009-10-21 00:40:46 +00003451TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003452 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003453 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003454 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3455 if (PointeeType.isNull())
3456 return QualType();
3457
3458 QualType Result = TL.getType();
3459 if (getDerived().AlwaysRebuild() ||
3460 PointeeType != TL.getPointeeLoc().getType()) {
3461 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003462 TL.getSigilLoc());
3463 if (Result.isNull())
3464 return QualType();
3465 }
3466
Douglas Gregor39968ad2010-04-22 16:50:51 +00003467 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003468 NewT.setSigilLoc(TL.getSigilLoc());
3469 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003470}
3471
John McCall85737a72009-10-30 00:06:24 +00003472/// Transforms a reference type. Note that somewhat paradoxically we
3473/// don't care whether the type itself is an l-value type or an r-value
3474/// type; we only care if the type was *written* as an l-value type
3475/// or an r-value type.
3476template<typename Derived>
3477QualType
3478TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003479 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003480 const ReferenceType *T = TL.getTypePtr();
3481
3482 // Note that this works with the pointee-as-written.
3483 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3484 if (PointeeType.isNull())
3485 return QualType();
3486
3487 QualType Result = TL.getType();
3488 if (getDerived().AlwaysRebuild() ||
3489 PointeeType != T->getPointeeTypeAsWritten()) {
3490 Result = getDerived().RebuildReferenceType(PointeeType,
3491 T->isSpelledAsLValue(),
3492 TL.getSigilLoc());
3493 if (Result.isNull())
3494 return QualType();
3495 }
3496
John McCallf85e1932011-06-15 23:02:42 +00003497 // Objective-C ARC can add lifetime qualifiers to the type that we're
3498 // referring to.
3499 TLB.TypeWasModifiedSafely(
3500 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3501
John McCall85737a72009-10-30 00:06:24 +00003502 // r-value references can be rebuilt as l-value references.
3503 ReferenceTypeLoc NewTL;
3504 if (isa<LValueReferenceType>(Result))
3505 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3506 else
3507 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3508 NewTL.setSigilLoc(TL.getSigilLoc());
3509
3510 return Result;
3511}
3512
Mike Stump1eb44332009-09-09 15:08:12 +00003513template<typename Derived>
3514QualType
John McCalla2becad2009-10-21 00:40:46 +00003515TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003516 LValueReferenceTypeLoc TL) {
3517 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003518}
3519
Mike Stump1eb44332009-09-09 15:08:12 +00003520template<typename Derived>
3521QualType
John McCalla2becad2009-10-21 00:40:46 +00003522TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003523 RValueReferenceTypeLoc TL) {
3524 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003525}
Mike Stump1eb44332009-09-09 15:08:12 +00003526
Douglas Gregor577f75a2009-08-04 16:50:30 +00003527template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003528QualType
John McCalla2becad2009-10-21 00:40:46 +00003529TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003530 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003531 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003532 if (PointeeType.isNull())
3533 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003534
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003535 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3536 TypeSourceInfo* NewClsTInfo = 0;
3537 if (OldClsTInfo) {
3538 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3539 if (!NewClsTInfo)
3540 return QualType();
3541 }
3542
3543 const MemberPointerType *T = TL.getTypePtr();
3544 QualType OldClsType = QualType(T->getClass(), 0);
3545 QualType NewClsType;
3546 if (NewClsTInfo)
3547 NewClsType = NewClsTInfo->getType();
3548 else {
3549 NewClsType = getDerived().TransformType(OldClsType);
3550 if (NewClsType.isNull())
3551 return QualType();
3552 }
Mike Stump1eb44332009-09-09 15:08:12 +00003553
John McCalla2becad2009-10-21 00:40:46 +00003554 QualType Result = TL.getType();
3555 if (getDerived().AlwaysRebuild() ||
3556 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003557 NewClsType != OldClsType) {
3558 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003559 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003560 if (Result.isNull())
3561 return QualType();
3562 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003563
John McCalla2becad2009-10-21 00:40:46 +00003564 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3565 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003566 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003567
3568 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003569}
3570
Mike Stump1eb44332009-09-09 15:08:12 +00003571template<typename Derived>
3572QualType
John McCalla2becad2009-10-21 00:40:46 +00003573TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003574 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003575 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003576 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003577 if (ElementType.isNull())
3578 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003579
John McCalla2becad2009-10-21 00:40:46 +00003580 QualType Result = TL.getType();
3581 if (getDerived().AlwaysRebuild() ||
3582 ElementType != T->getElementType()) {
3583 Result = getDerived().RebuildConstantArrayType(ElementType,
3584 T->getSizeModifier(),
3585 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003586 T->getIndexTypeCVRQualifiers(),
3587 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003588 if (Result.isNull())
3589 return QualType();
3590 }
Sean Huntc3021132010-05-05 15:23:54 +00003591
John McCalla2becad2009-10-21 00:40:46 +00003592 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3593 NewTL.setLBracketLoc(TL.getLBracketLoc());
3594 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003595
John McCalla2becad2009-10-21 00:40:46 +00003596 Expr *Size = TL.getSizeExpr();
3597 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003598 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003599 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3600 }
3601 NewTL.setSizeExpr(Size);
3602
3603 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003604}
Mike Stump1eb44332009-09-09 15:08:12 +00003605
Douglas Gregor577f75a2009-08-04 16:50:30 +00003606template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003607QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003608 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003609 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003610 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003611 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003612 if (ElementType.isNull())
3613 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003614
John McCalla2becad2009-10-21 00:40:46 +00003615 QualType Result = TL.getType();
3616 if (getDerived().AlwaysRebuild() ||
3617 ElementType != T->getElementType()) {
3618 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003619 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003620 T->getIndexTypeCVRQualifiers(),
3621 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003622 if (Result.isNull())
3623 return QualType();
3624 }
Sean Huntc3021132010-05-05 15:23:54 +00003625
John McCalla2becad2009-10-21 00:40:46 +00003626 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3627 NewTL.setLBracketLoc(TL.getLBracketLoc());
3628 NewTL.setRBracketLoc(TL.getRBracketLoc());
3629 NewTL.setSizeExpr(0);
3630
3631 return Result;
3632}
3633
3634template<typename Derived>
3635QualType
3636TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003637 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003638 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003639 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3640 if (ElementType.isNull())
3641 return QualType();
3642
3643 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003644 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003645
John McCall60d7b3a2010-08-24 06:29:42 +00003646 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003647 = getDerived().TransformExpr(T->getSizeExpr());
3648 if (SizeResult.isInvalid())
3649 return QualType();
3650
John McCall9ae2f072010-08-23 23:25:46 +00003651 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003652
3653 QualType Result = TL.getType();
3654 if (getDerived().AlwaysRebuild() ||
3655 ElementType != T->getElementType() ||
3656 Size != T->getSizeExpr()) {
3657 Result = getDerived().RebuildVariableArrayType(ElementType,
3658 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003659 Size,
John McCalla2becad2009-10-21 00:40:46 +00003660 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003661 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003662 if (Result.isNull())
3663 return QualType();
3664 }
Sean Huntc3021132010-05-05 15:23:54 +00003665
John McCalla2becad2009-10-21 00:40:46 +00003666 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3667 NewTL.setLBracketLoc(TL.getLBracketLoc());
3668 NewTL.setRBracketLoc(TL.getRBracketLoc());
3669 NewTL.setSizeExpr(Size);
3670
3671 return Result;
3672}
3673
3674template<typename Derived>
3675QualType
3676TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003677 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003678 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003679 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3680 if (ElementType.isNull())
3681 return QualType();
3682
3683 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003684 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003685
John McCall3b657512011-01-19 10:06:00 +00003686 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3687 Expr *origSize = TL.getSizeExpr();
3688 if (!origSize) origSize = T->getSizeExpr();
3689
3690 ExprResult sizeResult
3691 = getDerived().TransformExpr(origSize);
3692 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003693 return QualType();
3694
John McCall3b657512011-01-19 10:06:00 +00003695 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003696
3697 QualType Result = TL.getType();
3698 if (getDerived().AlwaysRebuild() ||
3699 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003700 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003701 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3702 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003703 size,
John McCalla2becad2009-10-21 00:40:46 +00003704 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003705 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003706 if (Result.isNull())
3707 return QualType();
3708 }
John McCalla2becad2009-10-21 00:40:46 +00003709
3710 // We might have any sort of array type now, but fortunately they
3711 // all have the same location layout.
3712 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3713 NewTL.setLBracketLoc(TL.getLBracketLoc());
3714 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003715 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003716
3717 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003718}
Mike Stump1eb44332009-09-09 15:08:12 +00003719
3720template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003721QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003722 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003723 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003724 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003725
3726 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003727 QualType ElementType = getDerived().TransformType(T->getElementType());
3728 if (ElementType.isNull())
3729 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003730
Douglas Gregor670444e2009-08-04 22:27:00 +00003731 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003732 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003733
John McCall60d7b3a2010-08-24 06:29:42 +00003734 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003735 if (Size.isInvalid())
3736 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003737
John McCalla2becad2009-10-21 00:40:46 +00003738 QualType Result = TL.getType();
3739 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003740 ElementType != T->getElementType() ||
3741 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003742 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003743 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003744 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003745 if (Result.isNull())
3746 return QualType();
3747 }
John McCalla2becad2009-10-21 00:40:46 +00003748
3749 // Result might be dependent or not.
3750 if (isa<DependentSizedExtVectorType>(Result)) {
3751 DependentSizedExtVectorTypeLoc NewTL
3752 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3753 NewTL.setNameLoc(TL.getNameLoc());
3754 } else {
3755 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3756 NewTL.setNameLoc(TL.getNameLoc());
3757 }
3758
3759 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003760}
Mike Stump1eb44332009-09-09 15:08:12 +00003761
3762template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003763QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003764 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003765 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003766 QualType ElementType = getDerived().TransformType(T->getElementType());
3767 if (ElementType.isNull())
3768 return QualType();
3769
John McCalla2becad2009-10-21 00:40:46 +00003770 QualType Result = TL.getType();
3771 if (getDerived().AlwaysRebuild() ||
3772 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003773 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003774 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003775 if (Result.isNull())
3776 return QualType();
3777 }
Sean Huntc3021132010-05-05 15:23:54 +00003778
John McCalla2becad2009-10-21 00:40:46 +00003779 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3780 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003781
John McCalla2becad2009-10-21 00:40:46 +00003782 return Result;
3783}
3784
3785template<typename Derived>
3786QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003787 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003788 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003789 QualType ElementType = getDerived().TransformType(T->getElementType());
3790 if (ElementType.isNull())
3791 return QualType();
3792
3793 QualType Result = TL.getType();
3794 if (getDerived().AlwaysRebuild() ||
3795 ElementType != T->getElementType()) {
3796 Result = getDerived().RebuildExtVectorType(ElementType,
3797 T->getNumElements(),
3798 /*FIXME*/ SourceLocation());
3799 if (Result.isNull())
3800 return QualType();
3801 }
Sean Huntc3021132010-05-05 15:23:54 +00003802
John McCalla2becad2009-10-21 00:40:46 +00003803 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3804 NewTL.setNameLoc(TL.getNameLoc());
3805
3806 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003807}
Mike Stump1eb44332009-09-09 15:08:12 +00003808
3809template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003810ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003811TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003812 int indexAdjustment,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003813 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003814 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003815 TypeSourceInfo *NewDI = 0;
3816
3817 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3818 // If we're substituting into a pack expansion type and we know the
3819 TypeLoc OldTL = OldDI->getTypeLoc();
3820 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3821
3822 TypeLocBuilder TLB;
3823 TypeLoc NewTL = OldDI->getTypeLoc();
3824 TLB.reserve(NewTL.getFullDataSize());
3825
3826 QualType Result = getDerived().TransformType(TLB,
3827 OldExpansionTL.getPatternLoc());
3828 if (Result.isNull())
3829 return 0;
3830
3831 Result = RebuildPackExpansionType(Result,
3832 OldExpansionTL.getPatternLoc().getSourceRange(),
3833 OldExpansionTL.getEllipsisLoc(),
3834 NumExpansions);
3835 if (Result.isNull())
3836 return 0;
3837
3838 PackExpansionTypeLoc NewExpansionTL
3839 = TLB.push<PackExpansionTypeLoc>(Result);
3840 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3841 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3842 } else
3843 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003844 if (!NewDI)
3845 return 0;
3846
John McCallfb44de92011-05-01 22:35:37 +00003847 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003848 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003849
3850 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3851 OldParm->getDeclContext(),
3852 OldParm->getInnerLocStart(),
3853 OldParm->getLocation(),
3854 OldParm->getIdentifier(),
3855 NewDI->getType(),
3856 NewDI,
3857 OldParm->getStorageClass(),
3858 OldParm->getStorageClassAsWritten(),
3859 /* DefArg */ NULL);
3860 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3861 OldParm->getFunctionScopeIndex() + indexAdjustment);
3862 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003863}
3864
3865template<typename Derived>
3866bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003867 TransformFunctionTypeParams(SourceLocation Loc,
3868 ParmVarDecl **Params, unsigned NumParams,
3869 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003870 SmallVectorImpl<QualType> &OutParamTypes,
3871 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003872 int indexAdjustment = 0;
3873
Douglas Gregora009b592011-01-07 00:20:55 +00003874 for (unsigned i = 0; i != NumParams; ++i) {
3875 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003876 assert(OldParm->getFunctionScopeIndex() == i);
3877
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003878 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003879 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003880 if (OldParm->isParameterPack()) {
3881 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003882 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003883
Douglas Gregor603cfb42011-01-05 23:12:31 +00003884 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003885 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3886 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3887 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3888 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003889 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3890
Douglas Gregor603cfb42011-01-05 23:12:31 +00003891 // Determine whether we should expand the parameter packs.
3892 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003893 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003894 llvm::Optional<unsigned> OrigNumExpansions
3895 = ExpansionTL.getTypePtr()->getNumExpansions();
3896 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003897 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3898 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003899 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003900 ShouldExpand,
3901 RetainExpansion,
3902 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003903 return true;
3904 }
3905
3906 if (ShouldExpand) {
3907 // Expand the function parameter pack into multiple, separate
3908 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003909 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003910 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003911 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3912 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003913 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003914 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003915 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003916 if (!NewParm)
3917 return true;
3918
Douglas Gregora009b592011-01-07 00:20:55 +00003919 OutParamTypes.push_back(NewParm->getType());
3920 if (PVars)
3921 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003922 }
Douglas Gregord3731192011-01-10 07:32:04 +00003923
3924 // If we're supposed to retain a pack expansion, do so by temporarily
3925 // forgetting the partially-substituted parameter pack.
3926 if (RetainExpansion) {
3927 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3928 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003929 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003930 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003931 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003932 if (!NewParm)
3933 return true;
3934
3935 OutParamTypes.push_back(NewParm->getType());
3936 if (PVars)
3937 PVars->push_back(NewParm);
3938 }
3939
John McCallfb44de92011-05-01 22:35:37 +00003940 // The next parameter should have the same adjustment as the
3941 // last thing we pushed, but we post-incremented indexAdjustment
3942 // on every push. Also, if we push nothing, the adjustment should
3943 // go down by one.
3944 indexAdjustment--;
3945
Douglas Gregor603cfb42011-01-05 23:12:31 +00003946 // We're done with the pack expansion.
3947 continue;
3948 }
3949
3950 // We'll substitute the parameter now without expanding the pack
3951 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003952 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3953 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003954 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003955 NumExpansions);
3956 } else {
3957 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003958 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003959 llvm::Optional<unsigned>());
Douglas Gregor603cfb42011-01-05 23:12:31 +00003960 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003961
John McCall21ef0fa2010-03-11 09:03:00 +00003962 if (!NewParm)
3963 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003964
Douglas Gregora009b592011-01-07 00:20:55 +00003965 OutParamTypes.push_back(NewParm->getType());
3966 if (PVars)
3967 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003968 continue;
3969 }
John McCall21ef0fa2010-03-11 09:03:00 +00003970
3971 // Deal with the possibility that we don't have a parameter
3972 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003973 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003974 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003975 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003976 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003977 if (const PackExpansionType *Expansion
3978 = dyn_cast<PackExpansionType>(OldType)) {
3979 // We have a function parameter pack that may need to be expanded.
3980 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00003981 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003982 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3983
3984 // Determine whether we should expand the parameter packs.
3985 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003986 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003987 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003988 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003989 ShouldExpand,
3990 RetainExpansion,
3991 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003992 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003993 }
3994
3995 if (ShouldExpand) {
3996 // Expand the function parameter pack into multiple, separate
3997 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003998 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003999 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4000 QualType NewType = getDerived().TransformType(Pattern);
4001 if (NewType.isNull())
4002 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004003
Douglas Gregora009b592011-01-07 00:20:55 +00004004 OutParamTypes.push_back(NewType);
4005 if (PVars)
4006 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004007 }
4008
4009 // We're done with the pack expansion.
4010 continue;
4011 }
4012
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004013 // If we're supposed to retain a pack expansion, do so by temporarily
4014 // forgetting the partially-substituted parameter pack.
4015 if (RetainExpansion) {
4016 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4017 QualType NewType = getDerived().TransformType(Pattern);
4018 if (NewType.isNull())
4019 return true;
4020
4021 OutParamTypes.push_back(NewType);
4022 if (PVars)
4023 PVars->push_back(0);
4024 }
Douglas Gregord3731192011-01-10 07:32:04 +00004025
Douglas Gregor603cfb42011-01-05 23:12:31 +00004026 // We'll substitute the parameter now without expanding the pack
4027 // expansion.
4028 OldType = Expansion->getPattern();
4029 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004030 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4031 NewType = getDerived().TransformType(OldType);
4032 } else {
4033 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004034 }
4035
Douglas Gregor603cfb42011-01-05 23:12:31 +00004036 if (NewType.isNull())
4037 return true;
4038
4039 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004040 NewType = getSema().Context.getPackExpansionType(NewType,
4041 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004042
Douglas Gregora009b592011-01-07 00:20:55 +00004043 OutParamTypes.push_back(NewType);
4044 if (PVars)
4045 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004046 }
4047
John McCallfb44de92011-05-01 22:35:37 +00004048#ifndef NDEBUG
4049 if (PVars) {
4050 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4051 if (ParmVarDecl *parm = (*PVars)[i])
4052 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004053 }
John McCallfb44de92011-05-01 22:35:37 +00004054#endif
4055
4056 return false;
4057}
John McCall21ef0fa2010-03-11 09:03:00 +00004058
4059template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004060QualType
John McCalla2becad2009-10-21 00:40:46 +00004061TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004062 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004063 // Transform the parameters and return type.
4064 //
4065 // We instantiate in source order, with the return type first followed by
4066 // the parameters, because users tend to expect this (even if they shouldn't
4067 // rely on it!).
4068 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004069 // When the function has a trailing return type, we instantiate the
4070 // parameters before the return type, since the return type can then refer
4071 // to the parameters themselves (via decltype, sizeof, etc.).
4072 //
Chris Lattner686775d2011-07-20 06:58:45 +00004073 SmallVector<QualType, 4> ParamTypes;
4074 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004075 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004076
Douglas Gregordab60ad2010-10-01 18:44:50 +00004077 QualType ResultType;
4078
4079 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004080 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4081 TL.getParmArray(),
4082 TL.getNumArgs(),
4083 TL.getTypePtr()->arg_type_begin(),
4084 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004085 return QualType();
4086
4087 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4088 if (ResultType.isNull())
4089 return QualType();
4090 }
4091 else {
4092 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4093 if (ResultType.isNull())
4094 return QualType();
4095
Douglas Gregora009b592011-01-07 00:20:55 +00004096 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4097 TL.getParmArray(),
4098 TL.getNumArgs(),
4099 TL.getTypePtr()->arg_type_begin(),
4100 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004101 return QualType();
4102 }
4103
John McCalla2becad2009-10-21 00:40:46 +00004104 QualType Result = TL.getType();
4105 if (getDerived().AlwaysRebuild() ||
4106 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004107 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004108 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4109 Result = getDerived().RebuildFunctionProtoType(ResultType,
4110 ParamTypes.data(),
4111 ParamTypes.size(),
4112 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004113 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004114 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004115 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004116 if (Result.isNull())
4117 return QualType();
4118 }
Mike Stump1eb44332009-09-09 15:08:12 +00004119
John McCalla2becad2009-10-21 00:40:46 +00004120 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004121 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4122 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004123 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004124 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4125 NewTL.setArg(i, ParamDecls[i]);
4126
4127 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004128}
Mike Stump1eb44332009-09-09 15:08:12 +00004129
Douglas Gregor577f75a2009-08-04 16:50:30 +00004130template<typename Derived>
4131QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004132 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004133 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004134 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004135 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4136 if (ResultType.isNull())
4137 return QualType();
4138
4139 QualType Result = TL.getType();
4140 if (getDerived().AlwaysRebuild() ||
4141 ResultType != T->getResultType())
4142 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4143
4144 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004145 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4146 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004147 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004148
4149 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004150}
Mike Stump1eb44332009-09-09 15:08:12 +00004151
John McCalled976492009-12-04 22:46:56 +00004152template<typename Derived> QualType
4153TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004154 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004155 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004156 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004157 if (!D)
4158 return QualType();
4159
4160 QualType Result = TL.getType();
4161 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4162 Result = getDerived().RebuildUnresolvedUsingType(D);
4163 if (Result.isNull())
4164 return QualType();
4165 }
4166
4167 // We might get an arbitrary type spec type back. We should at
4168 // least always get a type spec type, though.
4169 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4170 NewTL.setNameLoc(TL.getNameLoc());
4171
4172 return Result;
4173}
4174
Douglas Gregor577f75a2009-08-04 16:50:30 +00004175template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004176QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004177 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004178 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004179 TypedefNameDecl *Typedef
4180 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4181 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004182 if (!Typedef)
4183 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004184
John McCalla2becad2009-10-21 00:40:46 +00004185 QualType Result = TL.getType();
4186 if (getDerived().AlwaysRebuild() ||
4187 Typedef != T->getDecl()) {
4188 Result = getDerived().RebuildTypedefType(Typedef);
4189 if (Result.isNull())
4190 return QualType();
4191 }
Mike Stump1eb44332009-09-09 15:08:12 +00004192
John McCalla2becad2009-10-21 00:40:46 +00004193 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4194 NewTL.setNameLoc(TL.getNameLoc());
4195
4196 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004197}
Mike Stump1eb44332009-09-09 15:08:12 +00004198
Douglas Gregor577f75a2009-08-04 16:50:30 +00004199template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004200QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004201 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004202 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004203 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004204
John McCall60d7b3a2010-08-24 06:29:42 +00004205 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004206 if (E.isInvalid())
4207 return QualType();
4208
John McCalla2becad2009-10-21 00:40:46 +00004209 QualType Result = TL.getType();
4210 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004211 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004212 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004213 if (Result.isNull())
4214 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004215 }
John McCalla2becad2009-10-21 00:40:46 +00004216 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004217
John McCalla2becad2009-10-21 00:40:46 +00004218 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004219 NewTL.setTypeofLoc(TL.getTypeofLoc());
4220 NewTL.setLParenLoc(TL.getLParenLoc());
4221 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004222
4223 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004224}
Mike Stump1eb44332009-09-09 15:08:12 +00004225
4226template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004227QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004228 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004229 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4230 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4231 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004232 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004233
John McCalla2becad2009-10-21 00:40:46 +00004234 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004235 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4236 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004237 if (Result.isNull())
4238 return QualType();
4239 }
Mike Stump1eb44332009-09-09 15:08:12 +00004240
John McCalla2becad2009-10-21 00:40:46 +00004241 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004242 NewTL.setTypeofLoc(TL.getTypeofLoc());
4243 NewTL.setLParenLoc(TL.getLParenLoc());
4244 NewTL.setRParenLoc(TL.getRParenLoc());
4245 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004246
4247 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004248}
Mike Stump1eb44332009-09-09 15:08:12 +00004249
4250template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004251QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004252 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004253 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004254
Douglas Gregor670444e2009-08-04 22:27:00 +00004255 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004256 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004257
John McCall60d7b3a2010-08-24 06:29:42 +00004258 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004259 if (E.isInvalid())
4260 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004261
John McCalla2becad2009-10-21 00:40:46 +00004262 QualType Result = TL.getType();
4263 if (getDerived().AlwaysRebuild() ||
4264 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004265 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004266 if (Result.isNull())
4267 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004268 }
John McCalla2becad2009-10-21 00:40:46 +00004269 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004270
John McCalla2becad2009-10-21 00:40:46 +00004271 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4272 NewTL.setNameLoc(TL.getNameLoc());
4273
4274 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004275}
4276
4277template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004278QualType TreeTransform<Derived>::TransformUnaryTransformType(
4279 TypeLocBuilder &TLB,
4280 UnaryTransformTypeLoc TL) {
4281 QualType Result = TL.getType();
4282 if (Result->isDependentType()) {
4283 const UnaryTransformType *T = TL.getTypePtr();
4284 QualType NewBase =
4285 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4286 Result = getDerived().RebuildUnaryTransformType(NewBase,
4287 T->getUTTKind(),
4288 TL.getKWLoc());
4289 if (Result.isNull())
4290 return QualType();
4291 }
4292
4293 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4294 NewTL.setKWLoc(TL.getKWLoc());
4295 NewTL.setParensRange(TL.getParensRange());
4296 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4297 return Result;
4298}
4299
4300template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004301QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4302 AutoTypeLoc TL) {
4303 const AutoType *T = TL.getTypePtr();
4304 QualType OldDeduced = T->getDeducedType();
4305 QualType NewDeduced;
4306 if (!OldDeduced.isNull()) {
4307 NewDeduced = getDerived().TransformType(OldDeduced);
4308 if (NewDeduced.isNull())
4309 return QualType();
4310 }
4311
4312 QualType Result = TL.getType();
4313 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4314 Result = getDerived().RebuildAutoType(NewDeduced);
4315 if (Result.isNull())
4316 return QualType();
4317 }
4318
4319 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4320 NewTL.setNameLoc(TL.getNameLoc());
4321
4322 return Result;
4323}
4324
4325template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004326QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004327 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004328 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004329 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004330 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4331 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004332 if (!Record)
4333 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004334
John McCalla2becad2009-10-21 00:40:46 +00004335 QualType Result = TL.getType();
4336 if (getDerived().AlwaysRebuild() ||
4337 Record != T->getDecl()) {
4338 Result = getDerived().RebuildRecordType(Record);
4339 if (Result.isNull())
4340 return QualType();
4341 }
Mike Stump1eb44332009-09-09 15:08:12 +00004342
John McCalla2becad2009-10-21 00:40:46 +00004343 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4344 NewTL.setNameLoc(TL.getNameLoc());
4345
4346 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004347}
Mike Stump1eb44332009-09-09 15:08:12 +00004348
4349template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004350QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004351 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004352 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004353 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004354 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4355 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004356 if (!Enum)
4357 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004358
John McCalla2becad2009-10-21 00:40:46 +00004359 QualType Result = TL.getType();
4360 if (getDerived().AlwaysRebuild() ||
4361 Enum != T->getDecl()) {
4362 Result = getDerived().RebuildEnumType(Enum);
4363 if (Result.isNull())
4364 return QualType();
4365 }
Mike Stump1eb44332009-09-09 15:08:12 +00004366
John McCalla2becad2009-10-21 00:40:46 +00004367 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4368 NewTL.setNameLoc(TL.getNameLoc());
4369
4370 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004371}
John McCall7da24312009-09-05 00:15:47 +00004372
John McCall3cb0ebd2010-03-10 03:28:59 +00004373template<typename Derived>
4374QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4375 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004376 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004377 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4378 TL.getTypePtr()->getDecl());
4379 if (!D) return QualType();
4380
4381 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4382 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4383 return T;
4384}
4385
Douglas Gregor577f75a2009-08-04 16:50:30 +00004386template<typename Derived>
4387QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004388 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004389 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004390 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004391}
4392
Mike Stump1eb44332009-09-09 15:08:12 +00004393template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004394QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004395 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004396 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004397 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4398
4399 // Substitute into the replacement type, which itself might involve something
4400 // that needs to be transformed. This only tends to occur with default
4401 // template arguments of template template parameters.
4402 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4403 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4404 if (Replacement.isNull())
4405 return QualType();
4406
4407 // Always canonicalize the replacement type.
4408 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4409 QualType Result
4410 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4411 Replacement);
4412
4413 // Propagate type-source information.
4414 SubstTemplateTypeParmTypeLoc NewTL
4415 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4416 NewTL.setNameLoc(TL.getNameLoc());
4417 return Result;
4418
John McCall49a832b2009-10-18 09:09:24 +00004419}
4420
4421template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004422QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4423 TypeLocBuilder &TLB,
4424 SubstTemplateTypeParmPackTypeLoc TL) {
4425 return TransformTypeSpecType(TLB, TL);
4426}
4427
4428template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004429QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004430 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004431 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004432 const TemplateSpecializationType *T = TL.getTypePtr();
4433
Douglas Gregor1d752d72011-03-02 18:46:51 +00004434 // The nested-name-specifier never matters in a TemplateSpecializationType,
4435 // because we can't have a dependent nested-name-specifier anyway.
4436 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004437 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004438 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4439 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004440 if (Template.isNull())
4441 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004442
John McCall43fed0d2010-11-12 08:19:04 +00004443 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4444}
4445
Eli Friedmanb001de72011-10-06 23:00:33 +00004446template<typename Derived>
4447QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4448 AtomicTypeLoc TL) {
4449 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4450 if (ValueType.isNull())
4451 return QualType();
4452
4453 QualType Result = TL.getType();
4454 if (getDerived().AlwaysRebuild() ||
4455 ValueType != TL.getValueLoc().getType()) {
4456 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4457 if (Result.isNull())
4458 return QualType();
4459 }
4460
4461 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4462 NewTL.setKWLoc(TL.getKWLoc());
4463 NewTL.setLParenLoc(TL.getLParenLoc());
4464 NewTL.setRParenLoc(TL.getRParenLoc());
4465
4466 return Result;
4467}
4468
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004469namespace {
4470 /// \brief Simple iterator that traverses the template arguments in a
4471 /// container that provides a \c getArgLoc() member function.
4472 ///
4473 /// This iterator is intended to be used with the iterator form of
4474 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4475 template<typename ArgLocContainer>
4476 class TemplateArgumentLocContainerIterator {
4477 ArgLocContainer *Container;
4478 unsigned Index;
4479
4480 public:
4481 typedef TemplateArgumentLoc value_type;
4482 typedef TemplateArgumentLoc reference;
4483 typedef int difference_type;
4484 typedef std::input_iterator_tag iterator_category;
4485
4486 class pointer {
4487 TemplateArgumentLoc Arg;
4488
4489 public:
4490 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4491
4492 const TemplateArgumentLoc *operator->() const {
4493 return &Arg;
4494 }
4495 };
4496
4497
4498 TemplateArgumentLocContainerIterator() {}
4499
4500 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4501 unsigned Index)
4502 : Container(&Container), Index(Index) { }
4503
4504 TemplateArgumentLocContainerIterator &operator++() {
4505 ++Index;
4506 return *this;
4507 }
4508
4509 TemplateArgumentLocContainerIterator operator++(int) {
4510 TemplateArgumentLocContainerIterator Old(*this);
4511 ++(*this);
4512 return Old;
4513 }
4514
4515 TemplateArgumentLoc operator*() const {
4516 return Container->getArgLoc(Index);
4517 }
4518
4519 pointer operator->() const {
4520 return pointer(Container->getArgLoc(Index));
4521 }
4522
4523 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004524 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004525 return X.Container == Y.Container && X.Index == Y.Index;
4526 }
4527
4528 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004529 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004530 return !(X == Y);
4531 }
4532 };
4533}
4534
4535
John McCall43fed0d2010-11-12 08:19:04 +00004536template <typename Derived>
4537QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4538 TypeLocBuilder &TLB,
4539 TemplateSpecializationTypeLoc TL,
4540 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004541 TemplateArgumentListInfo NewTemplateArgs;
4542 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4543 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004544 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4545 ArgIterator;
4546 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4547 ArgIterator(TL, TL.getNumArgs()),
4548 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004549 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004550
John McCall833ca992009-10-29 08:12:44 +00004551 // FIXME: maybe don't rebuild if all the template arguments are the same.
4552
4553 QualType Result =
4554 getDerived().RebuildTemplateSpecializationType(Template,
4555 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004556 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004557
4558 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004559 // Specializations of template template parameters are represented as
4560 // TemplateSpecializationTypes, and substitution of type alias templates
4561 // within a dependent context can transform them into
4562 // DependentTemplateSpecializationTypes.
4563 if (isa<DependentTemplateSpecializationType>(Result)) {
4564 DependentTemplateSpecializationTypeLoc NewTL
4565 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4566 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4567 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4568 NewTL.setNameLoc(TL.getTemplateNameLoc());
4569 NewTL.setLAngleLoc(TL.getLAngleLoc());
4570 NewTL.setRAngleLoc(TL.getRAngleLoc());
4571 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4572 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4573 return Result;
4574 }
4575
John McCall833ca992009-10-29 08:12:44 +00004576 TemplateSpecializationTypeLoc NewTL
4577 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4578 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4579 NewTL.setLAngleLoc(TL.getLAngleLoc());
4580 NewTL.setRAngleLoc(TL.getRAngleLoc());
4581 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4582 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004583 }
Mike Stump1eb44332009-09-09 15:08:12 +00004584
John McCall833ca992009-10-29 08:12:44 +00004585 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004586}
Mike Stump1eb44332009-09-09 15:08:12 +00004587
Douglas Gregora88f09f2011-02-28 17:23:35 +00004588template <typename Derived>
4589QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4590 TypeLocBuilder &TLB,
4591 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004592 TemplateName Template,
4593 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004594 TemplateArgumentListInfo NewTemplateArgs;
4595 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4596 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4597 typedef TemplateArgumentLocContainerIterator<
4598 DependentTemplateSpecializationTypeLoc> ArgIterator;
4599 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4600 ArgIterator(TL, TL.getNumArgs()),
4601 NewTemplateArgs))
4602 return QualType();
4603
4604 // FIXME: maybe don't rebuild if all the template arguments are the same.
4605
4606 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4607 QualType Result
4608 = getSema().Context.getDependentTemplateSpecializationType(
4609 TL.getTypePtr()->getKeyword(),
4610 DTN->getQualifier(),
4611 DTN->getIdentifier(),
4612 NewTemplateArgs);
4613
4614 DependentTemplateSpecializationTypeLoc NewTL
4615 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4616 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004617
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004618 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregora88f09f2011-02-28 17:23:35 +00004619 NewTL.setNameLoc(TL.getNameLoc());
4620 NewTL.setLAngleLoc(TL.getLAngleLoc());
4621 NewTL.setRAngleLoc(TL.getRAngleLoc());
4622 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4623 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4624 return Result;
4625 }
4626
4627 QualType Result
4628 = getDerived().RebuildTemplateSpecializationType(Template,
4629 TL.getNameLoc(),
4630 NewTemplateArgs);
4631
4632 if (!Result.isNull()) {
4633 /// FIXME: Wrap this in an elaborated-type-specifier?
4634 TemplateSpecializationTypeLoc NewTL
4635 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4636 NewTL.setTemplateNameLoc(TL.getNameLoc());
4637 NewTL.setLAngleLoc(TL.getLAngleLoc());
4638 NewTL.setRAngleLoc(TL.getRAngleLoc());
4639 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4640 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4641 }
4642
4643 return Result;
4644}
4645
Mike Stump1eb44332009-09-09 15:08:12 +00004646template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004647QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004648TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004649 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004650 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004651
Douglas Gregor9e876872011-03-01 18:12:44 +00004652 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004653 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004654 if (TL.getQualifierLoc()) {
4655 QualifierLoc
4656 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4657 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004658 return QualType();
4659 }
Mike Stump1eb44332009-09-09 15:08:12 +00004660
John McCall43fed0d2010-11-12 08:19:04 +00004661 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4662 if (NamedT.isNull())
4663 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004664
Richard Smith3e4c6c42011-05-05 21:57:07 +00004665 // C++0x [dcl.type.elab]p2:
4666 // If the identifier resolves to a typedef-name or the simple-template-id
4667 // resolves to an alias template specialization, the
4668 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004669 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4670 if (const TemplateSpecializationType *TST =
4671 NamedT->getAs<TemplateSpecializationType>()) {
4672 TemplateName Template = TST->getTemplateName();
4673 if (TypeAliasTemplateDecl *TAT =
4674 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4675 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4676 diag::err_tag_reference_non_tag) << 4;
4677 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4678 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004679 }
4680 }
4681
John McCalla2becad2009-10-21 00:40:46 +00004682 QualType Result = TL.getType();
4683 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004684 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004685 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004686 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004687 T->getKeyword(),
4688 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004689 if (Result.isNull())
4690 return QualType();
4691 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004692
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004693 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004694 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004695 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004696 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004697}
Mike Stump1eb44332009-09-09 15:08:12 +00004698
4699template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004700QualType TreeTransform<Derived>::TransformAttributedType(
4701 TypeLocBuilder &TLB,
4702 AttributedTypeLoc TL) {
4703 const AttributedType *oldType = TL.getTypePtr();
4704 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4705 if (modifiedType.isNull())
4706 return QualType();
4707
4708 QualType result = TL.getType();
4709
4710 // FIXME: dependent operand expressions?
4711 if (getDerived().AlwaysRebuild() ||
4712 modifiedType != oldType->getModifiedType()) {
4713 // TODO: this is really lame; we should really be rebuilding the
4714 // equivalent type from first principles.
4715 QualType equivalentType
4716 = getDerived().TransformType(oldType->getEquivalentType());
4717 if (equivalentType.isNull())
4718 return QualType();
4719 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4720 modifiedType,
4721 equivalentType);
4722 }
4723
4724 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4725 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4726 if (TL.hasAttrOperand())
4727 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4728 if (TL.hasAttrExprOperand())
4729 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4730 else if (TL.hasAttrEnumOperand())
4731 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4732
4733 return result;
4734}
4735
4736template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004737QualType
4738TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4739 ParenTypeLoc TL) {
4740 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4741 if (Inner.isNull())
4742 return QualType();
4743
4744 QualType Result = TL.getType();
4745 if (getDerived().AlwaysRebuild() ||
4746 Inner != TL.getInnerLoc().getType()) {
4747 Result = getDerived().RebuildParenType(Inner);
4748 if (Result.isNull())
4749 return QualType();
4750 }
4751
4752 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4753 NewTL.setLParenLoc(TL.getLParenLoc());
4754 NewTL.setRParenLoc(TL.getRParenLoc());
4755 return Result;
4756}
4757
4758template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004759QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004760 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004761 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004762
Douglas Gregor2494dd02011-03-01 01:34:45 +00004763 NestedNameSpecifierLoc QualifierLoc
4764 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4765 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004766 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004767
John McCall33500952010-06-11 00:33:02 +00004768 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004769 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCall33500952010-06-11 00:33:02 +00004770 TL.getKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004771 QualifierLoc,
4772 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004773 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004774 if (Result.isNull())
4775 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004776
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004777 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4778 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004779 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4780
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004781 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4782 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004783 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004784 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004785 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4786 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004787 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004788 NewTL.setNameLoc(TL.getNameLoc());
4789 }
John McCalla2becad2009-10-21 00:40:46 +00004790 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004791}
Mike Stump1eb44332009-09-09 15:08:12 +00004792
Douglas Gregor577f75a2009-08-04 16:50:30 +00004793template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004794QualType TreeTransform<Derived>::
4795 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004796 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004797 NestedNameSpecifierLoc QualifierLoc;
4798 if (TL.getQualifierLoc()) {
4799 QualifierLoc
4800 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4801 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004802 return QualType();
4803 }
4804
John McCall43fed0d2010-11-12 08:19:04 +00004805 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004806 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004807}
4808
4809template<typename Derived>
4810QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004811TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4812 DependentTemplateSpecializationTypeLoc TL,
4813 NestedNameSpecifierLoc QualifierLoc) {
4814 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4815
4816 TemplateArgumentListInfo NewTemplateArgs;
4817 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4818 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4819
4820 typedef TemplateArgumentLocContainerIterator<
4821 DependentTemplateSpecializationTypeLoc> ArgIterator;
4822 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4823 ArgIterator(TL, TL.getNumArgs()),
4824 NewTemplateArgs))
4825 return QualType();
4826
4827 QualType Result
4828 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4829 QualifierLoc,
4830 T->getIdentifier(),
4831 TL.getNameLoc(),
4832 NewTemplateArgs);
4833 if (Result.isNull())
4834 return QualType();
4835
4836 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4837 QualType NamedT = ElabT->getNamedType();
4838
4839 // Copy information relevant to the template specialization.
4840 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004841 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004842 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004843 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4844 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004845 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004846 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004847
4848 // Copy information relevant to the elaborated type.
4849 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4850 NewTL.setKeywordLoc(TL.getKeywordLoc());
4851 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004852 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4853 DependentTemplateSpecializationTypeLoc SpecTL
4854 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor944cdae2011-03-07 15:13:34 +00004855 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004856 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004857 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004858 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4859 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004860 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004861 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004862 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004863 TemplateSpecializationTypeLoc SpecTL
4864 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004865 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004866 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4867 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004868 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004869 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004870 }
4871 return Result;
4872}
4873
4874template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004875QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4876 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004877 QualType Pattern
4878 = getDerived().TransformType(TLB, TL.getPatternLoc());
4879 if (Pattern.isNull())
4880 return QualType();
4881
4882 QualType Result = TL.getType();
4883 if (getDerived().AlwaysRebuild() ||
4884 Pattern != TL.getPatternLoc().getType()) {
4885 Result = getDerived().RebuildPackExpansionType(Pattern,
4886 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004887 TL.getEllipsisLoc(),
4888 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004889 if (Result.isNull())
4890 return QualType();
4891 }
4892
4893 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4894 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4895 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004896}
4897
4898template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004899QualType
4900TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004901 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004902 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004903 TLB.pushFullCopy(TL);
4904 return TL.getType();
4905}
4906
4907template<typename Derived>
4908QualType
4909TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004910 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004911 // ObjCObjectType is never dependent.
4912 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004913 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004914}
Mike Stump1eb44332009-09-09 15:08:12 +00004915
4916template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004917QualType
4918TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004919 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004920 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004921 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004922 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004923}
4924
Douglas Gregor577f75a2009-08-04 16:50:30 +00004925//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004926// Statement transformation
4927//===----------------------------------------------------------------------===//
4928template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004929StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004930TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004931 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004932}
4933
4934template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004935StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004936TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4937 return getDerived().TransformCompoundStmt(S, false);
4938}
4939
4940template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004941StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004942TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004943 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004944 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004945 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004946 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004947 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4948 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004949 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004950 if (Result.isInvalid()) {
4951 // Immediately fail if this was a DeclStmt, since it's very
4952 // likely that this will cause problems for future statements.
4953 if (isa<DeclStmt>(*B))
4954 return StmtError();
4955
4956 // Otherwise, just keep processing substatements and fail later.
4957 SubStmtInvalid = true;
4958 continue;
4959 }
Mike Stump1eb44332009-09-09 15:08:12 +00004960
Douglas Gregor43959a92009-08-20 07:17:43 +00004961 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4962 Statements.push_back(Result.takeAs<Stmt>());
4963 }
Mike Stump1eb44332009-09-09 15:08:12 +00004964
John McCall7114cba2010-08-27 19:56:05 +00004965 if (SubStmtInvalid)
4966 return StmtError();
4967
Douglas Gregor43959a92009-08-20 07:17:43 +00004968 if (!getDerived().AlwaysRebuild() &&
4969 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004970 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004971
4972 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4973 move_arg(Statements),
4974 S->getRBracLoc(),
4975 IsStmtExpr);
4976}
Mike Stump1eb44332009-09-09 15:08:12 +00004977
Douglas Gregor43959a92009-08-20 07:17:43 +00004978template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004979StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004980TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004981 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004982 {
4983 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004984 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004985
Eli Friedman264c1f82009-11-19 03:14:00 +00004986 // Transform the left-hand case value.
4987 LHS = getDerived().TransformExpr(S->getLHS());
4988 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004989 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004990
Eli Friedman264c1f82009-11-19 03:14:00 +00004991 // Transform the right-hand case value (for the GNU case-range extension).
4992 RHS = getDerived().TransformExpr(S->getRHS());
4993 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004994 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004995 }
Mike Stump1eb44332009-09-09 15:08:12 +00004996
Douglas Gregor43959a92009-08-20 07:17:43 +00004997 // Build the case statement.
4998 // Case statements are always rebuilt so that they will attached to their
4999 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005000 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005001 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005002 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005003 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005004 S->getColonLoc());
5005 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005006 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005007
Douglas Gregor43959a92009-08-20 07:17:43 +00005008 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005009 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005010 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005011 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005012
Douglas Gregor43959a92009-08-20 07:17:43 +00005013 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005014 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005015}
5016
5017template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005018StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005019TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005020 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005021 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005022 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005023 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005024
Douglas Gregor43959a92009-08-20 07:17:43 +00005025 // Default statements are always rebuilt
5026 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005027 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005028}
Mike Stump1eb44332009-09-09 15:08:12 +00005029
Douglas Gregor43959a92009-08-20 07:17:43 +00005030template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005031StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005032TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005033 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005034 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005035 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005036
Chris Lattner57ad3782011-02-17 20:34:02 +00005037 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5038 S->getDecl());
5039 if (!LD)
5040 return StmtError();
5041
5042
Douglas Gregor43959a92009-08-20 07:17:43 +00005043 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005044 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005045 cast<LabelDecl>(LD), SourceLocation(),
5046 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005047}
Mike Stump1eb44332009-09-09 15:08:12 +00005048
Douglas Gregor43959a92009-08-20 07:17:43 +00005049template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005050StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005051TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005052 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005053 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005054 VarDecl *ConditionVar = 0;
5055 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005056 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005057 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005058 getDerived().TransformDefinition(
5059 S->getConditionVariable()->getLocation(),
5060 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005061 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005062 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005063 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005064 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005065
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005066 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005067 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005068
5069 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005070 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005071 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5072 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005073 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005074 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005075
John McCall9ae2f072010-08-23 23:25:46 +00005076 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005077 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005078 }
Sean Huntc3021132010-05-05 15:23:54 +00005079
John McCall9ae2f072010-08-23 23:25:46 +00005080 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5081 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005082 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005083
Douglas Gregor43959a92009-08-20 07:17:43 +00005084 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005085 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005086 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005087 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005088
Douglas Gregor43959a92009-08-20 07:17:43 +00005089 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005090 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005091 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005092 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005093
Douglas Gregor43959a92009-08-20 07:17:43 +00005094 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005095 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005096 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005097 Then.get() == S->getThen() &&
5098 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005099 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005100
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005101 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005102 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005103 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005104}
5105
5106template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005107StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005108TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005109 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005110 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005111 VarDecl *ConditionVar = 0;
5112 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005113 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005114 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005115 getDerived().TransformDefinition(
5116 S->getConditionVariable()->getLocation(),
5117 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005118 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005119 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005120 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005121 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005122
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005123 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005124 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005125 }
Mike Stump1eb44332009-09-09 15:08:12 +00005126
Douglas Gregor43959a92009-08-20 07:17:43 +00005127 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005128 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005129 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005130 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005131 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005132 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005133
Douglas Gregor43959a92009-08-20 07:17:43 +00005134 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005135 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005136 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005137 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005138
Douglas Gregor43959a92009-08-20 07:17:43 +00005139 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005140 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5141 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005142}
Mike Stump1eb44332009-09-09 15:08:12 +00005143
Douglas Gregor43959a92009-08-20 07:17:43 +00005144template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005145StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005146TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005147 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005148 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005149 VarDecl *ConditionVar = 0;
5150 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005151 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005152 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005153 getDerived().TransformDefinition(
5154 S->getConditionVariable()->getLocation(),
5155 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005156 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005157 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005158 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005159 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005160
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005161 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005162 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005163
5164 if (S->getCond()) {
5165 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005166 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5167 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005168 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005169 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005170 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005171 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005172 }
Mike Stump1eb44332009-09-09 15:08:12 +00005173
John McCall9ae2f072010-08-23 23:25:46 +00005174 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5175 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005176 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005177
Douglas Gregor43959a92009-08-20 07:17:43 +00005178 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005179 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005180 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005181 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005182
Douglas Gregor43959a92009-08-20 07:17:43 +00005183 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005184 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005185 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005186 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005187 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005188
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005189 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005190 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005191}
Mike Stump1eb44332009-09-09 15:08:12 +00005192
Douglas Gregor43959a92009-08-20 07:17:43 +00005193template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005194StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005195TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005196 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005197 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005198 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005199 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005200
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005201 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005202 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005203 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005204 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005205
Douglas Gregor43959a92009-08-20 07:17:43 +00005206 if (!getDerived().AlwaysRebuild() &&
5207 Cond.get() == S->getCond() &&
5208 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005209 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005210
John McCall9ae2f072010-08-23 23:25:46 +00005211 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5212 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005213 S->getRParenLoc());
5214}
Mike Stump1eb44332009-09-09 15:08:12 +00005215
Douglas Gregor43959a92009-08-20 07:17:43 +00005216template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005217StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005218TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005219 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005220 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005221 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005222 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005223
Douglas Gregor43959a92009-08-20 07:17:43 +00005224 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005225 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005226 VarDecl *ConditionVar = 0;
5227 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005228 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005229 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005230 getDerived().TransformDefinition(
5231 S->getConditionVariable()->getLocation(),
5232 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005233 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005234 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005235 } else {
5236 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005237
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005238 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005239 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005240
5241 if (S->getCond()) {
5242 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005243 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5244 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005245 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005246 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005247
John McCall9ae2f072010-08-23 23:25:46 +00005248 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005249 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005250 }
Mike Stump1eb44332009-09-09 15:08:12 +00005251
John McCall9ae2f072010-08-23 23:25:46 +00005252 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5253 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005254 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005255
Douglas Gregor43959a92009-08-20 07:17:43 +00005256 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005257 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005258 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005259 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005260
John McCall9ae2f072010-08-23 23:25:46 +00005261 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5262 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005263 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005264
Douglas Gregor43959a92009-08-20 07:17:43 +00005265 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005266 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005267 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005268 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005269
Douglas Gregor43959a92009-08-20 07:17:43 +00005270 if (!getDerived().AlwaysRebuild() &&
5271 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005272 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005273 Inc.get() == S->getInc() &&
5274 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005275 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005276
Douglas Gregor43959a92009-08-20 07:17:43 +00005277 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005278 Init.get(), FullCond, ConditionVar,
5279 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005280}
5281
5282template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005283StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005284TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005285 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5286 S->getLabel());
5287 if (!LD)
5288 return StmtError();
5289
Douglas Gregor43959a92009-08-20 07:17:43 +00005290 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005291 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005292 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005293}
5294
5295template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005296StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005297TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005298 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005299 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005300 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005301
Douglas Gregor43959a92009-08-20 07:17:43 +00005302 if (!getDerived().AlwaysRebuild() &&
5303 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005304 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005305
5306 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005307 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005308}
5309
5310template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005311StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005312TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005313 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005314}
Mike Stump1eb44332009-09-09 15:08:12 +00005315
Douglas Gregor43959a92009-08-20 07:17:43 +00005316template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005317StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005318TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005319 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005320}
Mike Stump1eb44332009-09-09 15:08:12 +00005321
Douglas Gregor43959a92009-08-20 07:17:43 +00005322template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005323StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005324TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005325 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005326 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005327 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005328
Mike Stump1eb44332009-09-09 15:08:12 +00005329 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005330 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005331 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005332}
Mike Stump1eb44332009-09-09 15:08:12 +00005333
Douglas Gregor43959a92009-08-20 07:17:43 +00005334template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005335StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005336TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005337 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005338 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005339 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5340 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005341 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5342 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005343 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005344 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005345
Douglas Gregor43959a92009-08-20 07:17:43 +00005346 if (Transformed != *D)
5347 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005348
Douglas Gregor43959a92009-08-20 07:17:43 +00005349 Decls.push_back(Transformed);
5350 }
Mike Stump1eb44332009-09-09 15:08:12 +00005351
Douglas Gregor43959a92009-08-20 07:17:43 +00005352 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005353 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005354
5355 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005356 S->getStartLoc(), S->getEndLoc());
5357}
Mike Stump1eb44332009-09-09 15:08:12 +00005358
Douglas Gregor43959a92009-08-20 07:17:43 +00005359template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005360StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005361TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005362
John McCallca0408f2010-08-23 06:44:23 +00005363 ASTOwningVector<Expr*> Constraints(getSema());
5364 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005365 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005366
John McCall60d7b3a2010-08-24 06:29:42 +00005367 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005368 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005369
5370 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005371
Anders Carlsson703e3942010-01-24 05:50:09 +00005372 // Go through the outputs.
5373 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005374 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005375
Anders Carlsson703e3942010-01-24 05:50:09 +00005376 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005377 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005378
Anders Carlsson703e3942010-01-24 05:50:09 +00005379 // Transform the output expr.
5380 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005381 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005382 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005383 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005384
Anders Carlsson703e3942010-01-24 05:50:09 +00005385 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005386
John McCall9ae2f072010-08-23 23:25:46 +00005387 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005388 }
Sean Huntc3021132010-05-05 15:23:54 +00005389
Anders Carlsson703e3942010-01-24 05:50:09 +00005390 // Go through the inputs.
5391 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005392 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005393
Anders Carlsson703e3942010-01-24 05:50:09 +00005394 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005395 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005396
Anders Carlsson703e3942010-01-24 05:50:09 +00005397 // Transform the input expr.
5398 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005399 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005400 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005401 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005402
Anders Carlsson703e3942010-01-24 05:50:09 +00005403 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005404
John McCall9ae2f072010-08-23 23:25:46 +00005405 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005406 }
Sean Huntc3021132010-05-05 15:23:54 +00005407
Anders Carlsson703e3942010-01-24 05:50:09 +00005408 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005409 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005410
5411 // Go through the clobbers.
5412 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005413 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005414
5415 // No need to transform the asm string literal.
5416 AsmString = SemaRef.Owned(S->getAsmString());
5417
5418 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5419 S->isSimple(),
5420 S->isVolatile(),
5421 S->getNumOutputs(),
5422 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005423 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005424 move_arg(Constraints),
5425 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005426 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005427 move_arg(Clobbers),
5428 S->getRParenLoc(),
5429 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005430}
5431
5432
5433template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005434StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005435TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005436 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005437 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005438 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005439 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005440
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005441 // Transform the @catch statements (if present).
5442 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005443 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005444 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005445 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005446 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005447 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005448 if (Catch.get() != S->getCatchStmt(I))
5449 AnyCatchChanged = true;
5450 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005451 }
Sean Huntc3021132010-05-05 15:23:54 +00005452
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005453 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005454 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005455 if (S->getFinallyStmt()) {
5456 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5457 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005458 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005459 }
5460
5461 // If nothing changed, just retain this statement.
5462 if (!getDerived().AlwaysRebuild() &&
5463 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005464 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005465 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005466 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005467
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005468 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005469 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5470 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005471}
Mike Stump1eb44332009-09-09 15:08:12 +00005472
Douglas Gregor43959a92009-08-20 07:17:43 +00005473template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005474StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005475TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005476 // Transform the @catch parameter, if there is one.
5477 VarDecl *Var = 0;
5478 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5479 TypeSourceInfo *TSInfo = 0;
5480 if (FromVar->getTypeSourceInfo()) {
5481 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5482 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005483 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005484 }
Sean Huntc3021132010-05-05 15:23:54 +00005485
Douglas Gregorbe270a02010-04-26 17:57:08 +00005486 QualType T;
5487 if (TSInfo)
5488 T = TSInfo->getType();
5489 else {
5490 T = getDerived().TransformType(FromVar->getType());
5491 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005492 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005493 }
Sean Huntc3021132010-05-05 15:23:54 +00005494
Douglas Gregorbe270a02010-04-26 17:57:08 +00005495 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5496 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005497 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005498 }
Sean Huntc3021132010-05-05 15:23:54 +00005499
John McCall60d7b3a2010-08-24 06:29:42 +00005500 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005501 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005502 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005503
5504 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005505 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005506 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005507}
Mike Stump1eb44332009-09-09 15:08:12 +00005508
Douglas Gregor43959a92009-08-20 07:17:43 +00005509template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005510StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005511TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005512 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005513 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005514 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005515 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005516
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005517 // If nothing changed, just retain this statement.
5518 if (!getDerived().AlwaysRebuild() &&
5519 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005520 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005521
5522 // Build a new statement.
5523 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005524 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005525}
Mike Stump1eb44332009-09-09 15:08:12 +00005526
Douglas Gregor43959a92009-08-20 07:17:43 +00005527template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005528StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005529TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005530 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005531 if (S->getThrowExpr()) {
5532 Operand = getDerived().TransformExpr(S->getThrowExpr());
5533 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005534 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005535 }
Sean Huntc3021132010-05-05 15:23:54 +00005536
Douglas Gregord1377b22010-04-22 21:44:01 +00005537 if (!getDerived().AlwaysRebuild() &&
5538 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005539 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005540
John McCall9ae2f072010-08-23 23:25:46 +00005541 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005542}
Mike Stump1eb44332009-09-09 15:08:12 +00005543
Douglas Gregor43959a92009-08-20 07:17:43 +00005544template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005545StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005546TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005547 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005548 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005549 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005550 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005551 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005552 Object =
5553 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5554 Object.get());
5555 if (Object.isInvalid())
5556 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005557
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005558 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005559 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005560 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005561 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005562
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005563 // If nothing change, just retain the current statement.
5564 if (!getDerived().AlwaysRebuild() &&
5565 Object.get() == S->getSynchExpr() &&
5566 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005567 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005568
5569 // Build a new statement.
5570 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005571 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005572}
5573
5574template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005575StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005576TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5577 ObjCAutoreleasePoolStmt *S) {
5578 // Transform the body.
5579 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5580 if (Body.isInvalid())
5581 return StmtError();
5582
5583 // If nothing changed, just retain this statement.
5584 if (!getDerived().AlwaysRebuild() &&
5585 Body.get() == S->getSubStmt())
5586 return SemaRef.Owned(S);
5587
5588 // Build a new statement.
5589 return getDerived().RebuildObjCAutoreleasePoolStmt(
5590 S->getAtLoc(), Body.get());
5591}
5592
5593template<typename Derived>
5594StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005595TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005596 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005597 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005598 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005599 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005600 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005601
Douglas Gregorc3203e72010-04-22 23:10:45 +00005602 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005603 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005604 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005605 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005606 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5607 Collection.take());
5608 if (Collection.isInvalid())
5609 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005610
Douglas Gregorc3203e72010-04-22 23:10:45 +00005611 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005612 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005613 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005614 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005615
Douglas Gregorc3203e72010-04-22 23:10:45 +00005616 // If nothing changed, just retain this statement.
5617 if (!getDerived().AlwaysRebuild() &&
5618 Element.get() == S->getElement() &&
5619 Collection.get() == S->getCollection() &&
5620 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005621 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005622
Douglas Gregorc3203e72010-04-22 23:10:45 +00005623 // Build a new statement.
5624 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5625 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005626 Element.get(),
5627 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005628 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005629 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005630}
5631
5632
5633template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005634StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005635TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5636 // Transform the exception declaration, if any.
5637 VarDecl *Var = 0;
5638 if (S->getExceptionDecl()) {
5639 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005640 TypeSourceInfo *T = getDerived().TransformType(
5641 ExceptionDecl->getTypeSourceInfo());
5642 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005643 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005644
Douglas Gregor83cb9422010-09-09 17:09:21 +00005645 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005646 ExceptionDecl->getInnerLocStart(),
5647 ExceptionDecl->getLocation(),
5648 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005649 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005650 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005651 }
Mike Stump1eb44332009-09-09 15:08:12 +00005652
Douglas Gregor43959a92009-08-20 07:17:43 +00005653 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005654 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005655 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005656 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005657
Douglas Gregor43959a92009-08-20 07:17:43 +00005658 if (!getDerived().AlwaysRebuild() &&
5659 !Var &&
5660 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005661 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005662
5663 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5664 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005665 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005666}
Mike Stump1eb44332009-09-09 15:08:12 +00005667
Douglas Gregor43959a92009-08-20 07:17:43 +00005668template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005669StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005670TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5671 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005672 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005673 = getDerived().TransformCompoundStmt(S->getTryBlock());
5674 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005675 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005676
Douglas Gregor43959a92009-08-20 07:17:43 +00005677 // Transform the handlers.
5678 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005679 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005680 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005681 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005682 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5683 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005684 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005685
Douglas Gregor43959a92009-08-20 07:17:43 +00005686 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5687 Handlers.push_back(Handler.takeAs<Stmt>());
5688 }
Mike Stump1eb44332009-09-09 15:08:12 +00005689
Douglas Gregor43959a92009-08-20 07:17:43 +00005690 if (!getDerived().AlwaysRebuild() &&
5691 TryBlock.get() == S->getTryBlock() &&
5692 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005693 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005694
John McCall9ae2f072010-08-23 23:25:46 +00005695 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005696 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005697}
Mike Stump1eb44332009-09-09 15:08:12 +00005698
Richard Smithad762fc2011-04-14 22:09:26 +00005699template<typename Derived>
5700StmtResult
5701TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5702 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5703 if (Range.isInvalid())
5704 return StmtError();
5705
5706 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5707 if (BeginEnd.isInvalid())
5708 return StmtError();
5709
5710 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5711 if (Cond.isInvalid())
5712 return StmtError();
5713
5714 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5715 if (Inc.isInvalid())
5716 return StmtError();
5717
5718 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5719 if (LoopVar.isInvalid())
5720 return StmtError();
5721
5722 StmtResult NewStmt = S;
5723 if (getDerived().AlwaysRebuild() ||
5724 Range.get() != S->getRangeStmt() ||
5725 BeginEnd.get() != S->getBeginEndStmt() ||
5726 Cond.get() != S->getCond() ||
5727 Inc.get() != S->getInc() ||
5728 LoopVar.get() != S->getLoopVarStmt())
5729 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5730 S->getColonLoc(), Range.get(),
5731 BeginEnd.get(), Cond.get(),
5732 Inc.get(), LoopVar.get(),
5733 S->getRParenLoc());
5734
5735 StmtResult Body = getDerived().TransformStmt(S->getBody());
5736 if (Body.isInvalid())
5737 return StmtError();
5738
5739 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5740 // it now so we have a new statement to attach the body to.
5741 if (Body.get() != S->getBody() && NewStmt.get() == S)
5742 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5743 S->getColonLoc(), Range.get(),
5744 BeginEnd.get(), Cond.get(),
5745 Inc.get(), LoopVar.get(),
5746 S->getRParenLoc());
5747
5748 if (NewStmt.get() == S)
5749 return SemaRef.Owned(S);
5750
5751 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5752}
5753
John Wiegley28bbe4b2011-04-28 01:08:34 +00005754template<typename Derived>
5755StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005756TreeTransform<Derived>::TransformMSDependentExistsStmt(
5757 MSDependentExistsStmt *S) {
5758 // Transform the nested-name-specifier, if any.
5759 NestedNameSpecifierLoc QualifierLoc;
5760 if (S->getQualifierLoc()) {
5761 QualifierLoc
5762 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5763 if (!QualifierLoc)
5764 return StmtError();
5765 }
5766
5767 // Transform the declaration name.
5768 DeclarationNameInfo NameInfo = S->getNameInfo();
5769 if (NameInfo.getName()) {
5770 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5771 if (!NameInfo.getName())
5772 return StmtError();
5773 }
5774
5775 // Check whether anything changed.
5776 if (!getDerived().AlwaysRebuild() &&
5777 QualifierLoc == S->getQualifierLoc() &&
5778 NameInfo.getName() == S->getNameInfo().getName())
5779 return S;
5780
5781 // Determine whether this name exists, if we can.
5782 CXXScopeSpec SS;
5783 SS.Adopt(QualifierLoc);
5784 bool Dependent = false;
5785 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5786 case Sema::IER_Exists:
5787 if (S->isIfExists())
5788 break;
5789
5790 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5791
5792 case Sema::IER_DoesNotExist:
5793 if (S->isIfNotExists())
5794 break;
5795
5796 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5797
5798 case Sema::IER_Dependent:
5799 Dependent = true;
5800 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005801
5802 case Sema::IER_Error:
5803 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005804 }
5805
5806 // We need to continue with the instantiation, so do so now.
5807 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5808 if (SubStmt.isInvalid())
5809 return StmtError();
5810
5811 // If we have resolved the name, just transform to the substatement.
5812 if (!Dependent)
5813 return SubStmt;
5814
5815 // The name is still dependent, so build a dependent expression again.
5816 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5817 S->isIfExists(),
5818 QualifierLoc,
5819 NameInfo,
5820 SubStmt.get());
5821}
5822
5823template<typename Derived>
5824StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005825TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5826 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5827 if(TryBlock.isInvalid()) return StmtError();
5828
5829 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5830 if(!getDerived().AlwaysRebuild() &&
5831 TryBlock.get() == S->getTryBlock() &&
5832 Handler.get() == S->getHandler())
5833 return SemaRef.Owned(S);
5834
5835 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5836 S->getTryLoc(),
5837 TryBlock.take(),
5838 Handler.take());
5839}
5840
5841template<typename Derived>
5842StmtResult
5843TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5844 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5845 if(Block.isInvalid()) return StmtError();
5846
5847 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5848 Block.take());
5849}
5850
5851template<typename Derived>
5852StmtResult
5853TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5854 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5855 if(FilterExpr.isInvalid()) return StmtError();
5856
5857 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5858 if(Block.isInvalid()) return StmtError();
5859
5860 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5861 FilterExpr.take(),
5862 Block.take());
5863}
5864
5865template<typename Derived>
5866StmtResult
5867TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5868 if(isa<SEHFinallyStmt>(Handler))
5869 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5870 else
5871 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5872}
5873
Douglas Gregor43959a92009-08-20 07:17:43 +00005874//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005875// Expression transformation
5876//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005877template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005878ExprResult
John McCall454feb92009-12-08 09:21:05 +00005879TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005880 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005881}
Mike Stump1eb44332009-09-09 15:08:12 +00005882
5883template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005884ExprResult
John McCall454feb92009-12-08 09:21:05 +00005885TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005886 NestedNameSpecifierLoc QualifierLoc;
5887 if (E->getQualifierLoc()) {
5888 QualifierLoc
5889 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5890 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005891 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005892 }
John McCalldbd872f2009-12-08 09:08:17 +00005893
5894 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005895 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5896 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005897 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005898 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005899
John McCallec8045d2010-08-17 21:27:17 +00005900 DeclarationNameInfo NameInfo = E->getNameInfo();
5901 if (NameInfo.getName()) {
5902 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5903 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005904 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005905 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005906
5907 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005908 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005909 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005910 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005911 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005912
5913 // Mark it referenced in the new context regardless.
5914 // FIXME: this is a bit instantiation-specific.
5915 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5916
John McCall3fa5cae2010-10-26 07:05:15 +00005917 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005918 }
John McCalldbd872f2009-12-08 09:08:17 +00005919
5920 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005921 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005922 TemplateArgs = &TransArgs;
5923 TransArgs.setLAngleLoc(E->getLAngleLoc());
5924 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005925 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5926 E->getNumTemplateArgs(),
5927 TransArgs))
5928 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005929 }
5930
Douglas Gregor40d96a62011-02-28 21:54:11 +00005931 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5932 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005933}
Mike Stump1eb44332009-09-09 15:08:12 +00005934
Douglas Gregorb98b1992009-08-11 05:31:07 +00005935template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005936ExprResult
John McCall454feb92009-12-08 09:21:05 +00005937TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005938 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005939}
Mike Stump1eb44332009-09-09 15:08:12 +00005940
Douglas Gregorb98b1992009-08-11 05:31:07 +00005941template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005942ExprResult
John McCall454feb92009-12-08 09:21:05 +00005943TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005944 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005945}
Mike Stump1eb44332009-09-09 15:08:12 +00005946
Douglas Gregorb98b1992009-08-11 05:31:07 +00005947template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005948ExprResult
John McCall454feb92009-12-08 09:21:05 +00005949TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005950 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005951}
Mike Stump1eb44332009-09-09 15:08:12 +00005952
Douglas Gregorb98b1992009-08-11 05:31:07 +00005953template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005954ExprResult
John McCall454feb92009-12-08 09:21:05 +00005955TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005956 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005957}
Mike Stump1eb44332009-09-09 15:08:12 +00005958
Douglas Gregorb98b1992009-08-11 05:31:07 +00005959template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005960ExprResult
John McCall454feb92009-12-08 09:21:05 +00005961TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005962 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005963}
5964
5965template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005966ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00005967TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5968 ExprResult ControllingExpr =
5969 getDerived().TransformExpr(E->getControllingExpr());
5970 if (ControllingExpr.isInvalid())
5971 return ExprError();
5972
Chris Lattner686775d2011-07-20 06:58:45 +00005973 SmallVector<Expr *, 4> AssocExprs;
5974 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00005975 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5976 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5977 if (TS) {
5978 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5979 if (!AssocType)
5980 return ExprError();
5981 AssocTypes.push_back(AssocType);
5982 } else {
5983 AssocTypes.push_back(0);
5984 }
5985
5986 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5987 if (AssocExpr.isInvalid())
5988 return ExprError();
5989 AssocExprs.push_back(AssocExpr.release());
5990 }
5991
5992 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5993 E->getDefaultLoc(),
5994 E->getRParenLoc(),
5995 ControllingExpr.release(),
5996 AssocTypes.data(),
5997 AssocExprs.data(),
5998 E->getNumAssocs());
5999}
6000
6001template<typename Derived>
6002ExprResult
John McCall454feb92009-12-08 09:21:05 +00006003TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006004 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006005 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006006 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006007
Douglas Gregorb98b1992009-08-11 05:31:07 +00006008 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006009 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006010
John McCall9ae2f072010-08-23 23:25:46 +00006011 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006012 E->getRParen());
6013}
6014
Mike Stump1eb44332009-09-09 15:08:12 +00006015template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006016ExprResult
John McCall454feb92009-12-08 09:21:05 +00006017TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006018 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006019 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006020 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006021
Douglas Gregorb98b1992009-08-11 05:31:07 +00006022 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006023 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006024
Douglas Gregorb98b1992009-08-11 05:31:07 +00006025 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6026 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006027 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006028}
Mike Stump1eb44332009-09-09 15:08:12 +00006029
Douglas Gregorb98b1992009-08-11 05:31:07 +00006030template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006031ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006032TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6033 // Transform the type.
6034 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6035 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006036 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006037
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006038 // Transform all of the components into components similar to what the
6039 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006040 // FIXME: It would be slightly more efficient in the non-dependent case to
6041 // just map FieldDecls, rather than requiring the rebuilder to look for
6042 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006043 // template code that we don't care.
6044 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006045 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006046 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006047 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006048 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6049 const Node &ON = E->getComponent(I);
6050 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006051 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006052 Comp.LocStart = ON.getSourceRange().getBegin();
6053 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006054 switch (ON.getKind()) {
6055 case Node::Array: {
6056 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006057 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006058 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006059 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006060
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006061 ExprChanged = ExprChanged || Index.get() != FromIndex;
6062 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006063 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006064 break;
6065 }
Sean Huntc3021132010-05-05 15:23:54 +00006066
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006067 case Node::Field:
6068 case Node::Identifier:
6069 Comp.isBrackets = false;
6070 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006071 if (!Comp.U.IdentInfo)
6072 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006073
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006074 break;
Sean Huntc3021132010-05-05 15:23:54 +00006075
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006076 case Node::Base:
6077 // Will be recomputed during the rebuild.
6078 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006079 }
Sean Huntc3021132010-05-05 15:23:54 +00006080
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006081 Components.push_back(Comp);
6082 }
Sean Huntc3021132010-05-05 15:23:54 +00006083
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006084 // If nothing changed, retain the existing expression.
6085 if (!getDerived().AlwaysRebuild() &&
6086 Type == E->getTypeSourceInfo() &&
6087 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006088 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006089
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006090 // Build a new offsetof expression.
6091 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6092 Components.data(), Components.size(),
6093 E->getRParenLoc());
6094}
6095
6096template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006097ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006098TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6099 assert(getDerived().AlreadyTransformed(E->getType()) &&
6100 "opaque value expression requires transformation");
6101 return SemaRef.Owned(E);
6102}
6103
6104template<typename Derived>
6105ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006106TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
6107 // Rebuild the syntactic form.
6108 ExprResult result = getDerived().TransformExpr(E->getSyntacticForm());
6109 if (result.isInvalid()) return ExprError();
6110
6111 // If that gives us a pseudo-object result back, the pseudo-object
6112 // expression must have been an lvalue-to-rvalue conversion which we
6113 // should reapply.
6114 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6115 result = SemaRef.checkPseudoObjectRValue(result.take());
6116
6117 return result;
6118}
6119
6120template<typename Derived>
6121ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006122TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6123 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006124 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006125 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006126
John McCalla93c9342009-12-07 02:54:59 +00006127 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006128 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006129 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006130
John McCall5ab75172009-11-04 07:28:41 +00006131 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006132 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006133
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006134 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6135 E->getKind(),
6136 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006137 }
Mike Stump1eb44332009-09-09 15:08:12 +00006138
John McCall60d7b3a2010-08-24 06:29:42 +00006139 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00006140 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006141 // C++0x [expr.sizeof]p1:
6142 // The operand is either an expression, which is an unevaluated operand
6143 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00006144 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006145
Douglas Gregorb98b1992009-08-11 05:31:07 +00006146 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6147 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006148 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006149
Douglas Gregorb98b1992009-08-11 05:31:07 +00006150 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006151 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006152 }
Mike Stump1eb44332009-09-09 15:08:12 +00006153
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006154 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6155 E->getOperatorLoc(),
6156 E->getKind(),
6157 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006158}
Mike Stump1eb44332009-09-09 15:08:12 +00006159
Douglas Gregorb98b1992009-08-11 05:31:07 +00006160template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006161ExprResult
John McCall454feb92009-12-08 09:21:05 +00006162TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006163 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006164 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006165 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006166
John McCall60d7b3a2010-08-24 06:29:42 +00006167 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006168 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006169 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006170
6171
Douglas Gregorb98b1992009-08-11 05:31:07 +00006172 if (!getDerived().AlwaysRebuild() &&
6173 LHS.get() == E->getLHS() &&
6174 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006175 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006176
John McCall9ae2f072010-08-23 23:25:46 +00006177 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006178 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006179 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006180 E->getRBracketLoc());
6181}
Mike Stump1eb44332009-09-09 15:08:12 +00006182
6183template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006184ExprResult
John McCall454feb92009-12-08 09:21:05 +00006185TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006186 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006187 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006188 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006189 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006190
6191 // Transform arguments.
6192 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006193 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006194 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6195 &ArgChanged))
6196 return ExprError();
6197
Douglas Gregorb98b1992009-08-11 05:31:07 +00006198 if (!getDerived().AlwaysRebuild() &&
6199 Callee.get() == E->getCallee() &&
6200 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006201 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006202
Douglas Gregorb98b1992009-08-11 05:31:07 +00006203 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006204 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006205 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006206 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006207 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006208 E->getRParenLoc());
6209}
Mike Stump1eb44332009-09-09 15:08:12 +00006210
6211template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006212ExprResult
John McCall454feb92009-12-08 09:21:05 +00006213TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006214 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006216 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006217
Douglas Gregor40d96a62011-02-28 21:54:11 +00006218 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006219 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006220 QualifierLoc
6221 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6222
6223 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006224 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006225 }
Mike Stump1eb44332009-09-09 15:08:12 +00006226
Eli Friedmanf595cc42009-12-04 06:40:45 +00006227 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006228 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6229 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006230 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006231 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006232
John McCall6bb80172010-03-30 21:47:33 +00006233 NamedDecl *FoundDecl = E->getFoundDecl();
6234 if (FoundDecl == E->getMemberDecl()) {
6235 FoundDecl = Member;
6236 } else {
6237 FoundDecl = cast_or_null<NamedDecl>(
6238 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6239 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006240 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006241 }
6242
Douglas Gregorb98b1992009-08-11 05:31:07 +00006243 if (!getDerived().AlwaysRebuild() &&
6244 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006245 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006246 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006247 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006248 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006249
Anders Carlsson1f240322009-12-22 05:24:09 +00006250 // Mark it referenced in the new context regardless.
6251 // FIXME: this is a bit instantiation-specific.
6252 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00006253 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006254 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006255
John McCalld5532b62009-11-23 01:53:49 +00006256 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006257 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006258 TransArgs.setLAngleLoc(E->getLAngleLoc());
6259 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006260 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6261 E->getNumTemplateArgs(),
6262 TransArgs))
6263 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006264 }
Sean Huntc3021132010-05-05 15:23:54 +00006265
Douglas Gregorb98b1992009-08-11 05:31:07 +00006266 // FIXME: Bogus source location for the operator
6267 SourceLocation FakeOperatorLoc
6268 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6269
John McCallc2233c52010-01-15 08:34:02 +00006270 // FIXME: to do this check properly, we will need to preserve the
6271 // first-qualifier-in-scope here, just in case we had a dependent
6272 // base (and therefore couldn't do the check) and a
6273 // nested-name-qualifier (and therefore could do the lookup).
6274 NamedDecl *FirstQualifierInScope = 0;
6275
John McCall9ae2f072010-08-23 23:25:46 +00006276 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006277 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006278 QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006279 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006280 Member,
John McCall6bb80172010-03-30 21:47:33 +00006281 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006282 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006283 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006284 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006285}
Mike Stump1eb44332009-09-09 15:08:12 +00006286
Douglas Gregorb98b1992009-08-11 05:31:07 +00006287template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006288ExprResult
John McCall454feb92009-12-08 09:21:05 +00006289TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006290 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006291 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006292 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006293
John McCall60d7b3a2010-08-24 06:29:42 +00006294 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006295 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006296 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006297
Douglas Gregorb98b1992009-08-11 05:31:07 +00006298 if (!getDerived().AlwaysRebuild() &&
6299 LHS.get() == E->getLHS() &&
6300 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006301 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006302
Douglas Gregorb98b1992009-08-11 05:31:07 +00006303 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006304 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006305}
6306
Mike Stump1eb44332009-09-09 15:08:12 +00006307template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006308ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006309TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006310 CompoundAssignOperator *E) {
6311 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006312}
Mike Stump1eb44332009-09-09 15:08:12 +00006313
Douglas Gregorb98b1992009-08-11 05:31:07 +00006314template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006315ExprResult TreeTransform<Derived>::
6316TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6317 // Just rebuild the common and RHS expressions and see whether we
6318 // get any changes.
6319
6320 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6321 if (commonExpr.isInvalid())
6322 return ExprError();
6323
6324 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6325 if (rhs.isInvalid())
6326 return ExprError();
6327
6328 if (!getDerived().AlwaysRebuild() &&
6329 commonExpr.get() == e->getCommon() &&
6330 rhs.get() == e->getFalseExpr())
6331 return SemaRef.Owned(e);
6332
6333 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6334 e->getQuestionLoc(),
6335 0,
6336 e->getColonLoc(),
6337 rhs.get());
6338}
6339
6340template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006341ExprResult
John McCall454feb92009-12-08 09:21:05 +00006342TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006343 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006344 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006345 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006346
John McCall60d7b3a2010-08-24 06:29:42 +00006347 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006348 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006349 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006350
John McCall60d7b3a2010-08-24 06:29:42 +00006351 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006352 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006353 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006354
Douglas Gregorb98b1992009-08-11 05:31:07 +00006355 if (!getDerived().AlwaysRebuild() &&
6356 Cond.get() == E->getCond() &&
6357 LHS.get() == E->getLHS() &&
6358 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006359 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006360
John McCall9ae2f072010-08-23 23:25:46 +00006361 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006362 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006363 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006364 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006365 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006366}
Mike Stump1eb44332009-09-09 15:08:12 +00006367
6368template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006369ExprResult
John McCall454feb92009-12-08 09:21:05 +00006370TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006371 // Implicit casts are eliminated during transformation, since they
6372 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006373 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006374}
Mike Stump1eb44332009-09-09 15:08:12 +00006375
Douglas Gregorb98b1992009-08-11 05:31:07 +00006376template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006377ExprResult
John McCall454feb92009-12-08 09:21:05 +00006378TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006379 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6380 if (!Type)
6381 return ExprError();
6382
John McCall60d7b3a2010-08-24 06:29:42 +00006383 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006384 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006385 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006386 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006387
Douglas Gregorb98b1992009-08-11 05:31:07 +00006388 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006389 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006390 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006391 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006392
John McCall9d125032010-01-15 18:39:57 +00006393 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006394 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006395 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006396 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006397}
Mike Stump1eb44332009-09-09 15:08:12 +00006398
Douglas Gregorb98b1992009-08-11 05:31:07 +00006399template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006400ExprResult
John McCall454feb92009-12-08 09:21:05 +00006401TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006402 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6403 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6404 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006405 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006406
John McCall60d7b3a2010-08-24 06:29:42 +00006407 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006408 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006409 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006410
Douglas Gregorb98b1992009-08-11 05:31:07 +00006411 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006412 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006413 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00006414 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006415
John McCall1d7d8d62010-01-19 22:33:45 +00006416 // Note: the expression type doesn't necessarily match the
6417 // type-as-written, but that's okay, because it should always be
6418 // derivable from the initializer.
6419
John McCall42f56b52010-01-18 19:35:47 +00006420 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006421 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006422 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006423}
Mike Stump1eb44332009-09-09 15:08:12 +00006424
Douglas Gregorb98b1992009-08-11 05:31:07 +00006425template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006426ExprResult
John McCall454feb92009-12-08 09:21:05 +00006427TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006428 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006429 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006430 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006431
Douglas Gregorb98b1992009-08-11 05:31:07 +00006432 if (!getDerived().AlwaysRebuild() &&
6433 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006434 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006435
Douglas Gregorb98b1992009-08-11 05:31:07 +00006436 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006437 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006439 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006440 E->getAccessorLoc(),
6441 E->getAccessor());
6442}
Mike Stump1eb44332009-09-09 15:08:12 +00006443
Douglas Gregorb98b1992009-08-11 05:31:07 +00006444template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006445ExprResult
John McCall454feb92009-12-08 09:21:05 +00006446TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006447 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006448
John McCallca0408f2010-08-23 06:44:23 +00006449 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006450 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6451 Inits, &InitChanged))
6452 return ExprError();
6453
Douglas Gregorb98b1992009-08-11 05:31:07 +00006454 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006455 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006456
Douglas Gregorb98b1992009-08-11 05:31:07 +00006457 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006458 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006459}
Mike Stump1eb44332009-09-09 15:08:12 +00006460
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006462ExprResult
John McCall454feb92009-12-08 09:21:05 +00006463TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006464 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006465
Douglas Gregor43959a92009-08-20 07:17:43 +00006466 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006467 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006468 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006469 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006470
Douglas Gregor43959a92009-08-20 07:17:43 +00006471 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006472 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006473 bool ExprChanged = false;
6474 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6475 DEnd = E->designators_end();
6476 D != DEnd; ++D) {
6477 if (D->isFieldDesignator()) {
6478 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6479 D->getDotLoc(),
6480 D->getFieldLoc()));
6481 continue;
6482 }
Mike Stump1eb44332009-09-09 15:08:12 +00006483
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006485 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006486 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006487 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006488
6489 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006490 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006491
Douglas Gregorb98b1992009-08-11 05:31:07 +00006492 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6493 ArrayExprs.push_back(Index.release());
6494 continue;
6495 }
Mike Stump1eb44332009-09-09 15:08:12 +00006496
Douglas Gregorb98b1992009-08-11 05:31:07 +00006497 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006498 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006499 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6500 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006501 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006502
John McCall60d7b3a2010-08-24 06:29:42 +00006503 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006505 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006506
6507 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006508 End.get(),
6509 D->getLBracketLoc(),
6510 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006511
Douglas Gregorb98b1992009-08-11 05:31:07 +00006512 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6513 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006514
Douglas Gregorb98b1992009-08-11 05:31:07 +00006515 ArrayExprs.push_back(Start.release());
6516 ArrayExprs.push_back(End.release());
6517 }
Mike Stump1eb44332009-09-09 15:08:12 +00006518
Douglas Gregorb98b1992009-08-11 05:31:07 +00006519 if (!getDerived().AlwaysRebuild() &&
6520 Init.get() == E->getInit() &&
6521 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006522 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006523
Douglas Gregorb98b1992009-08-11 05:31:07 +00006524 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6525 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006526 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006527}
Mike Stump1eb44332009-09-09 15:08:12 +00006528
Douglas Gregorb98b1992009-08-11 05:31:07 +00006529template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006530ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006531TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006532 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006533 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006534
Douglas Gregor5557b252009-10-28 00:29:27 +00006535 // FIXME: Will we ever have proper type location here? Will we actually
6536 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006537 QualType T = getDerived().TransformType(E->getType());
6538 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006539 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006540
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541 if (!getDerived().AlwaysRebuild() &&
6542 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006543 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006544
Douglas Gregorb98b1992009-08-11 05:31:07 +00006545 return getDerived().RebuildImplicitValueInitExpr(T);
6546}
Mike Stump1eb44332009-09-09 15:08:12 +00006547
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006549ExprResult
John McCall454feb92009-12-08 09:21:05 +00006550TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006551 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6552 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006553 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006554
John McCall60d7b3a2010-08-24 06:29:42 +00006555 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006556 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006557 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006558
Douglas Gregorb98b1992009-08-11 05:31:07 +00006559 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006560 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006562 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006563
John McCall9ae2f072010-08-23 23:25:46 +00006564 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006565 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006566}
6567
6568template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006569ExprResult
John McCall454feb92009-12-08 09:21:05 +00006570TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006571 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006572 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006573 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6574 &ArgumentChanged))
6575 return ExprError();
6576
Douglas Gregorb98b1992009-08-11 05:31:07 +00006577 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6578 move_arg(Inits),
6579 E->getRParenLoc());
6580}
Mike Stump1eb44332009-09-09 15:08:12 +00006581
Douglas Gregorb98b1992009-08-11 05:31:07 +00006582/// \brief Transform an address-of-label expression.
6583///
6584/// By default, the transformation of an address-of-label expression always
6585/// rebuilds the expression, so that the label identifier can be resolved to
6586/// the corresponding label statement by semantic analysis.
6587template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006588ExprResult
John McCall454feb92009-12-08 09:21:05 +00006589TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006590 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6591 E->getLabel());
6592 if (!LD)
6593 return ExprError();
6594
Douglas Gregorb98b1992009-08-11 05:31:07 +00006595 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006596 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006597}
Mike Stump1eb44332009-09-09 15:08:12 +00006598
6599template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006600ExprResult
John McCall454feb92009-12-08 09:21:05 +00006601TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006602 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006603 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6604 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006605 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006606
Douglas Gregorb98b1992009-08-11 05:31:07 +00006607 if (!getDerived().AlwaysRebuild() &&
6608 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00006609 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006610
6611 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006612 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006613 E->getRParenLoc());
6614}
Mike Stump1eb44332009-09-09 15:08:12 +00006615
Douglas Gregorb98b1992009-08-11 05:31:07 +00006616template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006617ExprResult
John McCall454feb92009-12-08 09:21:05 +00006618TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006619 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006621 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006622
John McCall60d7b3a2010-08-24 06:29:42 +00006623 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006625 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006626
John McCall60d7b3a2010-08-24 06:29:42 +00006627 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006628 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006629 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006630
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631 if (!getDerived().AlwaysRebuild() &&
6632 Cond.get() == E->getCond() &&
6633 LHS.get() == E->getLHS() &&
6634 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006635 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006636
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006638 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639 E->getRParenLoc());
6640}
Mike Stump1eb44332009-09-09 15:08:12 +00006641
Douglas Gregorb98b1992009-08-11 05:31:07 +00006642template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006643ExprResult
John McCall454feb92009-12-08 09:21:05 +00006644TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006645 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646}
6647
6648template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006649ExprResult
John McCall454feb92009-12-08 09:21:05 +00006650TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006651 switch (E->getOperator()) {
6652 case OO_New:
6653 case OO_Delete:
6654 case OO_Array_New:
6655 case OO_Array_Delete:
6656 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006657 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006658
Douglas Gregor668d6d92009-12-13 20:44:55 +00006659 case OO_Call: {
6660 // This is a call to an object's operator().
6661 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6662
6663 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006664 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006665 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006666 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006667
6668 // FIXME: Poor location information
6669 SourceLocation FakeLParenLoc
6670 = SemaRef.PP.getLocForEndOfToken(
6671 static_cast<Expr *>(Object.get())->getLocEnd());
6672
6673 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006674 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006675 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6676 Args))
6677 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006678
John McCall9ae2f072010-08-23 23:25:46 +00006679 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006680 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006681 E->getLocEnd());
6682 }
6683
6684#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6685 case OO_##Name:
6686#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6687#include "clang/Basic/OperatorKinds.def"
6688 case OO_Subscript:
6689 // Handled below.
6690 break;
6691
6692 case OO_Conditional:
6693 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006694 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006695
6696 case OO_None:
6697 case NUM_OVERLOADED_OPERATORS:
6698 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006699 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006700 }
6701
John McCall60d7b3a2010-08-24 06:29:42 +00006702 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006703 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006704 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006705
John McCall60d7b3a2010-08-24 06:29:42 +00006706 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006707 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006708 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006709
John McCall60d7b3a2010-08-24 06:29:42 +00006710 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006711 if (E->getNumArgs() == 2) {
6712 Second = getDerived().TransformExpr(E->getArg(1));
6713 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006714 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006715 }
Mike Stump1eb44332009-09-09 15:08:12 +00006716
Douglas Gregorb98b1992009-08-11 05:31:07 +00006717 if (!getDerived().AlwaysRebuild() &&
6718 Callee.get() == E->getCallee() &&
6719 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006720 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00006721 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006722
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6724 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006725 Callee.get(),
6726 First.get(),
6727 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006728}
Mike Stump1eb44332009-09-09 15:08:12 +00006729
Douglas Gregorb98b1992009-08-11 05:31:07 +00006730template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006731ExprResult
John McCall454feb92009-12-08 09:21:05 +00006732TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6733 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006734}
Mike Stump1eb44332009-09-09 15:08:12 +00006735
Douglas Gregorb98b1992009-08-11 05:31:07 +00006736template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006737ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006738TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6739 // Transform the callee.
6740 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6741 if (Callee.isInvalid())
6742 return ExprError();
6743
6744 // Transform exec config.
6745 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6746 if (EC.isInvalid())
6747 return ExprError();
6748
6749 // Transform arguments.
6750 bool ArgChanged = false;
6751 ASTOwningVector<Expr*> Args(SemaRef);
6752 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6753 &ArgChanged))
6754 return ExprError();
6755
6756 if (!getDerived().AlwaysRebuild() &&
6757 Callee.get() == E->getCallee() &&
6758 !ArgChanged)
6759 return SemaRef.Owned(E);
6760
6761 // FIXME: Wrong source location information for the '('.
6762 SourceLocation FakeLParenLoc
6763 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6764 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6765 move_arg(Args),
6766 E->getRParenLoc(), EC.get());
6767}
6768
6769template<typename Derived>
6770ExprResult
John McCall454feb92009-12-08 09:21:05 +00006771TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006772 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6773 if (!Type)
6774 return ExprError();
6775
John McCall60d7b3a2010-08-24 06:29:42 +00006776 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006777 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006778 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006779 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006780
Douglas Gregorb98b1992009-08-11 05:31:07 +00006781 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006782 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006784 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006785
Douglas Gregorb98b1992009-08-11 05:31:07 +00006786 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006787 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006788 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6789 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6790 SourceLocation FakeRParenLoc
6791 = SemaRef.PP.getLocForEndOfToken(
6792 E->getSubExpr()->getSourceRange().getEnd());
6793 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006794 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006795 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006796 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006797 FakeRAngleLoc,
6798 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006799 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006800 FakeRParenLoc);
6801}
Mike Stump1eb44332009-09-09 15:08:12 +00006802
Douglas Gregorb98b1992009-08-11 05:31:07 +00006803template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006804ExprResult
John McCall454feb92009-12-08 09:21:05 +00006805TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6806 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807}
Mike Stump1eb44332009-09-09 15:08:12 +00006808
6809template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006810ExprResult
John McCall454feb92009-12-08 09:21:05 +00006811TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6812 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006813}
6814
Douglas Gregorb98b1992009-08-11 05:31:07 +00006815template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006816ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006817TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006818 CXXReinterpretCastExpr *E) {
6819 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006820}
Mike Stump1eb44332009-09-09 15:08:12 +00006821
Douglas Gregorb98b1992009-08-11 05:31:07 +00006822template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006823ExprResult
John McCall454feb92009-12-08 09:21:05 +00006824TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6825 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006826}
Mike Stump1eb44332009-09-09 15:08:12 +00006827
Douglas Gregorb98b1992009-08-11 05:31:07 +00006828template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006829ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006831 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006832 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6833 if (!Type)
6834 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006835
John McCall60d7b3a2010-08-24 06:29:42 +00006836 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006837 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006838 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006839 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006840
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006842 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006843 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006844 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006845
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006846 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006847 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006848 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006849 E->getRParenLoc());
6850}
Mike Stump1eb44332009-09-09 15:08:12 +00006851
Douglas Gregorb98b1992009-08-11 05:31:07 +00006852template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006853ExprResult
John McCall454feb92009-12-08 09:21:05 +00006854TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006855 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006856 TypeSourceInfo *TInfo
6857 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6858 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006859 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006860
Douglas Gregorb98b1992009-08-11 05:31:07 +00006861 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006862 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006863 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006864
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006865 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6866 E->getLocStart(),
6867 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006868 E->getLocEnd());
6869 }
Mike Stump1eb44332009-09-09 15:08:12 +00006870
Douglas Gregorb98b1992009-08-11 05:31:07 +00006871 // We don't know whether the expression is potentially evaluated until
6872 // after we perform semantic analysis, so the expression is potentially
6873 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006874 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006875 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006876
John McCall60d7b3a2010-08-24 06:29:42 +00006877 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006878 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006879 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006880
Douglas Gregorb98b1992009-08-11 05:31:07 +00006881 if (!getDerived().AlwaysRebuild() &&
6882 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006883 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006884
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006885 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6886 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006887 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006888 E->getLocEnd());
6889}
6890
6891template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006892ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006893TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6894 if (E->isTypeOperand()) {
6895 TypeSourceInfo *TInfo
6896 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6897 if (!TInfo)
6898 return ExprError();
6899
6900 if (!getDerived().AlwaysRebuild() &&
6901 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006902 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006903
Douglas Gregor3c52a212011-03-06 17:40:41 +00006904 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006905 E->getLocStart(),
6906 TInfo,
6907 E->getLocEnd());
6908 }
6909
6910 // We don't know whether the expression is potentially evaluated until
6911 // after we perform semantic analysis, so the expression is potentially
6912 // potentially evaluated.
6913 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6914
6915 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6916 if (SubExpr.isInvalid())
6917 return ExprError();
6918
6919 if (!getDerived().AlwaysRebuild() &&
6920 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006921 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006922
6923 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6924 E->getLocStart(),
6925 SubExpr.get(),
6926 E->getLocEnd());
6927}
6928
6929template<typename Derived>
6930ExprResult
John McCall454feb92009-12-08 09:21:05 +00006931TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006932 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006933}
Mike Stump1eb44332009-09-09 15:08:12 +00006934
Douglas Gregorb98b1992009-08-11 05:31:07 +00006935template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006936ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006938 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006939 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006940}
Mike Stump1eb44332009-09-09 15:08:12 +00006941
Douglas Gregorb98b1992009-08-11 05:31:07 +00006942template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006943ExprResult
John McCall454feb92009-12-08 09:21:05 +00006944TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006945 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00006946 QualType T;
6947 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6948 T = MD->getThisType(getSema().Context);
6949 else
6950 T = getSema().Context.getPointerType(
6951 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00006952
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006953 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006954 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006955
Douglas Gregor828a1972010-01-07 23:12:05 +00006956 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006957}
Mike Stump1eb44332009-09-09 15:08:12 +00006958
Douglas Gregorb98b1992009-08-11 05:31:07 +00006959template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006960ExprResult
John McCall454feb92009-12-08 09:21:05 +00006961TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006962 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006963 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006964 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006965
Douglas Gregorb98b1992009-08-11 05:31:07 +00006966 if (!getDerived().AlwaysRebuild() &&
6967 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006968 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006969
Douglas Gregorbca01b42011-07-06 22:04:06 +00006970 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6971 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006972}
Mike Stump1eb44332009-09-09 15:08:12 +00006973
Douglas Gregorb98b1992009-08-11 05:31:07 +00006974template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006975ExprResult
John McCall454feb92009-12-08 09:21:05 +00006976TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006977 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006978 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6979 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006980 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006981 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006982
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006983 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006984 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006985 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006986
Douglas Gregor036aed12009-12-23 23:03:06 +00006987 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006988}
Mike Stump1eb44332009-09-09 15:08:12 +00006989
Douglas Gregorb98b1992009-08-11 05:31:07 +00006990template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006991ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006992TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6993 CXXScalarValueInitExpr *E) {
6994 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6995 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006996 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006997
Douglas Gregorb98b1992009-08-11 05:31:07 +00006998 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006999 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007000 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007001
Douglas Gregorab6677e2010-09-08 00:15:04 +00007002 return getDerived().RebuildCXXScalarValueInitExpr(T,
7003 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007004 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007005}
Mike Stump1eb44332009-09-09 15:08:12 +00007006
Douglas Gregorb98b1992009-08-11 05:31:07 +00007007template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007008ExprResult
John McCall454feb92009-12-08 09:21:05 +00007009TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007010 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007011 TypeSourceInfo *AllocTypeInfo
7012 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7013 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007014 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007015
Douglas Gregorb98b1992009-08-11 05:31:07 +00007016 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007017 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007018 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007019 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007020
Douglas Gregorb98b1992009-08-11 05:31:07 +00007021 // Transform the placement arguments (if any).
7022 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007023 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007024 if (getDerived().TransformExprs(E->getPlacementArgs(),
7025 E->getNumPlacementArgs(), true,
7026 PlacementArgs, &ArgumentChanged))
7027 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007028
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007029 // Transform the constructor arguments (if any).
7030 // As an annoying corner case, we may have introduced an implicit value-
7031 // initialization expression when allocating a new array, which we implicitly
7032 // drop. It will be re-created during type checking.
John McCallca0408f2010-08-23 06:44:23 +00007033 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007034 if (!(E->isArray() && E->getNumConstructorArgs() == 1 &&
7035 isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) &&
7036 TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007037 ConstructorArgs, &ArgumentChanged))
7038 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007039
Douglas Gregor1af74512010-02-26 00:38:10 +00007040 // Transform constructor, new operator, and delete operator.
7041 CXXConstructorDecl *Constructor = 0;
7042 if (E->getConstructor()) {
7043 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007044 getDerived().TransformDecl(E->getLocStart(),
7045 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007046 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007047 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007048 }
7049
7050 FunctionDecl *OperatorNew = 0;
7051 if (E->getOperatorNew()) {
7052 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007053 getDerived().TransformDecl(E->getLocStart(),
7054 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007055 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007056 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007057 }
7058
7059 FunctionDecl *OperatorDelete = 0;
7060 if (E->getOperatorDelete()) {
7061 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007062 getDerived().TransformDecl(E->getLocStart(),
7063 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007064 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007065 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007066 }
Sean Huntc3021132010-05-05 15:23:54 +00007067
Douglas Gregorb98b1992009-08-11 05:31:07 +00007068 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007069 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007071 Constructor == E->getConstructor() &&
7072 OperatorNew == E->getOperatorNew() &&
7073 OperatorDelete == E->getOperatorDelete() &&
7074 !ArgumentChanged) {
7075 // Mark any declarations we need as referenced.
7076 // FIXME: instantiation-specific.
7077 if (Constructor)
7078 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
7079 if (OperatorNew)
7080 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
7081 if (OperatorDelete)
7082 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007083
7084 if (E->isArray() && Constructor &&
7085 !E->getAllocatedType()->isDependentType()) {
7086 QualType ElementType
7087 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7088 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7089 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7090 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
7091 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
7092 }
7093 }
7094 }
7095
John McCall3fa5cae2010-10-26 07:05:15 +00007096 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007097 }
Mike Stump1eb44332009-09-09 15:08:12 +00007098
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007099 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007100 if (!ArraySize.get()) {
7101 // If no array size was specified, but the new expression was
7102 // instantiated with an array type (e.g., "new T" where T is
7103 // instantiated with "int[4]"), extract the outer bound from the
7104 // array type as our array size. We do this with constant and
7105 // dependently-sized array types.
7106 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7107 if (!ArrayT) {
7108 // Do nothing
7109 } else if (const ConstantArrayType *ConsArrayT
7110 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007111 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007112 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7113 ConsArrayT->getSize(),
7114 SemaRef.Context.getSizeType(),
7115 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007116 AllocType = ConsArrayT->getElementType();
7117 } else if (const DependentSizedArrayType *DepArrayT
7118 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7119 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007120 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007121 AllocType = DepArrayT->getElementType();
7122 }
7123 }
7124 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007125
Douglas Gregorb98b1992009-08-11 05:31:07 +00007126 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7127 E->isGlobalNew(),
7128 /*FIXME:*/E->getLocStart(),
7129 move_arg(PlacementArgs),
7130 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007131 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007132 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007133 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007134 ArraySize.get(),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007135 E->getConstructorLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007136 move_arg(ConstructorArgs),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007137 E->getConstructorRParen());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007138}
Mike Stump1eb44332009-09-09 15:08:12 +00007139
Douglas Gregorb98b1992009-08-11 05:31:07 +00007140template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007141ExprResult
John McCall454feb92009-12-08 09:21:05 +00007142TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007143 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007144 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007145 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007146
Douglas Gregor1af74512010-02-26 00:38:10 +00007147 // Transform the delete operator, if known.
7148 FunctionDecl *OperatorDelete = 0;
7149 if (E->getOperatorDelete()) {
7150 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007151 getDerived().TransformDecl(E->getLocStart(),
7152 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007153 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007154 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007155 }
Sean Huntc3021132010-05-05 15:23:54 +00007156
Douglas Gregorb98b1992009-08-11 05:31:07 +00007157 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007158 Operand.get() == E->getArgument() &&
7159 OperatorDelete == E->getOperatorDelete()) {
7160 // Mark any declarations we need as referenced.
7161 // FIXME: instantiation-specific.
7162 if (OperatorDelete)
7163 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007164
7165 if (!E->getArgument()->isTypeDependent()) {
7166 QualType Destroyed = SemaRef.Context.getBaseElementType(
7167 E->getDestroyedType());
7168 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7169 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7170 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
7171 SemaRef.LookupDestructor(Record));
7172 }
7173 }
7174
John McCall3fa5cae2010-10-26 07:05:15 +00007175 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007176 }
Mike Stump1eb44332009-09-09 15:08:12 +00007177
Douglas Gregorb98b1992009-08-11 05:31:07 +00007178 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7179 E->isGlobalDelete(),
7180 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007181 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007182}
Mike Stump1eb44332009-09-09 15:08:12 +00007183
Douglas Gregorb98b1992009-08-11 05:31:07 +00007184template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007185ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007186TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007187 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007188 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007189 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007190 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007191
John McCallb3d87482010-08-24 05:47:05 +00007192 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007193 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007194 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007195 E->getOperatorLoc(),
7196 E->isArrow()? tok::arrow : tok::period,
7197 ObjectTypePtr,
7198 MayBePseudoDestructor);
7199 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007200 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007201
John McCallb3d87482010-08-24 05:47:05 +00007202 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007203 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7204 if (QualifierLoc) {
7205 QualifierLoc
7206 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7207 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007208 return ExprError();
7209 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007210 CXXScopeSpec SS;
7211 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007212
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007213 PseudoDestructorTypeStorage Destroyed;
7214 if (E->getDestroyedTypeInfo()) {
7215 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007216 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007217 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007218 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007219 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007220 Destroyed = DestroyedTypeInfo;
7221 } else if (ObjectType->isDependentType()) {
7222 // We aren't likely to be able to resolve the identifier down to a type
7223 // now anyway, so just retain the identifier.
7224 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7225 E->getDestroyedTypeLoc());
7226 } else {
7227 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007228 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007229 *E->getDestroyedTypeIdentifier(),
7230 E->getDestroyedTypeLoc(),
7231 /*Scope=*/0,
7232 SS, ObjectTypePtr,
7233 false);
7234 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007235 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007236
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007237 Destroyed
7238 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7239 E->getDestroyedTypeLoc());
7240 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007241
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007242 TypeSourceInfo *ScopeTypeInfo = 0;
7243 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007244 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007245 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007246 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007247 }
Sean Huntc3021132010-05-05 15:23:54 +00007248
John McCall9ae2f072010-08-23 23:25:46 +00007249 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007250 E->getOperatorLoc(),
7251 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007252 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007253 ScopeTypeInfo,
7254 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007255 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007256 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007257}
Mike Stump1eb44332009-09-09 15:08:12 +00007258
Douglas Gregora71d8192009-09-04 17:36:40 +00007259template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007260ExprResult
John McCallba135432009-11-21 08:51:07 +00007261TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007262 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007263 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7264 Sema::LookupOrdinaryName);
7265
7266 // Transform all the decls.
7267 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7268 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007269 NamedDecl *InstD = static_cast<NamedDecl*>(
7270 getDerived().TransformDecl(Old->getNameLoc(),
7271 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007272 if (!InstD) {
7273 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7274 // This can happen because of dependent hiding.
7275 if (isa<UsingShadowDecl>(*I))
7276 continue;
7277 else
John McCallf312b1e2010-08-26 23:41:50 +00007278 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007279 }
John McCallf7a1a742009-11-24 19:00:30 +00007280
7281 // Expand using declarations.
7282 if (isa<UsingDecl>(InstD)) {
7283 UsingDecl *UD = cast<UsingDecl>(InstD);
7284 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7285 E = UD->shadow_end(); I != E; ++I)
7286 R.addDecl(*I);
7287 continue;
7288 }
7289
7290 R.addDecl(InstD);
7291 }
7292
7293 // Resolve a kind, but don't do any further analysis. If it's
7294 // ambiguous, the callee needs to deal with it.
7295 R.resolveKind();
7296
7297 // Rebuild the nested-name qualifier, if present.
7298 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007299 if (Old->getQualifierLoc()) {
7300 NestedNameSpecifierLoc QualifierLoc
7301 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7302 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007303 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007304
Douglas Gregor4c9be892011-02-28 20:01:57 +00007305 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007306 }
7307
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007308 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007309 CXXRecordDecl *NamingClass
7310 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7311 Old->getNameLoc(),
7312 Old->getNamingClass()));
7313 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007314 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007315
Douglas Gregor66c45152010-04-27 16:10:10 +00007316 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007317 }
7318
7319 // If we have no template arguments, it's a normal declaration name.
7320 if (!Old->hasExplicitTemplateArgs())
7321 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7322
7323 // If we have template arguments, rebuild them, then rebuild the
7324 // templateid expression.
7325 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007326 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7327 Old->getNumTemplateArgs(),
7328 TransArgs))
7329 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007330
7331 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7332 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007333}
Mike Stump1eb44332009-09-09 15:08:12 +00007334
Douglas Gregorb98b1992009-08-11 05:31:07 +00007335template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007336ExprResult
John McCall454feb92009-12-08 09:21:05 +00007337TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007338 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7339 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007340 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007341
Douglas Gregorb98b1992009-08-11 05:31:07 +00007342 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007343 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007344 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007345
Mike Stump1eb44332009-09-09 15:08:12 +00007346 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007347 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007348 T,
7349 E->getLocEnd());
7350}
Mike Stump1eb44332009-09-09 15:08:12 +00007351
Douglas Gregorb98b1992009-08-11 05:31:07 +00007352template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007353ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007354TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7355 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7356 if (!LhsT)
7357 return ExprError();
7358
7359 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7360 if (!RhsT)
7361 return ExprError();
7362
7363 if (!getDerived().AlwaysRebuild() &&
7364 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7365 return SemaRef.Owned(E);
7366
7367 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7368 E->getLocStart(),
7369 LhsT, RhsT,
7370 E->getLocEnd());
7371}
7372
7373template<typename Derived>
7374ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007375TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7376 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7377 if (!T)
7378 return ExprError();
7379
7380 if (!getDerived().AlwaysRebuild() &&
7381 T == E->getQueriedTypeSourceInfo())
7382 return SemaRef.Owned(E);
7383
7384 ExprResult SubExpr;
7385 {
7386 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7387 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7388 if (SubExpr.isInvalid())
7389 return ExprError();
7390
7391 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7392 return SemaRef.Owned(E);
7393 }
7394
7395 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7396 E->getLocStart(),
7397 T,
7398 SubExpr.get(),
7399 E->getLocEnd());
7400}
7401
7402template<typename Derived>
7403ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007404TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7405 ExprResult SubExpr;
7406 {
7407 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7408 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7409 if (SubExpr.isInvalid())
7410 return ExprError();
7411
7412 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7413 return SemaRef.Owned(E);
7414 }
7415
7416 return getDerived().RebuildExpressionTrait(
7417 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7418}
7419
7420template<typename Derived>
7421ExprResult
John McCall865d4472009-11-19 22:55:06 +00007422TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007423 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007424 NestedNameSpecifierLoc QualifierLoc
7425 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7426 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007427 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007428
John McCall43fed0d2010-11-12 08:19:04 +00007429 // TODO: If this is a conversion-function-id, verify that the
7430 // destination type name (if present) resolves the same way after
7431 // instantiation as it did in the local scope.
7432
Abramo Bagnara25777432010-08-11 22:01:17 +00007433 DeclarationNameInfo NameInfo
7434 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7435 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007436 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007437
John McCallf7a1a742009-11-24 19:00:30 +00007438 if (!E->hasExplicitTemplateArgs()) {
7439 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007440 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007441 // Note: it is sufficient to compare the Name component of NameInfo:
7442 // if name has not changed, DNLoc has not changed either.
7443 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007444 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007445
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007446 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007447 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007448 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007449 }
John McCalld5532b62009-11-23 01:53:49 +00007450
7451 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007452 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7453 E->getNumTemplateArgs(),
7454 TransArgs))
7455 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007456
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007457 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007458 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007459 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007460}
7461
7462template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007463ExprResult
John McCall454feb92009-12-08 09:21:05 +00007464TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007465 // CXXConstructExprs are always implicit, so when we have a
7466 // 1-argument construction we just transform that argument.
7467 if (E->getNumArgs() == 1 ||
7468 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7469 return getDerived().TransformExpr(E->getArg(0));
7470
Douglas Gregorb98b1992009-08-11 05:31:07 +00007471 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7472
7473 QualType T = getDerived().TransformType(E->getType());
7474 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007475 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007476
7477 CXXConstructorDecl *Constructor
7478 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007479 getDerived().TransformDecl(E->getLocStart(),
7480 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007481 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007482 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007483
Douglas Gregorb98b1992009-08-11 05:31:07 +00007484 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007485 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007486 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7487 &ArgumentChanged))
7488 return ExprError();
7489
Douglas Gregorb98b1992009-08-11 05:31:07 +00007490 if (!getDerived().AlwaysRebuild() &&
7491 T == E->getType() &&
7492 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007493 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007494 // Mark the constructor as referenced.
7495 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00007496 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007497 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007498 }
Mike Stump1eb44332009-09-09 15:08:12 +00007499
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007500 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7501 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007502 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007503 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007504 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007505 E->getConstructionKind(),
7506 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007507}
Mike Stump1eb44332009-09-09 15:08:12 +00007508
Douglas Gregorb98b1992009-08-11 05:31:07 +00007509/// \brief Transform a C++ temporary-binding expression.
7510///
Douglas Gregor51326552009-12-24 18:51:59 +00007511/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7512/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007513template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007514ExprResult
John McCall454feb92009-12-08 09:21:05 +00007515TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007516 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007517}
Mike Stump1eb44332009-09-09 15:08:12 +00007518
John McCall4765fa02010-12-06 08:20:24 +00007519/// \brief Transform a C++ expression that contains cleanups that should
7520/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007521///
John McCall4765fa02010-12-06 08:20:24 +00007522/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007523/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007524template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007525ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007526TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007527 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007528}
Mike Stump1eb44332009-09-09 15:08:12 +00007529
Douglas Gregorb98b1992009-08-11 05:31:07 +00007530template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007531ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007532TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007533 CXXTemporaryObjectExpr *E) {
7534 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7535 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007536 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007537
Douglas Gregorb98b1992009-08-11 05:31:07 +00007538 CXXConstructorDecl *Constructor
7539 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007540 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007541 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007542 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007543 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007544
Douglas Gregorb98b1992009-08-11 05:31:07 +00007545 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007546 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007547 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007548 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7549 &ArgumentChanged))
7550 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007551
Douglas Gregorb98b1992009-08-11 05:31:07 +00007552 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007553 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007554 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007555 !ArgumentChanged) {
7556 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00007557 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007558 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007559 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007560
7561 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7562 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007563 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007564 E->getLocEnd());
7565}
Mike Stump1eb44332009-09-09 15:08:12 +00007566
Douglas Gregorb98b1992009-08-11 05:31:07 +00007567template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007568ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007569TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007570 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007571 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7572 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007573 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007574
Douglas Gregorb98b1992009-08-11 05:31:07 +00007575 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007576 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007577 Args.reserve(E->arg_size());
7578 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7579 &ArgumentChanged))
7580 return ExprError();
7581
Douglas Gregorb98b1992009-08-11 05:31:07 +00007582 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007583 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007584 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007585 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007586
Douglas Gregorb98b1992009-08-11 05:31:07 +00007587 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007588 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007589 E->getLParenLoc(),
7590 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007591 E->getRParenLoc());
7592}
Mike Stump1eb44332009-09-09 15:08:12 +00007593
Douglas Gregorb98b1992009-08-11 05:31:07 +00007594template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007595ExprResult
John McCall865d4472009-11-19 22:55:06 +00007596TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007597 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007598 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007599 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007600 Expr *OldBase;
7601 QualType BaseType;
7602 QualType ObjectType;
7603 if (!E->isImplicitAccess()) {
7604 OldBase = E->getBase();
7605 Base = getDerived().TransformExpr(OldBase);
7606 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007607 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007608
John McCallaa81e162009-12-01 22:10:20 +00007609 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007610 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007611 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007612 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007613 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007614 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007615 ObjectTy,
7616 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007617 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007618 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007619
John McCallb3d87482010-08-24 05:47:05 +00007620 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007621 BaseType = ((Expr*) Base.get())->getType();
7622 } else {
7623 OldBase = 0;
7624 BaseType = getDerived().TransformType(E->getBaseType());
7625 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7626 }
Mike Stump1eb44332009-09-09 15:08:12 +00007627
Douglas Gregor6cd21982009-10-20 05:58:46 +00007628 // Transform the first part of the nested-name-specifier that qualifies
7629 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007630 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007631 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007632 E->getFirstQualifierFoundInScope(),
7633 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007634
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007635 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007636 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007637 QualifierLoc
7638 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7639 ObjectType,
7640 FirstQualifierInScope);
7641 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007642 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007643 }
Mike Stump1eb44332009-09-09 15:08:12 +00007644
John McCall43fed0d2010-11-12 08:19:04 +00007645 // TODO: If this is a conversion-function-id, verify that the
7646 // destination type name (if present) resolves the same way after
7647 // instantiation as it did in the local scope.
7648
Abramo Bagnara25777432010-08-11 22:01:17 +00007649 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007650 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007651 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007652 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007653
John McCallaa81e162009-12-01 22:10:20 +00007654 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007655 // This is a reference to a member without an explicitly-specified
7656 // template argument list. Optimize for this common case.
7657 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007658 Base.get() == OldBase &&
7659 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007660 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007661 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007662 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007663 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007664
John McCall9ae2f072010-08-23 23:25:46 +00007665 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007666 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007667 E->isArrow(),
7668 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007669 QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00007670 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007671 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007672 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007673 }
7674
John McCalld5532b62009-11-23 01:53:49 +00007675 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007676 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7677 E->getNumTemplateArgs(),
7678 TransArgs))
7679 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007680
John McCall9ae2f072010-08-23 23:25:46 +00007681 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007682 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007683 E->isArrow(),
7684 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007685 QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007686 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007687 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007688 &TransArgs);
7689}
7690
7691template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007692ExprResult
John McCall454feb92009-12-08 09:21:05 +00007693TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007694 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007695 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007696 QualType BaseType;
7697 if (!Old->isImplicitAccess()) {
7698 Base = getDerived().TransformExpr(Old->getBase());
7699 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007700 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00007701 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
7702 Old->isArrow());
7703 if (Base.isInvalid())
7704 return ExprError();
7705 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00007706 } else {
7707 BaseType = getDerived().TransformType(Old->getBaseType());
7708 }
John McCall129e2df2009-11-30 22:42:35 +00007709
Douglas Gregor4c9be892011-02-28 20:01:57 +00007710 NestedNameSpecifierLoc QualifierLoc;
7711 if (Old->getQualifierLoc()) {
7712 QualifierLoc
7713 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7714 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007715 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007716 }
7717
Abramo Bagnara25777432010-08-11 22:01:17 +00007718 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007719 Sema::LookupOrdinaryName);
7720
7721 // Transform all the decls.
7722 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7723 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007724 NamedDecl *InstD = static_cast<NamedDecl*>(
7725 getDerived().TransformDecl(Old->getMemberLoc(),
7726 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007727 if (!InstD) {
7728 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7729 // This can happen because of dependent hiding.
7730 if (isa<UsingShadowDecl>(*I))
7731 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007732 else {
7733 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007734 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007735 }
John McCall9f54ad42009-12-10 09:41:52 +00007736 }
John McCall129e2df2009-11-30 22:42:35 +00007737
7738 // Expand using declarations.
7739 if (isa<UsingDecl>(InstD)) {
7740 UsingDecl *UD = cast<UsingDecl>(InstD);
7741 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7742 E = UD->shadow_end(); I != E; ++I)
7743 R.addDecl(*I);
7744 continue;
7745 }
7746
7747 R.addDecl(InstD);
7748 }
7749
7750 R.resolveKind();
7751
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007752 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007753 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007754 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007755 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007756 Old->getMemberLoc(),
7757 Old->getNamingClass()));
7758 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007759 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007760
Douglas Gregor66c45152010-04-27 16:10:10 +00007761 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007762 }
Sean Huntc3021132010-05-05 15:23:54 +00007763
John McCall129e2df2009-11-30 22:42:35 +00007764 TemplateArgumentListInfo TransArgs;
7765 if (Old->hasExplicitTemplateArgs()) {
7766 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7767 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007768 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7769 Old->getNumTemplateArgs(),
7770 TransArgs))
7771 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007772 }
John McCallc2233c52010-01-15 08:34:02 +00007773
7774 // FIXME: to do this check properly, we will need to preserve the
7775 // first-qualifier-in-scope here, just in case we had a dependent
7776 // base (and therefore couldn't do the check) and a
7777 // nested-name-qualifier (and therefore could do the lookup).
7778 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007779
John McCall9ae2f072010-08-23 23:25:46 +00007780 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007781 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007782 Old->getOperatorLoc(),
7783 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007784 QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00007785 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007786 R,
7787 (Old->hasExplicitTemplateArgs()
7788 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007789}
7790
7791template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007792ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007793TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00007794 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00007795 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7796 if (SubExpr.isInvalid())
7797 return ExprError();
7798
7799 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007800 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007801
7802 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7803}
7804
7805template<typename Derived>
7806ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007807TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007808 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7809 if (Pattern.isInvalid())
7810 return ExprError();
7811
7812 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7813 return SemaRef.Owned(E);
7814
Douglas Gregor67fd1252011-01-14 21:20:45 +00007815 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7816 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007817}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007818
7819template<typename Derived>
7820ExprResult
7821TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7822 // If E is not value-dependent, then nothing will change when we transform it.
7823 // Note: This is an instantiation-centric view.
7824 if (!E->isValueDependent())
7825 return SemaRef.Owned(E);
7826
7827 // Note: None of the implementations of TryExpandParameterPacks can ever
7828 // produce a diagnostic when given only a single unexpanded parameter pack,
7829 // so
7830 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7831 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007832 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007833 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007834 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00007835 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00007836 ShouldExpand, RetainExpansion,
7837 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007838 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007839
Douglas Gregor089e8932011-10-10 18:59:29 +00007840 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007841 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00007842
7843 NamedDecl *Pack = E->getPack();
7844 if (!ShouldExpand) {
7845 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
7846 Pack));
7847 if (!Pack)
7848 return ExprError();
7849 }
7850
Douglas Gregoree8aff02011-01-04 17:33:58 +00007851
7852 // We now know the length of the parameter pack, so build a new expression
7853 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00007854 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00007855 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00007856 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007857}
7858
Douglas Gregorbe230c32011-01-03 17:17:50 +00007859template<typename Derived>
7860ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007861TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7862 SubstNonTypeTemplateParmPackExpr *E) {
7863 // Default behavior is to do nothing with this transformation.
7864 return SemaRef.Owned(E);
7865}
7866
7867template<typename Derived>
7868ExprResult
John McCall91a57552011-07-15 05:09:51 +00007869TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7870 SubstNonTypeTemplateParmExpr *E) {
7871 // Default behavior is to do nothing with this transformation.
7872 return SemaRef.Owned(E);
7873}
7874
7875template<typename Derived>
7876ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00007877TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7878 MaterializeTemporaryExpr *E) {
7879 return getDerived().TransformExpr(E->GetTemporaryExpr());
7880}
7881
7882template<typename Derived>
7883ExprResult
John McCall454feb92009-12-08 09:21:05 +00007884TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007885 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007886}
7887
Mike Stump1eb44332009-09-09 15:08:12 +00007888template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007889ExprResult
John McCall454feb92009-12-08 09:21:05 +00007890TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007891 TypeSourceInfo *EncodedTypeInfo
7892 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7893 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007894 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007895
Douglas Gregorb98b1992009-08-11 05:31:07 +00007896 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007897 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007898 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007899
7900 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007901 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007902 E->getRParenLoc());
7903}
Mike Stump1eb44332009-09-09 15:08:12 +00007904
Douglas Gregorb98b1992009-08-11 05:31:07 +00007905template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00007906ExprResult TreeTransform<Derived>::
7907TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7908 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7909 if (result.isInvalid()) return ExprError();
7910 Expr *subExpr = result.take();
7911
7912 if (!getDerived().AlwaysRebuild() &&
7913 subExpr == E->getSubExpr())
7914 return SemaRef.Owned(E);
7915
7916 return SemaRef.Owned(new(SemaRef.Context)
7917 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7918}
7919
7920template<typename Derived>
7921ExprResult TreeTransform<Derived>::
7922TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7923 TypeSourceInfo *TSInfo
7924 = getDerived().TransformType(E->getTypeInfoAsWritten());
7925 if (!TSInfo)
7926 return ExprError();
7927
7928 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7929 if (Result.isInvalid())
7930 return ExprError();
7931
7932 if (!getDerived().AlwaysRebuild() &&
7933 TSInfo == E->getTypeInfoAsWritten() &&
7934 Result.get() == E->getSubExpr())
7935 return SemaRef.Owned(E);
7936
7937 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7938 E->getBridgeKeywordLoc(), TSInfo,
7939 Result.get());
7940}
7941
7942template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007943ExprResult
John McCall454feb92009-12-08 09:21:05 +00007944TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007945 // Transform arguments.
7946 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007947 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007948 Args.reserve(E->getNumArgs());
7949 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7950 &ArgChanged))
7951 return ExprError();
7952
Douglas Gregor92e986e2010-04-22 16:44:27 +00007953 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7954 // Class message: transform the receiver type.
7955 TypeSourceInfo *ReceiverTypeInfo
7956 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7957 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007958 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007959
Douglas Gregor92e986e2010-04-22 16:44:27 +00007960 // If nothing changed, just retain the existing message send.
7961 if (!getDerived().AlwaysRebuild() &&
7962 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007963 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007964
7965 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007966 SmallVector<SourceLocation, 16> SelLocs;
7967 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007968 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7969 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007970 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00007971 E->getMethodDecl(),
7972 E->getLeftLoc(),
7973 move_arg(Args),
7974 E->getRightLoc());
7975 }
7976
7977 // Instance message: transform the receiver
7978 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7979 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007980 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007981 = getDerived().TransformExpr(E->getInstanceReceiver());
7982 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007983 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007984
7985 // If nothing changed, just retain the existing message send.
7986 if (!getDerived().AlwaysRebuild() &&
7987 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007988 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007989
Douglas Gregor92e986e2010-04-22 16:44:27 +00007990 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007991 SmallVector<SourceLocation, 16> SelLocs;
7992 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00007993 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007994 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007995 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00007996 E->getMethodDecl(),
7997 E->getLeftLoc(),
7998 move_arg(Args),
7999 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008000}
8001
Mike Stump1eb44332009-09-09 15:08:12 +00008002template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008003ExprResult
John McCall454feb92009-12-08 09:21:05 +00008004TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008005 return SemaRef.Owned(E);
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>::TransformObjCProtocolExpr(ObjCProtocolExpr *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>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008017 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008018 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008019 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008020 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008021
8022 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008023
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008024 // If nothing changed, just retain the existing expression.
8025 if (!getDerived().AlwaysRebuild() &&
8026 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008027 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008028
John McCall9ae2f072010-08-23 23:25:46 +00008029 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008030 E->getLocation(),
8031 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008032}
8033
Mike Stump1eb44332009-09-09 15:08:12 +00008034template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008035ExprResult
John McCall454feb92009-12-08 09:21:05 +00008036TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008037 // 'super' and types never change. Property never changes. Just
8038 // retain the existing expression.
8039 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008040 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008041
Douglas Gregore3303542010-04-26 20:47:02 +00008042 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008043 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008044 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008045 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008046
Douglas Gregore3303542010-04-26 20:47:02 +00008047 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008048
Douglas Gregore3303542010-04-26 20:47:02 +00008049 // If nothing changed, just retain the existing expression.
8050 if (!getDerived().AlwaysRebuild() &&
8051 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008052 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008053
John McCall12f78a62010-12-02 01:19:52 +00008054 if (E->isExplicitProperty())
8055 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8056 E->getExplicitProperty(),
8057 E->getLocation());
8058
8059 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008060 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008061 E->getImplicitPropertyGetter(),
8062 E->getImplicitPropertySetter(),
8063 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008064}
8065
Mike Stump1eb44332009-09-09 15:08:12 +00008066template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008067ExprResult
John McCall454feb92009-12-08 09:21:05 +00008068TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008069 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008070 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008071 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008072 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008073
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008074 // If nothing changed, just retain the existing expression.
8075 if (!getDerived().AlwaysRebuild() &&
8076 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008077 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008078
John McCall9ae2f072010-08-23 23:25:46 +00008079 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008080 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008081}
8082
Mike Stump1eb44332009-09-09 15:08:12 +00008083template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008084ExprResult
John McCall454feb92009-12-08 09:21:05 +00008085TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008086 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008087 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008088 SubExprs.reserve(E->getNumSubExprs());
8089 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8090 SubExprs, &ArgumentChanged))
8091 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008092
Douglas Gregorb98b1992009-08-11 05:31:07 +00008093 if (!getDerived().AlwaysRebuild() &&
8094 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008095 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008096
Douglas Gregorb98b1992009-08-11 05:31:07 +00008097 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8098 move_arg(SubExprs),
8099 E->getRParenLoc());
8100}
8101
Mike Stump1eb44332009-09-09 15:08:12 +00008102template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008103ExprResult
John McCall454feb92009-12-08 09:21:05 +00008104TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008105 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008106
John McCallc6ac9c32011-02-04 18:33:18 +00008107 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8108 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8109
8110 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008111 // We built a new blockScopeInfo in call to ActOnBlockStart
8112 // in above, CapturesCXXThis need be set here from the block
8113 // expression.
8114 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
8115
Chris Lattner686775d2011-07-20 06:58:45 +00008116 SmallVector<ParmVarDecl*, 4> params;
8117 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008118
8119 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008120 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8121 oldBlock->param_begin(),
8122 oldBlock->param_size(),
8123 0, paramTypes, &params))
Douglas Gregora779d9c2011-01-19 21:32:01 +00008124 return true;
John McCallc6ac9c32011-02-04 18:33:18 +00008125
8126 const FunctionType *exprFunctionType = E->getFunctionType();
8127 QualType exprResultType = exprFunctionType->getResultType();
8128 if (!exprResultType.isNull()) {
8129 if (!exprResultType->isDependentType())
8130 blockScope->ReturnType = exprResultType;
8131 else if (exprResultType != getSema().Context.DependentTy)
8132 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008133 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008134
8135 // If the return type has not been determined yet, leave it as a dependent
8136 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00008137 if (blockScope->ReturnType.isNull())
8138 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00008139
8140 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00008141 if (blockScope->ReturnType->isObjCObjectType()) {
8142 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008143 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00008144 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00008145 return ExprError();
8146 }
John McCall711c52b2011-01-05 12:14:39 +00008147
John McCallc6ac9c32011-02-04 18:33:18 +00008148 QualType functionType = getDerived().RebuildFunctionProtoType(
8149 blockScope->ReturnType,
8150 paramTypes.data(),
8151 paramTypes.size(),
8152 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00008153 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008154 exprFunctionType->getExtInfo());
8155 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008156
8157 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008158 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008159 blockScope->TheDecl->setParams(params);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008160
8161 // If the return type wasn't explicitly set, it will have been marked as a
8162 // dependent type (DependentTy); clear out the return type setting so
8163 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00008164 if (blockScope->ReturnType == getSema().Context.DependentTy)
8165 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00008166
John McCall711c52b2011-01-05 12:14:39 +00008167 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008168 StmtResult body = getDerived().TransformStmt(E->getBody());
8169 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00008170 return ExprError();
8171
John McCallc6ac9c32011-02-04 18:33:18 +00008172#ifndef NDEBUG
8173 // In builds with assertions, make sure that we captured everything we
8174 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008175 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8176 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8177 e = oldBlock->capture_end(); i != e; ++i) {
8178 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008179
Douglas Gregorfc921372011-05-20 15:32:55 +00008180 // Ignore parameter packs.
8181 if (isa<ParmVarDecl>(oldCapture) &&
8182 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8183 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008184
Douglas Gregorfc921372011-05-20 15:32:55 +00008185 VarDecl *newCapture =
8186 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8187 oldCapture));
8188 assert(blockScope->CaptureMap.count(newCapture));
8189 }
John McCallc6ac9c32011-02-04 18:33:18 +00008190 }
8191#endif
8192
8193 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8194 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008195}
8196
Mike Stump1eb44332009-09-09 15:08:12 +00008197template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008198ExprResult
John McCall454feb92009-12-08 09:21:05 +00008199TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008200 ValueDecl *ND
8201 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8202 E->getDecl()));
8203 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00008204 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00008205
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008206 if (!getDerived().AlwaysRebuild() &&
8207 ND == E->getDecl()) {
8208 // Mark it referenced in the new context regardless.
8209 // FIXME: this is a bit instantiation-specific.
8210 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8211
John McCall3fa5cae2010-10-26 07:05:15 +00008212 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008213 }
8214
Abramo Bagnara25777432010-08-11 22:01:17 +00008215 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00008216 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00008217 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008218}
Mike Stump1eb44332009-09-09 15:08:12 +00008219
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008220template<typename Derived>
8221ExprResult
8222TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008223 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008224}
Eli Friedman276b0612011-10-11 02:20:01 +00008225
8226template<typename Derived>
8227ExprResult
8228TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008229 QualType RetTy = getDerived().TransformType(E->getType());
8230 bool ArgumentChanged = false;
8231 ASTOwningVector<Expr*> SubExprs(SemaRef);
8232 SubExprs.reserve(E->getNumSubExprs());
8233 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8234 SubExprs, &ArgumentChanged))
8235 return ExprError();
8236
8237 if (!getDerived().AlwaysRebuild() &&
8238 !ArgumentChanged)
8239 return SemaRef.Owned(E);
8240
8241 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8242 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008243}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008244
Douglas Gregorb98b1992009-08-11 05:31:07 +00008245//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008246// Type reconstruction
8247//===----------------------------------------------------------------------===//
8248
Mike Stump1eb44332009-09-09 15:08:12 +00008249template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008250QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8251 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008252 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008253 getDerived().getBaseEntity());
8254}
8255
Mike Stump1eb44332009-09-09 15:08:12 +00008256template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008257QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8258 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008259 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008260 getDerived().getBaseEntity());
8261}
8262
Mike Stump1eb44332009-09-09 15:08:12 +00008263template<typename Derived>
8264QualType
John McCall85737a72009-10-30 00:06:24 +00008265TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8266 bool WrittenAsLValue,
8267 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008268 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008269 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008270}
8271
8272template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008273QualType
John McCall85737a72009-10-30 00:06:24 +00008274TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8275 QualType ClassType,
8276 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008277 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008278 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008279}
8280
8281template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008282QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008283TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8284 ArrayType::ArraySizeModifier SizeMod,
8285 const llvm::APInt *Size,
8286 Expr *SizeExpr,
8287 unsigned IndexTypeQuals,
8288 SourceRange BracketsRange) {
8289 if (SizeExpr || !Size)
8290 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8291 IndexTypeQuals, BracketsRange,
8292 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008293
8294 QualType Types[] = {
8295 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8296 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8297 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008298 };
8299 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8300 QualType SizeType;
8301 for (unsigned I = 0; I != NumTypes; ++I)
8302 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8303 SizeType = Types[I];
8304 break;
8305 }
Mike Stump1eb44332009-09-09 15:08:12 +00008306
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008307 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8308 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00008309 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008310 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008311 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008312}
Mike Stump1eb44332009-09-09 15:08:12 +00008313
Douglas Gregor577f75a2009-08-04 16:50:30 +00008314template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008315QualType
8316TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008317 ArrayType::ArraySizeModifier SizeMod,
8318 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008319 unsigned IndexTypeQuals,
8320 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008321 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008322 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008323}
8324
8325template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008326QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008327TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008328 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008329 unsigned IndexTypeQuals,
8330 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008331 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008332 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008333}
Mike Stump1eb44332009-09-09 15:08:12 +00008334
Douglas Gregor577f75a2009-08-04 16:50:30 +00008335template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008336QualType
8337TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008338 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008339 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008340 unsigned IndexTypeQuals,
8341 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008342 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008343 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008344 IndexTypeQuals, BracketsRange);
8345}
8346
8347template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008348QualType
8349TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008350 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008351 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008352 unsigned IndexTypeQuals,
8353 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008354 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008355 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008356 IndexTypeQuals, BracketsRange);
8357}
8358
8359template<typename Derived>
8360QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008361 unsigned NumElements,
8362 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008363 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008364 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008365}
Mike Stump1eb44332009-09-09 15:08:12 +00008366
Douglas Gregor577f75a2009-08-04 16:50:30 +00008367template<typename Derived>
8368QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8369 unsigned NumElements,
8370 SourceLocation AttributeLoc) {
8371 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8372 NumElements, true);
8373 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008374 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8375 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008376 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008377}
Mike Stump1eb44332009-09-09 15:08:12 +00008378
Douglas Gregor577f75a2009-08-04 16:50:30 +00008379template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008380QualType
8381TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008382 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008383 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008384 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, 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>
8388QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008389 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008390 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008391 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00008392 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008393 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008394 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008395 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00008396 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008397 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008398 getDerived().getBaseEntity(),
8399 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008400}
Mike Stump1eb44332009-09-09 15:08:12 +00008401
Douglas Gregor577f75a2009-08-04 16:50:30 +00008402template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008403QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8404 return SemaRef.Context.getFunctionNoProtoType(T);
8405}
8406
8407template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008408QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8409 assert(D && "no decl found");
8410 if (D->isInvalidDecl()) return QualType();
8411
Douglas Gregor92e986e2010-04-22 16:44:27 +00008412 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008413 TypeDecl *Ty;
8414 if (isa<UsingDecl>(D)) {
8415 UsingDecl *Using = cast<UsingDecl>(D);
8416 assert(Using->isTypeName() &&
8417 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8418
8419 // A valid resolved using typename decl points to exactly one type decl.
8420 assert(++Using->shadow_begin() == Using->shadow_end());
8421 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008422
John McCalled976492009-12-04 22:46:56 +00008423 } else {
8424 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8425 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8426 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8427 }
8428
8429 return SemaRef.Context.getTypeDeclType(Ty);
8430}
8431
8432template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008433QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8434 SourceLocation Loc) {
8435 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008436}
8437
8438template<typename Derived>
8439QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8440 return SemaRef.Context.getTypeOfType(Underlying);
8441}
8442
8443template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008444QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8445 SourceLocation Loc) {
8446 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008447}
8448
8449template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008450QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8451 UnaryTransformType::UTTKind UKind,
8452 SourceLocation Loc) {
8453 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8454}
8455
8456template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008457QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008458 TemplateName Template,
8459 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008460 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008461 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008462}
Mike Stump1eb44332009-09-09 15:08:12 +00008463
Douglas Gregordcee1a12009-08-06 05:28:30 +00008464template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00008465QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8466 SourceLocation KWLoc) {
8467 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8468}
8469
8470template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008471TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008472TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008473 bool TemplateKW,
8474 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008475 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008476 Template);
8477}
8478
8479template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008480TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008481TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8482 const IdentifierInfo &Name,
8483 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008484 QualType ObjectType,
8485 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008486 UnqualifiedId TemplateName;
8487 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008488 Sema::TemplateTy Template;
8489 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008490 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008491 SS,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008492 TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008493 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008494 /*EnteringContext=*/false,
8495 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008496 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008497}
Mike Stump1eb44332009-09-09 15:08:12 +00008498
Douglas Gregorb98b1992009-08-11 05:31:07 +00008499template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008500TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008501TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008502 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008503 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008504 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008505 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008506 // FIXME: Bogus location information.
8507 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8508 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008509 Sema::TemplateTy Template;
8510 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008511 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008512 SS,
8513 Name,
John McCallb3d87482010-08-24 05:47:05 +00008514 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008515 /*EnteringContext=*/false,
8516 Template);
8517 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008518}
Sean Huntc3021132010-05-05 15:23:54 +00008519
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008520template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008521ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008522TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8523 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008524 Expr *OrigCallee,
8525 Expr *First,
8526 Expr *Second) {
8527 Expr *Callee = OrigCallee->IgnoreParenCasts();
8528 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008529
Douglas Gregorb98b1992009-08-11 05:31:07 +00008530 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008531 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008532 if (!First->getType()->isOverloadableType() &&
8533 !Second->getType()->isOverloadableType())
8534 return getSema().CreateBuiltinArraySubscriptExpr(First,
8535 Callee->getLocStart(),
8536 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008537 } else if (Op == OO_Arrow) {
8538 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008539 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8540 } else if (Second == 0 || isPostIncDec) {
8541 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008542 // The argument is not of overloadable type, so try to create a
8543 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008544 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008545 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008546
John McCall9ae2f072010-08-23 23:25:46 +00008547 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008548 }
8549 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008550 if (!First->getType()->isOverloadableType() &&
8551 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008552 // Neither of the arguments is an overloadable type, so try to
8553 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008554 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008555 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008556 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008557 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008558 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008559
Douglas Gregorb98b1992009-08-11 05:31:07 +00008560 return move(Result);
8561 }
8562 }
Mike Stump1eb44332009-09-09 15:08:12 +00008563
8564 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008565 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008566 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008567
John McCall9ae2f072010-08-23 23:25:46 +00008568 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008569 assert(ULE->requiresADL());
8570
8571 // FIXME: Do we have to check
8572 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008573 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008574 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008575 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008576 }
Mike Stump1eb44332009-09-09 15:08:12 +00008577
Douglas Gregorb98b1992009-08-11 05:31:07 +00008578 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008579 Expr *Args[2] = { First, Second };
8580 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008581
Douglas Gregorb98b1992009-08-11 05:31:07 +00008582 // Create the overloaded operator invocation for unary operators.
8583 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008584 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008585 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008586 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008587 }
Mike Stump1eb44332009-09-09 15:08:12 +00008588
Douglas Gregor5b8968c2011-07-15 16:25:15 +00008589 if (Op == OO_Subscript) {
8590 SourceLocation LBrace;
8591 SourceLocation RBrace;
8592
8593 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8594 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8595 LBrace = SourceLocation::getFromRawEncoding(
8596 NameLoc.CXXOperatorName.BeginOpNameLoc);
8597 RBrace = SourceLocation::getFromRawEncoding(
8598 NameLoc.CXXOperatorName.EndOpNameLoc);
8599 } else {
8600 LBrace = Callee->getLocStart();
8601 RBrace = OpLoc;
8602 }
8603
8604 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8605 First, Second);
8606 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00008607
Douglas Gregorb98b1992009-08-11 05:31:07 +00008608 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008609 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008610 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008611 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8612 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008613 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008614
Mike Stump1eb44332009-09-09 15:08:12 +00008615 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008616}
Mike Stump1eb44332009-09-09 15:08:12 +00008617
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008618template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008619ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008620TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008621 SourceLocation OperatorLoc,
8622 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008623 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008624 TypeSourceInfo *ScopeType,
8625 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008626 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008627 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008628 QualType BaseType = Base->getType();
8629 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008630 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008631 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008632 !BaseType->getAs<PointerType>()->getPointeeType()
8633 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008634 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008635 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008636 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008637 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008638 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008639 /*FIXME?*/true);
8640 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008641
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008642 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008643 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8644 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8645 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8646 NameInfo.setNamedTypeInfo(DestroyedType);
8647
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008648 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008649
John McCall9ae2f072010-08-23 23:25:46 +00008650 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008651 OperatorLoc, isArrow,
8652 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008653 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008654 /*TemplateArgs*/ 0);
8655}
8656
Douglas Gregor577f75a2009-08-04 16:50:30 +00008657} // end namespace clang
8658
8659#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H