blob: 64315ea15d0dc5ed8be71e21cf114179ad86414e [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 }
1294
1295 /// \brief Attach body to a C++0x range-based for statement.
1296 ///
1297 /// By default, performs semantic analysis to finish the new statement.
1298 /// Subclasses may override this routine to provide different behavior.
1299 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1300 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1301 }
1302
John Wiegley28bbe4b2011-04-28 01:08:34 +00001303 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1304 SourceLocation TryLoc,
1305 Stmt *TryBlock,
1306 Stmt *Handler) {
1307 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1308 }
1309
1310 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1311 Expr *FilterExpr,
1312 Stmt *Block) {
1313 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1314 }
1315
1316 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1317 Stmt *Block) {
1318 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1319 }
1320
Douglas Gregorb98b1992009-08-11 05:31:07 +00001321 /// \brief Build a new expression that references a declaration.
1322 ///
1323 /// By default, performs semantic analysis to build the new expression.
1324 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001325 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001326 LookupResult &R,
1327 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001328 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1329 }
1330
1331
1332 /// \brief Build a new expression that references a declaration.
1333 ///
1334 /// By default, performs semantic analysis to build the new expression.
1335 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001336 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001337 ValueDecl *VD,
1338 const DeclarationNameInfo &NameInfo,
1339 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001340 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001341 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001342
1343 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001344
1345 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001346 }
Mike Stump1eb44332009-09-09 15:08:12 +00001347
Douglas Gregorb98b1992009-08-11 05:31:07 +00001348 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001349 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001350 /// By default, performs semantic analysis to build the new expression.
1351 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001352 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001353 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001354 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001355 }
1356
Douglas Gregora71d8192009-09-04 17:36:40 +00001357 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001358 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001359 /// By default, performs semantic analysis to build the new expression.
1360 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001361 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001362 SourceLocation OperatorLoc,
1363 bool isArrow,
1364 CXXScopeSpec &SS,
1365 TypeSourceInfo *ScopeType,
1366 SourceLocation CCLoc,
1367 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001368 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001369
Douglas Gregorb98b1992009-08-11 05:31:07 +00001370 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001371 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001372 /// By default, performs semantic analysis to build the new expression.
1373 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001374 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001375 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001376 Expr *SubExpr) {
1377 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001378 }
Mike Stump1eb44332009-09-09 15:08:12 +00001379
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001380 /// \brief Build a new builtin offsetof expression.
1381 ///
1382 /// By default, performs semantic analysis to build the new expression.
1383 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001384 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001385 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001386 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001387 unsigned NumComponents,
1388 SourceLocation RParenLoc) {
1389 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1390 NumComponents, RParenLoc);
1391 }
Sean Huntc3021132010-05-05 15:23:54 +00001392
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001393 /// \brief Build a new sizeof, alignof or vec_step expression with a
1394 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001395 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001396 /// By default, performs semantic analysis to build the new expression.
1397 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001398 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1399 SourceLocation OpLoc,
1400 UnaryExprOrTypeTrait ExprKind,
1401 SourceRange R) {
1402 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001403 }
1404
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001405 /// \brief Build a new sizeof, alignof or vec step expression with an
1406 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001407 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001408 /// By default, performs semantic analysis to build the new expression.
1409 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001410 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1411 UnaryExprOrTypeTrait ExprKind,
1412 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001413 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001414 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001415 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001416 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001417
Douglas Gregorb98b1992009-08-11 05:31:07 +00001418 return move(Result);
1419 }
Mike Stump1eb44332009-09-09 15:08:12 +00001420
Douglas Gregorb98b1992009-08-11 05:31:07 +00001421 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001422 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001423 /// By default, performs semantic analysis to build the new expression.
1424 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001425 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001426 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001427 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001428 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001429 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1430 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001431 RBracketLoc);
1432 }
1433
1434 /// \brief Build a new call 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 RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001439 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001440 SourceLocation RParenLoc,
1441 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001442 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001443 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001444 }
1445
1446 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001447 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001448 /// By default, performs semantic analysis to build the new expression.
1449 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001450 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001451 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001452 NestedNameSpecifierLoc QualifierLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001453 const DeclarationNameInfo &MemberNameInfo,
1454 ValueDecl *Member,
1455 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001456 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001457 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001458 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001459 // We have a reference to an unnamed field. This is always the
1460 // base of an anonymous struct/union member access, i.e. the
1461 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001462 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001463 assert(Member->getType()->isRecordType() &&
1464 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001465
John Wiegley429bb272011-04-08 18:41:53 +00001466 ExprResult BaseResult =
1467 getSema().PerformObjectMemberConversion(Base,
1468 QualifierLoc.getNestedNameSpecifier(),
1469 FoundDecl, Member);
1470 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001471 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001472 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001473 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001474 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001475 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001476 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001477 cast<FieldDecl>(Member)->getType(),
1478 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001479 return getSema().Owned(ME);
1480 }
Mike Stump1eb44332009-09-09 15:08:12 +00001481
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001482 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001483 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001484
John Wiegley429bb272011-04-08 18:41:53 +00001485 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1486 if (BaseResult.isInvalid())
1487 return ExprError();
1488 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001489 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001490
John McCall6bb80172010-03-30 21:47:33 +00001491 // FIXME: this involves duplicating earlier analysis in a lot of
1492 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001493 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001494 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001495 R.resolveKind();
1496
John McCall9ae2f072010-08-23 23:25:46 +00001497 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001498 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001499 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001500 }
Mike Stump1eb44332009-09-09 15:08:12 +00001501
Douglas Gregorb98b1992009-08-11 05:31:07 +00001502 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001503 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001504 /// By default, performs semantic analysis to build the new expression.
1505 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001506 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001507 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001508 Expr *LHS, Expr *RHS) {
1509 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001510 }
1511
1512 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001513 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 /// By default, performs semantic analysis to build the new expression.
1515 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001516 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001517 SourceLocation QuestionLoc,
1518 Expr *LHS,
1519 SourceLocation ColonLoc,
1520 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001521 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1522 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001523 }
1524
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001526 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001527 /// By default, performs semantic analysis to build the new expression.
1528 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001529 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001530 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001531 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001532 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001533 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001534 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001535 }
Mike Stump1eb44332009-09-09 15:08:12 +00001536
Douglas Gregorb98b1992009-08-11 05:31:07 +00001537 /// \brief Build a new compound literal 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 RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001542 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001543 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001544 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001545 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001546 Init);
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 extended vector element access 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 RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001554 SourceLocation OpLoc,
1555 SourceLocation AccessorLoc,
1556 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001557
John McCall129e2df2009-11-30 22:42:35 +00001558 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001559 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001560 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001561 OpLoc, /*IsArrow*/ false,
1562 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001563 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001564 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 }
Mike Stump1eb44332009-09-09 15:08:12 +00001566
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001568 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001571 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001572 MultiExprArg Inits,
1573 SourceLocation RBraceLoc,
1574 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001575 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001576 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1577 if (Result.isInvalid() || ResultTy->isDependentType())
1578 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001579
Douglas Gregore48319a2009-11-09 17:16:50 +00001580 // Patch in the result type we were given, which may have been computed
1581 // when the initial InitListExpr was built.
1582 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1583 ILE->setType(ResultTy);
1584 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001585 }
Mike Stump1eb44332009-09-09 15:08:12 +00001586
Douglas Gregorb98b1992009-08-11 05:31:07 +00001587 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001588 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001589 /// By default, performs semantic analysis to build the new expression.
1590 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001591 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 MultiExprArg ArrayExprs,
1593 SourceLocation EqualOrColonLoc,
1594 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001595 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001596 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001598 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001599 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001600 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001601
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 ArrayExprs.release();
1603 return move(Result);
1604 }
Mike Stump1eb44332009-09-09 15:08:12 +00001605
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001607 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 /// By default, builds the implicit value initialization without performing
1609 /// any semantic analysis. Subclasses may override this routine to provide
1610 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001611 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001612 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1613 }
Mike Stump1eb44332009-09-09 15:08:12 +00001614
Douglas Gregorb98b1992009-08-11 05:31:07 +00001615 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001616 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 /// By default, performs semantic analysis to build the new expression.
1618 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001619 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001620 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001621 SourceLocation RParenLoc) {
1622 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001623 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001624 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001625 }
1626
1627 /// \brief Build a new expression list in parentheses.
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 RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 MultiExprArg SubExprs,
1633 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001634 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001635 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 }
Mike Stump1eb44332009-09-09 15:08:12 +00001637
Douglas Gregorb98b1992009-08-11 05:31:07 +00001638 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001639 ///
1640 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 /// rather than attempting to map the label statement itself.
1642 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001643 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001644 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001645 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 }
Mike Stump1eb44332009-09-09 15:08:12 +00001647
Douglas Gregorb98b1992009-08-11 05:31:07 +00001648 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001649 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001652 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001653 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001654 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001655 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001656 }
Mike Stump1eb44332009-09-09 15:08:12 +00001657
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 /// \brief Build a new __builtin_choose_expr expression.
1659 ///
1660 /// By default, performs semantic analysis to build the new expression.
1661 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001662 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001663 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 SourceLocation RParenLoc) {
1665 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001666 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 RParenLoc);
1668 }
Mike Stump1eb44332009-09-09 15:08:12 +00001669
Peter Collingbournef111d932011-04-15 00:35:48 +00001670 /// \brief Build a new generic selection expression.
1671 ///
1672 /// By default, performs semantic analysis to build the new expression.
1673 /// Subclasses may override this routine to provide different behavior.
1674 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1675 SourceLocation DefaultLoc,
1676 SourceLocation RParenLoc,
1677 Expr *ControllingExpr,
1678 TypeSourceInfo **Types,
1679 Expr **Exprs,
1680 unsigned NumAssocs) {
1681 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1682 ControllingExpr, Types, Exprs,
1683 NumAssocs);
1684 }
1685
Douglas Gregorb98b1992009-08-11 05:31:07 +00001686 /// \brief Build a new overloaded operator call expression.
1687 ///
1688 /// By default, performs semantic analysis to build the new expression.
1689 /// The semantic analysis provides the behavior of template instantiation,
1690 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001691 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001692 /// argument-dependent lookup, etc. Subclasses may override this routine to
1693 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001694 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001695 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001696 Expr *Callee,
1697 Expr *First,
1698 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001699
1700 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001701 /// reinterpret_cast.
1702 ///
1703 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001704 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001705 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001706 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 Stmt::StmtClass Class,
1708 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001709 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 SourceLocation RAngleLoc,
1711 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001712 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001713 SourceLocation RParenLoc) {
1714 switch (Class) {
1715 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001716 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001717 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001718 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001719
1720 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001721 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001722 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001723 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001724
Douglas Gregorb98b1992009-08-11 05:31:07 +00001725 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001726 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001727 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001728 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001729 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001730
Douglas Gregorb98b1992009-08-11 05:31:07 +00001731 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001732 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001733 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001734 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001735
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001737 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001738 }
Mike Stump1eb44332009-09-09 15:08:12 +00001739
John McCallf312b1e2010-08-26 23:41:50 +00001740 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 }
Mike Stump1eb44332009-09-09 15:08:12 +00001742
Douglas Gregorb98b1992009-08-11 05:31:07 +00001743 /// \brief Build a new C++ static_cast expression.
1744 ///
1745 /// By default, performs semantic analysis to build the new expression.
1746 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001747 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001749 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001750 SourceLocation RAngleLoc,
1751 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001752 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001754 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001755 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001756 SourceRange(LAngleLoc, RAngleLoc),
1757 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001758 }
1759
1760 /// \brief Build a new C++ dynamic_cast expression.
1761 ///
1762 /// By default, performs semantic analysis to build the new expression.
1763 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001764 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001766 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 SourceLocation RAngleLoc,
1768 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001769 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001771 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001772 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001773 SourceRange(LAngleLoc, RAngleLoc),
1774 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 }
1776
1777 /// \brief Build a new C++ reinterpret_cast expression.
1778 ///
1779 /// By default, performs semantic analysis to build the new expression.
1780 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001781 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001783 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784 SourceLocation RAngleLoc,
1785 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001786 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001788 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001789 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001790 SourceRange(LAngleLoc, RAngleLoc),
1791 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 }
1793
1794 /// \brief Build a new C++ const_cast expression.
1795 ///
1796 /// By default, performs semantic analysis to build the new expression.
1797 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001798 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001800 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 SourceLocation RAngleLoc,
1802 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001803 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001805 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001806 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001807 SourceRange(LAngleLoc, RAngleLoc),
1808 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 }
Mike Stump1eb44332009-09-09 15:08:12 +00001810
Douglas Gregorb98b1992009-08-11 05:31:07 +00001811 /// \brief Build a new C++ functional-style cast expression.
1812 ///
1813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001815 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1816 SourceLocation LParenLoc,
1817 Expr *Sub,
1818 SourceLocation RParenLoc) {
1819 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001820 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001821 RParenLoc);
1822 }
Mike Stump1eb44332009-09-09 15:08:12 +00001823
Douglas Gregorb98b1992009-08-11 05:31:07 +00001824 /// \brief Build a new C++ typeid(type) expression.
1825 ///
1826 /// By default, performs semantic analysis to build the new expression.
1827 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001828 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001829 SourceLocation TypeidLoc,
1830 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001831 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001832 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001833 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001834 }
Mike Stump1eb44332009-09-09 15:08:12 +00001835
Francois Pichet01b7c302010-09-08 12:20:18 +00001836
Douglas Gregorb98b1992009-08-11 05:31:07 +00001837 /// \brief Build a new C++ typeid(expr) expression.
1838 ///
1839 /// By default, performs semantic analysis to build the new expression.
1840 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001841 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001842 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001843 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001844 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001845 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001846 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001847 }
1848
Francois Pichet01b7c302010-09-08 12:20:18 +00001849 /// \brief Build a new C++ __uuidof(type) expression.
1850 ///
1851 /// By default, performs semantic analysis to build the new expression.
1852 /// Subclasses may override this routine to provide different behavior.
1853 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1854 SourceLocation TypeidLoc,
1855 TypeSourceInfo *Operand,
1856 SourceLocation RParenLoc) {
1857 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1858 RParenLoc);
1859 }
1860
1861 /// \brief Build a new C++ __uuidof(expr) 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 Expr *Operand,
1868 SourceLocation RParenLoc) {
1869 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1870 RParenLoc);
1871 }
1872
Douglas Gregorb98b1992009-08-11 05:31:07 +00001873 /// \brief Build a new C++ "this" expression.
1874 ///
1875 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001876 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001877 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001878 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001879 QualType ThisType,
1880 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001881 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001882 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1883 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001884 }
1885
1886 /// \brief Build a new C++ throw expression.
1887 ///
1888 /// By default, performs semantic analysis to build the new expression.
1889 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001890 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1891 bool IsThrownVariableInScope) {
1892 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001893 }
1894
1895 /// \brief Build a new C++ default-argument expression.
1896 ///
1897 /// By default, builds a new default-argument expression, which does not
1898 /// require any semantic analysis. Subclasses may override this routine to
1899 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001900 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001901 ParmVarDecl *Param) {
1902 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1903 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001904 }
1905
1906 /// \brief Build a new C++ zero-initialization expression.
1907 ///
1908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001910 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1911 SourceLocation LParenLoc,
1912 SourceLocation RParenLoc) {
1913 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001914 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001915 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001916 }
Mike Stump1eb44332009-09-09 15:08:12 +00001917
Douglas Gregorb98b1992009-08-11 05:31:07 +00001918 /// \brief Build a new C++ "new" expression.
1919 ///
1920 /// By default, performs semantic analysis to build the new expression.
1921 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001922 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001923 bool UseGlobal,
1924 SourceLocation PlacementLParen,
1925 MultiExprArg PlacementArgs,
1926 SourceLocation PlacementRParen,
1927 SourceRange TypeIdParens,
1928 QualType AllocatedType,
1929 TypeSourceInfo *AllocatedTypeInfo,
1930 Expr *ArraySize,
1931 SourceLocation ConstructorLParen,
1932 MultiExprArg ConstructorArgs,
1933 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001934 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 PlacementLParen,
1936 move(PlacementArgs),
1937 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001938 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001939 AllocatedType,
1940 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001941 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001942 ConstructorLParen,
1943 move(ConstructorArgs),
1944 ConstructorRParen);
1945 }
Mike Stump1eb44332009-09-09 15:08:12 +00001946
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 /// \brief Build a new C++ "delete" expression.
1948 ///
1949 /// By default, performs semantic analysis to build the new expression.
1950 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001951 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 bool IsGlobalDelete,
1953 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001954 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001955 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001956 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001957 }
Mike Stump1eb44332009-09-09 15:08:12 +00001958
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 /// \brief Build a new unary type trait 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 RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001964 SourceLocation StartLoc,
1965 TypeSourceInfo *T,
1966 SourceLocation RParenLoc) {
1967 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001968 }
1969
Francois Pichet6ad6f282010-12-07 00:08:36 +00001970 /// \brief Build a new binary type trait expression.
1971 ///
1972 /// By default, performs semantic analysis to build the new expression.
1973 /// Subclasses may override this routine to provide different behavior.
1974 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1975 SourceLocation StartLoc,
1976 TypeSourceInfo *LhsT,
1977 TypeSourceInfo *RhsT,
1978 SourceLocation RParenLoc) {
1979 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1980 }
1981
John Wiegley21ff2e52011-04-28 00:16:57 +00001982 /// \brief Build a new array 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 RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1987 SourceLocation StartLoc,
1988 TypeSourceInfo *TSInfo,
1989 Expr *DimExpr,
1990 SourceLocation RParenLoc) {
1991 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1992 }
1993
John Wiegley55262202011-04-25 06:54:41 +00001994 /// \brief Build a new expression 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 RebuildExpressionTrait(ExpressionTrait Trait,
1999 SourceLocation StartLoc,
2000 Expr *Queried,
2001 SourceLocation RParenLoc) {
2002 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2003 }
2004
Mike Stump1eb44332009-09-09 15:08:12 +00002005 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002006 /// expression.
2007 ///
2008 /// By default, performs semantic analysis to build the new expression.
2009 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002010 ExprResult RebuildDependentScopeDeclRefExpr(
2011 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002012 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002013 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002014 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002015 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002016
2017 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00002018 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002019 *TemplateArgs);
2020
Abramo Bagnara25777432010-08-11 22:01:17 +00002021 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002022 }
2023
2024 /// \brief Build a new template-id expression.
2025 ///
2026 /// By default, performs semantic analysis to build the new expression.
2027 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002028 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00002029 LookupResult &R,
2030 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00002031 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00002032 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002033 }
2034
2035 /// \brief Build a new object-construction expression.
2036 ///
2037 /// By default, performs semantic analysis to build the new expression.
2038 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002039 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002040 SourceLocation Loc,
2041 CXXConstructorDecl *Constructor,
2042 bool IsElidable,
2043 MultiExprArg Args,
2044 bool HadMultipleCandidates,
2045 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002046 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002047 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002048 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002049 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002050 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002051 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002052
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002053 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002054 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002055 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002056 RequiresZeroInit, ConstructKind,
2057 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002058 }
2059
2060 /// \brief Build a new object-construction expression.
2061 ///
2062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002064 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2065 SourceLocation LParenLoc,
2066 MultiExprArg Args,
2067 SourceLocation RParenLoc) {
2068 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002069 LParenLoc,
2070 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002071 RParenLoc);
2072 }
2073
2074 /// \brief Build a new object-construction expression.
2075 ///
2076 /// By default, performs semantic analysis to build the new expression.
2077 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002078 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2079 SourceLocation LParenLoc,
2080 MultiExprArg Args,
2081 SourceLocation RParenLoc) {
2082 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002083 LParenLoc,
2084 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002085 RParenLoc);
2086 }
Mike Stump1eb44332009-09-09 15:08:12 +00002087
Douglas Gregorb98b1992009-08-11 05:31:07 +00002088 /// \brief Build a new member reference expression.
2089 ///
2090 /// By default, performs semantic analysis to build the new expression.
2091 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002092 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002093 QualType BaseType,
2094 bool IsArrow,
2095 SourceLocation OperatorLoc,
2096 NestedNameSpecifierLoc QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00002097 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002098 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002099 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002100 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002101 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002102
John McCall9ae2f072010-08-23 23:25:46 +00002103 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002104 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00002105 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002106 MemberNameInfo,
2107 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002108 }
2109
John McCall129e2df2009-11-30 22:42:35 +00002110 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002111 ///
2112 /// By default, performs semantic analysis to build the new expression.
2113 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002114 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00002115 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00002116 SourceLocation OperatorLoc,
2117 bool IsArrow,
Douglas Gregor4c9be892011-02-28 20:01:57 +00002118 NestedNameSpecifierLoc QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00002119 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00002120 LookupResult &R,
2121 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002122 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002123 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002124
John McCall9ae2f072010-08-23 23:25:46 +00002125 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002126 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00002127 SS, FirstQualifierInScope,
2128 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002129 }
Mike Stump1eb44332009-09-09 15:08:12 +00002130
Sebastian Redl2e156222010-09-10 20:55:43 +00002131 /// \brief Build a new noexcept expression.
2132 ///
2133 /// By default, performs semantic analysis to build the new expression.
2134 /// Subclasses may override this routine to provide different behavior.
2135 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2136 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2137 }
2138
Douglas Gregoree8aff02011-01-04 17:33:58 +00002139 /// \brief Build a new expression to compute the length of a parameter pack.
2140 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2141 SourceLocation PackLoc,
2142 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002143 llvm::Optional<unsigned> Length) {
2144 if (Length)
2145 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2146 OperatorLoc, Pack, PackLoc,
2147 RParenLoc, *Length);
2148
Douglas Gregoree8aff02011-01-04 17:33:58 +00002149 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2150 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002151 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002152 }
2153
Douglas Gregorb98b1992009-08-11 05:31:07 +00002154 /// \brief Build a new Objective-C @encode expression.
2155 ///
2156 /// By default, performs semantic analysis to build the new expression.
2157 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002158 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002159 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002160 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002161 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002162 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002163 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002164
Douglas Gregor92e986e2010-04-22 16:44:27 +00002165 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002166 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002167 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002168 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002169 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002170 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002171 MultiExprArg Args,
2172 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002173 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2174 ReceiverTypeInfo->getType(),
2175 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002176 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002177 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002178 }
2179
2180 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002181 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002182 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002183 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002184 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002185 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002186 MultiExprArg Args,
2187 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002188 return SemaRef.BuildInstanceMessage(Receiver,
2189 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002190 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002191 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002192 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002193 }
2194
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002195 /// \brief Build a new Objective-C ivar reference expression.
2196 ///
2197 /// By default, performs semantic analysis to build the new expression.
2198 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002199 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002200 SourceLocation IvarLoc,
2201 bool IsArrow, bool IsFreeIvar) {
2202 // FIXME: We lose track of the IsFreeIvar bit.
2203 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002204 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002205 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2206 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002207 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002208 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002209 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002210 false);
John Wiegley429bb272011-04-08 18:41:53 +00002211 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002212 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002213
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002214 if (Result.get())
2215 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002216
John Wiegley429bb272011-04-08 18:41:53 +00002217 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002218 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002219 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002220 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002221 /*TemplateArgs=*/0);
2222 }
Douglas Gregore3303542010-04-26 20:47:02 +00002223
2224 /// \brief Build a new Objective-C property reference expression.
2225 ///
2226 /// By default, performs semantic analysis to build the new expression.
2227 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002228 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002229 ObjCPropertyDecl *Property,
2230 SourceLocation PropertyLoc) {
2231 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002232 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002233 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2234 Sema::LookupMemberName);
2235 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002236 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002237 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002238 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002239 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002240 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002241
Douglas Gregore3303542010-04-26 20:47:02 +00002242 if (Result.get())
2243 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002244
John Wiegley429bb272011-04-08 18:41:53 +00002245 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002246 /*FIXME:*/PropertyLoc, IsArrow,
2247 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002248 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002249 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002250 /*TemplateArgs=*/0);
2251 }
Sean Huntc3021132010-05-05 15:23:54 +00002252
John McCall12f78a62010-12-02 01:19:52 +00002253 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002254 ///
2255 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002256 /// Subclasses may override this routine to provide different behavior.
2257 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2258 ObjCMethodDecl *Getter,
2259 ObjCMethodDecl *Setter,
2260 SourceLocation PropertyLoc) {
2261 // Since these expressions can only be value-dependent, we do not
2262 // need to perform semantic analysis again.
2263 return Owned(
2264 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2265 VK_LValue, OK_ObjCProperty,
2266 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002267 }
2268
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002269 /// \brief Build a new Objective-C "isa" expression.
2270 ///
2271 /// By default, performs semantic analysis to build the new expression.
2272 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002273 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002274 bool IsArrow) {
2275 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002276 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002277 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2278 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002279 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002280 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002281 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002282 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002283 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002284
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002285 if (Result.get())
2286 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002287
John Wiegley429bb272011-04-08 18:41:53 +00002288 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002289 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002290 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002291 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002292 /*TemplateArgs=*/0);
2293 }
Sean Huntc3021132010-05-05 15:23:54 +00002294
Douglas Gregorb98b1992009-08-11 05:31:07 +00002295 /// \brief Build a new shuffle vector expression.
2296 ///
2297 /// By default, performs semantic analysis to build the new expression.
2298 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002299 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002300 MultiExprArg SubExprs,
2301 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002302 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002303 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002304 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2305 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2306 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2307 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002308
Douglas Gregorb98b1992009-08-11 05:31:07 +00002309 // Build a reference to the __builtin_shufflevector builtin
2310 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002311 ExprResult Callee
2312 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2313 VK_LValue, BuiltinLoc));
2314 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2315 if (Callee.isInvalid())
2316 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002317
2318 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002319 unsigned NumSubExprs = SubExprs.size();
2320 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002321 ExprResult TheCall = SemaRef.Owned(
2322 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002323 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002324 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002325 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002326 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002327
Douglas Gregorb98b1992009-08-11 05:31:07 +00002328 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002329 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002330 }
John McCall43fed0d2010-11-12 08:19:04 +00002331
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002332 /// \brief Build a new template argument pack expansion.
2333 ///
2334 /// By default, performs semantic analysis to build a new pack expansion
2335 /// for a template argument. Subclasses may override this routine to provide
2336 /// different behavior.
2337 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002338 SourceLocation EllipsisLoc,
2339 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002340 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002341 case TemplateArgument::Expression: {
2342 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002343 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2344 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002345 if (Result.isInvalid())
2346 return TemplateArgumentLoc();
2347
2348 return TemplateArgumentLoc(Result.get(), Result.get());
2349 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002350
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002351 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002352 return TemplateArgumentLoc(TemplateArgument(
2353 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002354 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002355 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002356 Pattern.getTemplateNameLoc(),
2357 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002358
2359 case TemplateArgument::Null:
2360 case TemplateArgument::Integral:
2361 case TemplateArgument::Declaration:
2362 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002363 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002364 llvm_unreachable("Pack expansion pattern has no parameter packs");
2365
2366 case TemplateArgument::Type:
2367 if (TypeSourceInfo *Expansion
2368 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002369 EllipsisLoc,
2370 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002371 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2372 Expansion);
2373 break;
2374 }
2375
2376 return TemplateArgumentLoc();
2377 }
2378
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002379 /// \brief Build a new expression pack expansion.
2380 ///
2381 /// By default, performs semantic analysis to build a new pack expansion
2382 /// for an expression. Subclasses may override this routine to provide
2383 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002384 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2385 llvm::Optional<unsigned> NumExpansions) {
2386 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002387 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002388
2389 /// \brief Build a new atomic operation expression.
2390 ///
2391 /// By default, performs semantic analysis to build the new expression.
2392 /// Subclasses may override this routine to provide different behavior.
2393 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2394 MultiExprArg SubExprs,
2395 QualType RetTy,
2396 AtomicExpr::AtomicOp Op,
2397 SourceLocation RParenLoc) {
2398 // Just create the expression; there is not any interesting semantic
2399 // analysis here because we can't actually build an AtomicExpr until
2400 // we are sure it is semantically sound.
2401 unsigned NumSubExprs = SubExprs.size();
2402 Expr **Subs = (Expr **)SubExprs.release();
2403 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2404 NumSubExprs, RetTy, Op,
2405 RParenLoc);
2406 }
2407
John McCall43fed0d2010-11-12 08:19:04 +00002408private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002409 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2410 QualType ObjectType,
2411 NamedDecl *FirstQualifierInScope,
2412 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002413
2414 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2415 QualType ObjectType,
2416 NamedDecl *FirstQualifierInScope,
2417 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002418};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002419
Douglas Gregor43959a92009-08-20 07:17:43 +00002420template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002421StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002422 if (!S)
2423 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002424
Douglas Gregor43959a92009-08-20 07:17:43 +00002425 switch (S->getStmtClass()) {
2426 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002427
Douglas Gregor43959a92009-08-20 07:17:43 +00002428 // Transform individual statement nodes
2429#define STMT(Node, Parent) \
2430 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002431#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002432#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002433#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002434
Douglas Gregor43959a92009-08-20 07:17:43 +00002435 // Transform expressions by calling TransformExpr.
2436#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002437#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002438#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002439#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002440 {
John McCall60d7b3a2010-08-24 06:29:42 +00002441 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002442 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002443 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002444
John McCall9ae2f072010-08-23 23:25:46 +00002445 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002446 }
Mike Stump1eb44332009-09-09 15:08:12 +00002447 }
2448
John McCall3fa5cae2010-10-26 07:05:15 +00002449 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002450}
Mike Stump1eb44332009-09-09 15:08:12 +00002451
2452
Douglas Gregor670444e2009-08-04 22:27:00 +00002453template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002454ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002455 if (!E)
2456 return SemaRef.Owned(E);
2457
2458 switch (E->getStmtClass()) {
2459 case Stmt::NoStmtClass: break;
2460#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002461#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002462#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002463 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002464#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002465 }
2466
John McCall3fa5cae2010-10-26 07:05:15 +00002467 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002468}
2469
2470template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002471bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2472 unsigned NumInputs,
2473 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002474 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002475 bool *ArgChanged) {
2476 for (unsigned I = 0; I != NumInputs; ++I) {
2477 // If requested, drop call arguments that need to be dropped.
2478 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2479 if (ArgChanged)
2480 *ArgChanged = true;
2481
2482 break;
2483 }
2484
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002485 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2486 Expr *Pattern = Expansion->getPattern();
2487
Chris Lattner686775d2011-07-20 06:58:45 +00002488 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002489 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2490 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2491
2492 // Determine whether the set of unexpanded parameter packs can and should
2493 // be expanded.
2494 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002495 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002496 llvm::Optional<unsigned> OrigNumExpansions
2497 = Expansion->getNumExpansions();
2498 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002499 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2500 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002501 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002502 Expand, RetainExpansion,
2503 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002504 return true;
2505
2506 if (!Expand) {
2507 // The transform has determined that we should perform a simple
2508 // transformation on the pack expansion, producing another pack
2509 // expansion.
2510 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2511 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2512 if (OutPattern.isInvalid())
2513 return true;
2514
2515 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002516 Expansion->getEllipsisLoc(),
2517 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002518 if (Out.isInvalid())
2519 return true;
2520
2521 if (ArgChanged)
2522 *ArgChanged = true;
2523 Outputs.push_back(Out.get());
2524 continue;
2525 }
John McCallc8fc90a2011-07-06 07:30:07 +00002526
2527 // Record right away that the argument was changed. This needs
2528 // to happen even if the array expands to nothing.
2529 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002530
2531 // The transform has determined that we should perform an elementwise
2532 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002533 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002534 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2535 ExprResult Out = getDerived().TransformExpr(Pattern);
2536 if (Out.isInvalid())
2537 return true;
2538
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002539 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002540 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2541 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002542 if (Out.isInvalid())
2543 return true;
2544 }
2545
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002546 Outputs.push_back(Out.get());
2547 }
2548
2549 continue;
2550 }
2551
Douglas Gregoraa165f82011-01-03 19:04:46 +00002552 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2553 if (Result.isInvalid())
2554 return true;
2555
2556 if (Result.get() != Inputs[I] && ArgChanged)
2557 *ArgChanged = true;
2558
2559 Outputs.push_back(Result.get());
2560 }
2561
2562 return false;
2563}
2564
2565template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002566NestedNameSpecifierLoc
2567TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2568 NestedNameSpecifierLoc NNS,
2569 QualType ObjectType,
2570 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002571 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002572 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2573 Qualifier = Qualifier.getPrefix())
2574 Qualifiers.push_back(Qualifier);
2575
2576 CXXScopeSpec SS;
2577 while (!Qualifiers.empty()) {
2578 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2579 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2580
2581 switch (QNNS->getKind()) {
2582 case NestedNameSpecifier::Identifier:
2583 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2584 *QNNS->getAsIdentifier(),
2585 Q.getLocalBeginLoc(),
2586 Q.getLocalEndLoc(),
2587 ObjectType, false, SS,
2588 FirstQualifierInScope, false))
2589 return NestedNameSpecifierLoc();
2590
2591 break;
2592
2593 case NestedNameSpecifier::Namespace: {
2594 NamespaceDecl *NS
2595 = cast_or_null<NamespaceDecl>(
2596 getDerived().TransformDecl(
2597 Q.getLocalBeginLoc(),
2598 QNNS->getAsNamespace()));
2599 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2600 break;
2601 }
2602
2603 case NestedNameSpecifier::NamespaceAlias: {
2604 NamespaceAliasDecl *Alias
2605 = cast_or_null<NamespaceAliasDecl>(
2606 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2607 QNNS->getAsNamespaceAlias()));
2608 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2609 Q.getLocalEndLoc());
2610 break;
2611 }
2612
2613 case NestedNameSpecifier::Global:
2614 // There is no meaningful transformation that one could perform on the
2615 // global scope.
2616 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2617 break;
2618
2619 case NestedNameSpecifier::TypeSpecWithTemplate:
2620 case NestedNameSpecifier::TypeSpec: {
2621 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2622 FirstQualifierInScope, SS);
2623
2624 if (!TL)
2625 return NestedNameSpecifierLoc();
2626
2627 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2628 (SemaRef.getLangOptions().CPlusPlus0x &&
2629 TL.getType()->isEnumeralType())) {
2630 assert(!TL.getType().hasLocalQualifiers() &&
2631 "Can't get cv-qualifiers here");
2632 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2633 Q.getLocalEndLoc());
2634 break;
2635 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002636 // If the nested-name-specifier is an invalid type def, don't emit an
2637 // error because a previous error should have already been emitted.
2638 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2639 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2640 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2641 << TL.getType() << SS.getRange();
2642 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002643 return NestedNameSpecifierLoc();
2644 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002645 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002646
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002647 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002648 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002649 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002650 }
2651
2652 // Don't rebuild the nested-name-specifier if we don't have to.
2653 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2654 !getDerived().AlwaysRebuild())
2655 return NNS;
2656
2657 // If we can re-use the source-location data from the original
2658 // nested-name-specifier, do so.
2659 if (SS.location_size() == NNS.getDataLength() &&
2660 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2661 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2662
2663 // Allocate new nested-name-specifier location information.
2664 return SS.getWithLocInContext(SemaRef.Context);
2665}
2666
2667template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002668DeclarationNameInfo
2669TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002670::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002671 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002672 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002673 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002674
2675 switch (Name.getNameKind()) {
2676 case DeclarationName::Identifier:
2677 case DeclarationName::ObjCZeroArgSelector:
2678 case DeclarationName::ObjCOneArgSelector:
2679 case DeclarationName::ObjCMultiArgSelector:
2680 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002681 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002682 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002683 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002684
Douglas Gregor81499bb2009-09-03 22:13:48 +00002685 case DeclarationName::CXXConstructorName:
2686 case DeclarationName::CXXDestructorName:
2687 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002688 TypeSourceInfo *NewTInfo;
2689 CanQualType NewCanTy;
2690 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002691 NewTInfo = getDerived().TransformType(OldTInfo);
2692 if (!NewTInfo)
2693 return DeclarationNameInfo();
2694 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002695 }
2696 else {
2697 NewTInfo = 0;
2698 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002699 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002700 if (NewT.isNull())
2701 return DeclarationNameInfo();
2702 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2703 }
Mike Stump1eb44332009-09-09 15:08:12 +00002704
Abramo Bagnara25777432010-08-11 22:01:17 +00002705 DeclarationName NewName
2706 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2707 NewCanTy);
2708 DeclarationNameInfo NewNameInfo(NameInfo);
2709 NewNameInfo.setName(NewName);
2710 NewNameInfo.setNamedTypeInfo(NewTInfo);
2711 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002712 }
Mike Stump1eb44332009-09-09 15:08:12 +00002713 }
2714
David Blaikieb219cfc2011-09-23 05:06:16 +00002715 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002716}
2717
2718template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002719TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002720TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2721 TemplateName Name,
2722 SourceLocation NameLoc,
2723 QualType ObjectType,
2724 NamedDecl *FirstQualifierInScope) {
2725 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2726 TemplateDecl *Template = QTN->getTemplateDecl();
2727 assert(Template && "qualified template name must refer to a template");
2728
2729 TemplateDecl *TransTemplate
2730 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2731 Template));
2732 if (!TransTemplate)
2733 return TemplateName();
2734
2735 if (!getDerived().AlwaysRebuild() &&
2736 SS.getScopeRep() == QTN->getQualifier() &&
2737 TransTemplate == Template)
2738 return Name;
2739
2740 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2741 TransTemplate);
2742 }
2743
2744 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2745 if (SS.getScopeRep()) {
2746 // These apply to the scope specifier, not the template.
2747 ObjectType = QualType();
2748 FirstQualifierInScope = 0;
2749 }
2750
2751 if (!getDerived().AlwaysRebuild() &&
2752 SS.getScopeRep() == DTN->getQualifier() &&
2753 ObjectType.isNull())
2754 return Name;
2755
2756 if (DTN->isIdentifier()) {
2757 return getDerived().RebuildTemplateName(SS,
2758 *DTN->getIdentifier(),
2759 NameLoc,
2760 ObjectType,
2761 FirstQualifierInScope);
2762 }
2763
2764 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2765 ObjectType);
2766 }
2767
2768 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2769 TemplateDecl *TransTemplate
2770 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2771 Template));
2772 if (!TransTemplate)
2773 return TemplateName();
2774
2775 if (!getDerived().AlwaysRebuild() &&
2776 TransTemplate == Template)
2777 return Name;
2778
2779 return TemplateName(TransTemplate);
2780 }
2781
2782 if (SubstTemplateTemplateParmPackStorage *SubstPack
2783 = Name.getAsSubstTemplateTemplateParmPack()) {
2784 TemplateTemplateParmDecl *TransParam
2785 = cast_or_null<TemplateTemplateParmDecl>(
2786 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2787 if (!TransParam)
2788 return TemplateName();
2789
2790 if (!getDerived().AlwaysRebuild() &&
2791 TransParam == SubstPack->getParameterPack())
2792 return Name;
2793
2794 return getDerived().RebuildTemplateName(TransParam,
2795 SubstPack->getArgumentPack());
2796 }
2797
2798 // These should be getting filtered out before they reach the AST.
2799 llvm_unreachable("overloaded function decl survived to here");
2800 return TemplateName();
2801}
2802
2803template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002804void TreeTransform<Derived>::InventTemplateArgumentLoc(
2805 const TemplateArgument &Arg,
2806 TemplateArgumentLoc &Output) {
2807 SourceLocation Loc = getDerived().getBaseLocation();
2808 switch (Arg.getKind()) {
2809 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002810 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002811 break;
2812
2813 case TemplateArgument::Type:
2814 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002815 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002816
John McCall833ca992009-10-29 08:12:44 +00002817 break;
2818
Douglas Gregor788cd062009-11-11 01:00:40 +00002819 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002820 case TemplateArgument::TemplateExpansion: {
2821 NestedNameSpecifierLocBuilder Builder;
2822 TemplateName Template = Arg.getAsTemplate();
2823 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2824 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2825 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2826 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2827
2828 if (Arg.getKind() == TemplateArgument::Template)
2829 Output = TemplateArgumentLoc(Arg,
2830 Builder.getWithLocInContext(SemaRef.Context),
2831 Loc);
2832 else
2833 Output = TemplateArgumentLoc(Arg,
2834 Builder.getWithLocInContext(SemaRef.Context),
2835 Loc, Loc);
2836
Douglas Gregor788cd062009-11-11 01:00:40 +00002837 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002838 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002839
John McCall833ca992009-10-29 08:12:44 +00002840 case TemplateArgument::Expression:
2841 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2842 break;
2843
2844 case TemplateArgument::Declaration:
2845 case TemplateArgument::Integral:
2846 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002847 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002848 break;
2849 }
2850}
2851
2852template<typename Derived>
2853bool TreeTransform<Derived>::TransformTemplateArgument(
2854 const TemplateArgumentLoc &Input,
2855 TemplateArgumentLoc &Output) {
2856 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002857 switch (Arg.getKind()) {
2858 case TemplateArgument::Null:
2859 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002860 Output = Input;
2861 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002862
Douglas Gregor670444e2009-08-04 22:27:00 +00002863 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002864 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002865 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002866 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002867
2868 DI = getDerived().TransformType(DI);
2869 if (!DI) return true;
2870
2871 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2872 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002873 }
Mike Stump1eb44332009-09-09 15:08:12 +00002874
Douglas Gregor670444e2009-08-04 22:27:00 +00002875 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002876 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002877 DeclarationName Name;
2878 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2879 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002880 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002881 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002882 if (!D) return true;
2883
John McCall828bff22009-10-29 18:45:58 +00002884 Expr *SourceExpr = Input.getSourceDeclExpression();
2885 if (SourceExpr) {
2886 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002887 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002888 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002889 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002890 }
2891
2892 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002893 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002894 }
Mike Stump1eb44332009-09-09 15:08:12 +00002895
Douglas Gregor788cd062009-11-11 01:00:40 +00002896 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002897 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2898 if (QualifierLoc) {
2899 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2900 if (!QualifierLoc)
2901 return true;
2902 }
2903
Douglas Gregor1d752d72011-03-02 18:46:51 +00002904 CXXScopeSpec SS;
2905 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002906 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002907 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2908 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002909 if (Template.isNull())
2910 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002911
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002912 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002913 Input.getTemplateNameLoc());
2914 return false;
2915 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002916
2917 case TemplateArgument::TemplateExpansion:
2918 llvm_unreachable("Caller should expand pack expansions");
2919
Douglas Gregor670444e2009-08-04 22:27:00 +00002920 case TemplateArgument::Expression: {
2921 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002922 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002923 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002924
John McCall833ca992009-10-29 08:12:44 +00002925 Expr *InputExpr = Input.getSourceExpression();
2926 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2927
Chris Lattner223de242011-04-25 20:37:58 +00002928 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall833ca992009-10-29 08:12:44 +00002929 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002930 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002931 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002932 }
Mike Stump1eb44332009-09-09 15:08:12 +00002933
Douglas Gregor670444e2009-08-04 22:27:00 +00002934 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00002935 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00002936 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002937 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002938 AEnd = Arg.pack_end();
2939 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002940
John McCall833ca992009-10-29 08:12:44 +00002941 // FIXME: preserve source information here when we start
2942 // caring about parameter packs.
2943
John McCall828bff22009-10-29 18:45:58 +00002944 TemplateArgumentLoc InputArg;
2945 TemplateArgumentLoc OutputArg;
2946 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2947 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002948 return true;
2949
John McCall828bff22009-10-29 18:45:58 +00002950 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002951 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002952
2953 TemplateArgument *TransformedArgsPtr
2954 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2955 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2956 TransformedArgsPtr);
2957 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2958 TransformedArgs.size()),
2959 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002960 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002961 }
2962 }
Mike Stump1eb44332009-09-09 15:08:12 +00002963
Douglas Gregor670444e2009-08-04 22:27:00 +00002964 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002965 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002966}
2967
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002968/// \brief Iterator adaptor that invents template argument location information
2969/// for each of the template arguments in its underlying iterator.
2970template<typename Derived, typename InputIterator>
2971class TemplateArgumentLocInventIterator {
2972 TreeTransform<Derived> &Self;
2973 InputIterator Iter;
2974
2975public:
2976 typedef TemplateArgumentLoc value_type;
2977 typedef TemplateArgumentLoc reference;
2978 typedef typename std::iterator_traits<InputIterator>::difference_type
2979 difference_type;
2980 typedef std::input_iterator_tag iterator_category;
2981
2982 class pointer {
2983 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002984
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002985 public:
2986 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2987
2988 const TemplateArgumentLoc *operator->() const { return &Arg; }
2989 };
2990
2991 TemplateArgumentLocInventIterator() { }
2992
2993 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2994 InputIterator Iter)
2995 : Self(Self), Iter(Iter) { }
2996
2997 TemplateArgumentLocInventIterator &operator++() {
2998 ++Iter;
2999 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003000 }
3001
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003002 TemplateArgumentLocInventIterator operator++(int) {
3003 TemplateArgumentLocInventIterator Old(*this);
3004 ++(*this);
3005 return Old;
3006 }
3007
3008 reference operator*() const {
3009 TemplateArgumentLoc Result;
3010 Self.InventTemplateArgumentLoc(*Iter, Result);
3011 return Result;
3012 }
3013
3014 pointer operator->() const { return pointer(**this); }
3015
3016 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3017 const TemplateArgumentLocInventIterator &Y) {
3018 return X.Iter == Y.Iter;
3019 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003020
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003021 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3022 const TemplateArgumentLocInventIterator &Y) {
3023 return X.Iter != Y.Iter;
3024 }
3025};
3026
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003027template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003028template<typename InputIterator>
3029bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3030 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003031 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003032 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003033 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003034 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003035
3036 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3037 // Unpack argument packs, which we translate them into separate
3038 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003039 // FIXME: We could do much better if we could guarantee that the
3040 // TemplateArgumentLocInfo for the pack expansion would be usable for
3041 // all of the template arguments in the argument pack.
3042 typedef TemplateArgumentLocInventIterator<Derived,
3043 TemplateArgument::pack_iterator>
3044 PackLocIterator;
3045 if (TransformTemplateArguments(PackLocIterator(*this,
3046 In.getArgument().pack_begin()),
3047 PackLocIterator(*this,
3048 In.getArgument().pack_end()),
3049 Outputs))
3050 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003051
3052 continue;
3053 }
3054
3055 if (In.getArgument().isPackExpansion()) {
3056 // We have a pack expansion, for which we will be substituting into
3057 // the pattern.
3058 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003059 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003060 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003061 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3062 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003063
Chris Lattner686775d2011-07-20 06:58:45 +00003064 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003065 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3066 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3067
3068 // Determine whether the set of unexpanded parameter packs can and should
3069 // be expanded.
3070 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003071 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003072 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003073 if (getDerived().TryExpandParameterPacks(Ellipsis,
3074 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003075 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003076 Expand,
3077 RetainExpansion,
3078 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003079 return true;
3080
3081 if (!Expand) {
3082 // The transform has determined that we should perform a simple
3083 // transformation on the pack expansion, producing another pack
3084 // expansion.
3085 TemplateArgumentLoc OutPattern;
3086 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3087 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3088 return true;
3089
Douglas Gregorcded4f62011-01-14 17:04:44 +00003090 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3091 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003092 if (Out.getArgument().isNull())
3093 return true;
3094
3095 Outputs.addArgument(Out);
3096 continue;
3097 }
3098
3099 // The transform has determined that we should perform an elementwise
3100 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003101 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003102 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3103
3104 if (getDerived().TransformTemplateArgument(Pattern, Out))
3105 return true;
3106
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003107 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003108 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3109 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003110 if (Out.getArgument().isNull())
3111 return true;
3112 }
3113
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003114 Outputs.addArgument(Out);
3115 }
3116
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003117 // If we're supposed to retain a pack expansion, do so by temporarily
3118 // forgetting the partially-substituted parameter pack.
3119 if (RetainExpansion) {
3120 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3121
3122 if (getDerived().TransformTemplateArgument(Pattern, Out))
3123 return true;
3124
Douglas Gregorcded4f62011-01-14 17:04:44 +00003125 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3126 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003127 if (Out.getArgument().isNull())
3128 return true;
3129
3130 Outputs.addArgument(Out);
3131 }
Douglas Gregord3731192011-01-10 07:32:04 +00003132
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003133 continue;
3134 }
3135
3136 // The simple case:
3137 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003138 return true;
3139
3140 Outputs.addArgument(Out);
3141 }
3142
3143 return false;
3144
3145}
3146
Douglas Gregor577f75a2009-08-04 16:50:30 +00003147//===----------------------------------------------------------------------===//
3148// Type transformation
3149//===----------------------------------------------------------------------===//
3150
3151template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003152QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003153 if (getDerived().AlreadyTransformed(T))
3154 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003155
John McCalla2becad2009-10-21 00:40:46 +00003156 // Temporary workaround. All of these transformations should
3157 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003158 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3159 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003160
John McCall43fed0d2010-11-12 08:19:04 +00003161 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003162
John McCalla2becad2009-10-21 00:40:46 +00003163 if (!NewDI)
3164 return QualType();
3165
3166 return NewDI->getType();
3167}
3168
3169template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003170TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00003171 if (getDerived().AlreadyTransformed(DI->getType()))
3172 return DI;
3173
3174 TypeLocBuilder TLB;
3175
3176 TypeLoc TL = DI->getTypeLoc();
3177 TLB.reserve(TL.getFullDataSize());
3178
John McCall43fed0d2010-11-12 08:19:04 +00003179 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003180 if (Result.isNull())
3181 return 0;
3182
John McCalla93c9342009-12-07 02:54:59 +00003183 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003184}
3185
3186template<typename Derived>
3187QualType
John McCall43fed0d2010-11-12 08:19:04 +00003188TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003189 switch (T.getTypeLocClass()) {
3190#define ABSTRACT_TYPELOC(CLASS, PARENT)
3191#define TYPELOC(CLASS, PARENT) \
3192 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003193 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003194#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003195 }
Mike Stump1eb44332009-09-09 15:08:12 +00003196
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003197 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003198 return QualType();
3199}
3200
3201/// FIXME: By default, this routine adds type qualifiers only to types
3202/// that can have qualifiers, and silently suppresses those qualifiers
3203/// that are not permitted (e.g., qualifiers on reference or function
3204/// types). This is the right thing for template instantiation, but
3205/// probably not for other clients.
3206template<typename Derived>
3207QualType
3208TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003209 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003210 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003211
John McCall43fed0d2010-11-12 08:19:04 +00003212 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003213 if (Result.isNull())
3214 return QualType();
3215
3216 // Silently suppress qualifiers if the result type can't be qualified.
3217 // FIXME: this is the right thing for template instantiation, but
3218 // probably not for other clients.
3219 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003220 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003221
John McCallf85e1932011-06-15 23:02:42 +00003222 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003223 // resulting type.
3224 if (Quals.hasObjCLifetime()) {
3225 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3226 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003227 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003228 // Objective-C ARC:
3229 // A lifetime qualifier applied to a substituted template parameter
3230 // overrides the lifetime qualifier from the template argument.
3231 if (const SubstTemplateTypeParmType *SubstTypeParam
3232 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3233 QualType Replacement = SubstTypeParam->getReplacementType();
3234 Qualifiers Qs = Replacement.getQualifiers();
3235 Qs.removeObjCLifetime();
3236 Replacement
3237 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3238 Qs);
3239 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3240 SubstTypeParam->getReplacedParameter(),
3241 Replacement);
3242 TLB.TypeWasModifiedSafely(Result);
3243 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003244 // Otherwise, complain about the addition of a qualifier to an
3245 // already-qualified type.
3246 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003247 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003248 << Result << R;
3249
Douglas Gregore559ca12011-06-17 22:11:49 +00003250 Quals.removeObjCLifetime();
3251 }
3252 }
3253 }
John McCall28654742010-06-05 06:41:15 +00003254 if (!Quals.empty()) {
3255 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3256 TLB.push<QualifiedTypeLoc>(Result);
3257 // No location information to preserve.
3258 }
John McCalla2becad2009-10-21 00:40:46 +00003259
3260 return Result;
3261}
3262
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003263template<typename Derived>
3264TypeLoc
3265TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3266 QualType ObjectType,
3267 NamedDecl *UnqualLookup,
3268 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003269 QualType T = TL.getType();
3270 if (getDerived().AlreadyTransformed(T))
3271 return TL;
3272
3273 TypeLocBuilder TLB;
3274 QualType Result;
3275
3276 if (isa<TemplateSpecializationType>(T)) {
3277 TemplateSpecializationTypeLoc SpecTL
3278 = cast<TemplateSpecializationTypeLoc>(TL);
3279
3280 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003281 getDerived().TransformTemplateName(SS,
3282 SpecTL.getTypePtr()->getTemplateName(),
3283 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003284 ObjectType, UnqualLookup);
3285 if (Template.isNull())
3286 return TypeLoc();
3287
3288 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3289 Template);
3290 } else if (isa<DependentTemplateSpecializationType>(T)) {
3291 DependentTemplateSpecializationTypeLoc SpecTL
3292 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3293
Douglas Gregora88f09f2011-02-28 17:23:35 +00003294 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003295 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003296 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003297 SpecTL.getNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003298 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003299 if (Template.isNull())
3300 return TypeLoc();
3301
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003302 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003303 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003304 Template,
3305 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003306 } else {
3307 // Nothing special needs to be done for these.
3308 Result = getDerived().TransformType(TLB, TL);
3309 }
3310
3311 if (Result.isNull())
3312 return TypeLoc();
3313
3314 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3315}
3316
Douglas Gregorb71d8212011-03-02 18:32:08 +00003317template<typename Derived>
3318TypeSourceInfo *
3319TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3320 QualType ObjectType,
3321 NamedDecl *UnqualLookup,
3322 CXXScopeSpec &SS) {
3323 // FIXME: Painfully copy-paste from the above!
3324
3325 QualType T = TSInfo->getType();
3326 if (getDerived().AlreadyTransformed(T))
3327 return TSInfo;
3328
3329 TypeLocBuilder TLB;
3330 QualType Result;
3331
3332 TypeLoc TL = TSInfo->getTypeLoc();
3333 if (isa<TemplateSpecializationType>(T)) {
3334 TemplateSpecializationTypeLoc SpecTL
3335 = cast<TemplateSpecializationTypeLoc>(TL);
3336
3337 TemplateName Template
3338 = getDerived().TransformTemplateName(SS,
3339 SpecTL.getTypePtr()->getTemplateName(),
3340 SpecTL.getTemplateNameLoc(),
3341 ObjectType, UnqualLookup);
3342 if (Template.isNull())
3343 return 0;
3344
3345 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3346 Template);
3347 } else if (isa<DependentTemplateSpecializationType>(T)) {
3348 DependentTemplateSpecializationTypeLoc SpecTL
3349 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3350
3351 TemplateName Template
3352 = getDerived().RebuildTemplateName(SS,
3353 *SpecTL.getTypePtr()->getIdentifier(),
3354 SpecTL.getNameLoc(),
3355 ObjectType, UnqualLookup);
3356 if (Template.isNull())
3357 return 0;
3358
3359 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3360 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003361 Template,
3362 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003363 } else {
3364 // Nothing special needs to be done for these.
3365 Result = getDerived().TransformType(TLB, TL);
3366 }
3367
3368 if (Result.isNull())
3369 return 0;
3370
3371 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3372}
3373
John McCalla2becad2009-10-21 00:40:46 +00003374template <class TyLoc> static inline
3375QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3376 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3377 NewT.setNameLoc(T.getNameLoc());
3378 return T.getType();
3379}
3380
John McCalla2becad2009-10-21 00:40:46 +00003381template<typename Derived>
3382QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003383 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003384 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3385 NewT.setBuiltinLoc(T.getBuiltinLoc());
3386 if (T.needsExtraLocalData())
3387 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3388 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003389}
Mike Stump1eb44332009-09-09 15:08:12 +00003390
Douglas Gregor577f75a2009-08-04 16:50:30 +00003391template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003392QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003393 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003394 // FIXME: recurse?
3395 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003396}
Mike Stump1eb44332009-09-09 15:08:12 +00003397
Douglas Gregor577f75a2009-08-04 16:50:30 +00003398template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003399QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003400 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003401 QualType PointeeType
3402 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003403 if (PointeeType.isNull())
3404 return QualType();
3405
3406 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003407 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003408 // A dependent pointer type 'T *' has is being transformed such
3409 // that an Objective-C class type is being replaced for 'T'. The
3410 // resulting pointer type is an ObjCObjectPointerType, not a
3411 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003412 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003413
John McCallc12c5bb2010-05-15 11:32:37 +00003414 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3415 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003416 return Result;
3417 }
John McCall43fed0d2010-11-12 08:19:04 +00003418
Douglas Gregor92e986e2010-04-22 16:44:27 +00003419 if (getDerived().AlwaysRebuild() ||
3420 PointeeType != TL.getPointeeLoc().getType()) {
3421 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3422 if (Result.isNull())
3423 return QualType();
3424 }
John McCallf85e1932011-06-15 23:02:42 +00003425
3426 // Objective-C ARC can add lifetime qualifiers to the type that we're
3427 // pointing to.
3428 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3429
Douglas Gregor92e986e2010-04-22 16:44:27 +00003430 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3431 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003432 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003433}
Mike Stump1eb44332009-09-09 15:08:12 +00003434
3435template<typename Derived>
3436QualType
John McCalla2becad2009-10-21 00:40:46 +00003437TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003438 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003439 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003440 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3441 if (PointeeType.isNull())
3442 return QualType();
3443
3444 QualType Result = TL.getType();
3445 if (getDerived().AlwaysRebuild() ||
3446 PointeeType != TL.getPointeeLoc().getType()) {
3447 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003448 TL.getSigilLoc());
3449 if (Result.isNull())
3450 return QualType();
3451 }
3452
Douglas Gregor39968ad2010-04-22 16:50:51 +00003453 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003454 NewT.setSigilLoc(TL.getSigilLoc());
3455 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003456}
3457
John McCall85737a72009-10-30 00:06:24 +00003458/// Transforms a reference type. Note that somewhat paradoxically we
3459/// don't care whether the type itself is an l-value type or an r-value
3460/// type; we only care if the type was *written* as an l-value type
3461/// or an r-value type.
3462template<typename Derived>
3463QualType
3464TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003465 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003466 const ReferenceType *T = TL.getTypePtr();
3467
3468 // Note that this works with the pointee-as-written.
3469 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3470 if (PointeeType.isNull())
3471 return QualType();
3472
3473 QualType Result = TL.getType();
3474 if (getDerived().AlwaysRebuild() ||
3475 PointeeType != T->getPointeeTypeAsWritten()) {
3476 Result = getDerived().RebuildReferenceType(PointeeType,
3477 T->isSpelledAsLValue(),
3478 TL.getSigilLoc());
3479 if (Result.isNull())
3480 return QualType();
3481 }
3482
John McCallf85e1932011-06-15 23:02:42 +00003483 // Objective-C ARC can add lifetime qualifiers to the type that we're
3484 // referring to.
3485 TLB.TypeWasModifiedSafely(
3486 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3487
John McCall85737a72009-10-30 00:06:24 +00003488 // r-value references can be rebuilt as l-value references.
3489 ReferenceTypeLoc NewTL;
3490 if (isa<LValueReferenceType>(Result))
3491 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3492 else
3493 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3494 NewTL.setSigilLoc(TL.getSigilLoc());
3495
3496 return Result;
3497}
3498
Mike Stump1eb44332009-09-09 15:08:12 +00003499template<typename Derived>
3500QualType
John McCalla2becad2009-10-21 00:40:46 +00003501TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003502 LValueReferenceTypeLoc TL) {
3503 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003504}
3505
Mike Stump1eb44332009-09-09 15:08:12 +00003506template<typename Derived>
3507QualType
John McCalla2becad2009-10-21 00:40:46 +00003508TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003509 RValueReferenceTypeLoc TL) {
3510 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003511}
Mike Stump1eb44332009-09-09 15:08:12 +00003512
Douglas Gregor577f75a2009-08-04 16:50:30 +00003513template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003514QualType
John McCalla2becad2009-10-21 00:40:46 +00003515TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003516 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003517 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003518 if (PointeeType.isNull())
3519 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003520
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003521 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3522 TypeSourceInfo* NewClsTInfo = 0;
3523 if (OldClsTInfo) {
3524 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3525 if (!NewClsTInfo)
3526 return QualType();
3527 }
3528
3529 const MemberPointerType *T = TL.getTypePtr();
3530 QualType OldClsType = QualType(T->getClass(), 0);
3531 QualType NewClsType;
3532 if (NewClsTInfo)
3533 NewClsType = NewClsTInfo->getType();
3534 else {
3535 NewClsType = getDerived().TransformType(OldClsType);
3536 if (NewClsType.isNull())
3537 return QualType();
3538 }
Mike Stump1eb44332009-09-09 15:08:12 +00003539
John McCalla2becad2009-10-21 00:40:46 +00003540 QualType Result = TL.getType();
3541 if (getDerived().AlwaysRebuild() ||
3542 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003543 NewClsType != OldClsType) {
3544 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003545 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003546 if (Result.isNull())
3547 return QualType();
3548 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003549
John McCalla2becad2009-10-21 00:40:46 +00003550 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3551 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003552 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003553
3554 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003555}
3556
Mike Stump1eb44332009-09-09 15:08:12 +00003557template<typename Derived>
3558QualType
John McCalla2becad2009-10-21 00:40:46 +00003559TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003560 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003561 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003562 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003563 if (ElementType.isNull())
3564 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003565
John McCalla2becad2009-10-21 00:40:46 +00003566 QualType Result = TL.getType();
3567 if (getDerived().AlwaysRebuild() ||
3568 ElementType != T->getElementType()) {
3569 Result = getDerived().RebuildConstantArrayType(ElementType,
3570 T->getSizeModifier(),
3571 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003572 T->getIndexTypeCVRQualifiers(),
3573 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003574 if (Result.isNull())
3575 return QualType();
3576 }
Sean Huntc3021132010-05-05 15:23:54 +00003577
John McCalla2becad2009-10-21 00:40:46 +00003578 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3579 NewTL.setLBracketLoc(TL.getLBracketLoc());
3580 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003581
John McCalla2becad2009-10-21 00:40:46 +00003582 Expr *Size = TL.getSizeExpr();
3583 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003584 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003585 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3586 }
3587 NewTL.setSizeExpr(Size);
3588
3589 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003590}
Mike Stump1eb44332009-09-09 15:08:12 +00003591
Douglas Gregor577f75a2009-08-04 16:50:30 +00003592template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003593QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003594 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003595 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003596 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003597 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003598 if (ElementType.isNull())
3599 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003600
John McCalla2becad2009-10-21 00:40:46 +00003601 QualType Result = TL.getType();
3602 if (getDerived().AlwaysRebuild() ||
3603 ElementType != T->getElementType()) {
3604 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003605 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003606 T->getIndexTypeCVRQualifiers(),
3607 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003608 if (Result.isNull())
3609 return QualType();
3610 }
Sean Huntc3021132010-05-05 15:23:54 +00003611
John McCalla2becad2009-10-21 00:40:46 +00003612 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3613 NewTL.setLBracketLoc(TL.getLBracketLoc());
3614 NewTL.setRBracketLoc(TL.getRBracketLoc());
3615 NewTL.setSizeExpr(0);
3616
3617 return Result;
3618}
3619
3620template<typename Derived>
3621QualType
3622TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003623 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003624 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003625 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3626 if (ElementType.isNull())
3627 return QualType();
3628
3629 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003630 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003631
John McCall60d7b3a2010-08-24 06:29:42 +00003632 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003633 = getDerived().TransformExpr(T->getSizeExpr());
3634 if (SizeResult.isInvalid())
3635 return QualType();
3636
John McCall9ae2f072010-08-23 23:25:46 +00003637 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003638
3639 QualType Result = TL.getType();
3640 if (getDerived().AlwaysRebuild() ||
3641 ElementType != T->getElementType() ||
3642 Size != T->getSizeExpr()) {
3643 Result = getDerived().RebuildVariableArrayType(ElementType,
3644 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003645 Size,
John McCalla2becad2009-10-21 00:40:46 +00003646 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003647 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003648 if (Result.isNull())
3649 return QualType();
3650 }
Sean Huntc3021132010-05-05 15:23:54 +00003651
John McCalla2becad2009-10-21 00:40:46 +00003652 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3653 NewTL.setLBracketLoc(TL.getLBracketLoc());
3654 NewTL.setRBracketLoc(TL.getRBracketLoc());
3655 NewTL.setSizeExpr(Size);
3656
3657 return Result;
3658}
3659
3660template<typename Derived>
3661QualType
3662TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003663 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003664 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003665 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3666 if (ElementType.isNull())
3667 return QualType();
3668
3669 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003670 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003671
John McCall3b657512011-01-19 10:06:00 +00003672 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3673 Expr *origSize = TL.getSizeExpr();
3674 if (!origSize) origSize = T->getSizeExpr();
3675
3676 ExprResult sizeResult
3677 = getDerived().TransformExpr(origSize);
3678 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003679 return QualType();
3680
John McCall3b657512011-01-19 10:06:00 +00003681 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003682
3683 QualType Result = TL.getType();
3684 if (getDerived().AlwaysRebuild() ||
3685 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003686 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003687 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3688 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003689 size,
John McCalla2becad2009-10-21 00:40:46 +00003690 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003691 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003692 if (Result.isNull())
3693 return QualType();
3694 }
John McCalla2becad2009-10-21 00:40:46 +00003695
3696 // We might have any sort of array type now, but fortunately they
3697 // all have the same location layout.
3698 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3699 NewTL.setLBracketLoc(TL.getLBracketLoc());
3700 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003701 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003702
3703 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003704}
Mike Stump1eb44332009-09-09 15:08:12 +00003705
3706template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003707QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003708 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003709 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003710 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003711
3712 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003713 QualType ElementType = getDerived().TransformType(T->getElementType());
3714 if (ElementType.isNull())
3715 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003716
Douglas Gregor670444e2009-08-04 22:27:00 +00003717 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003718 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003719
John McCall60d7b3a2010-08-24 06:29:42 +00003720 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003721 if (Size.isInvalid())
3722 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003723
John McCalla2becad2009-10-21 00:40:46 +00003724 QualType Result = TL.getType();
3725 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003726 ElementType != T->getElementType() ||
3727 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003728 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003729 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003730 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003731 if (Result.isNull())
3732 return QualType();
3733 }
John McCalla2becad2009-10-21 00:40:46 +00003734
3735 // Result might be dependent or not.
3736 if (isa<DependentSizedExtVectorType>(Result)) {
3737 DependentSizedExtVectorTypeLoc NewTL
3738 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3739 NewTL.setNameLoc(TL.getNameLoc());
3740 } else {
3741 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3742 NewTL.setNameLoc(TL.getNameLoc());
3743 }
3744
3745 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003746}
Mike Stump1eb44332009-09-09 15:08:12 +00003747
3748template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003749QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003750 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003751 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003752 QualType ElementType = getDerived().TransformType(T->getElementType());
3753 if (ElementType.isNull())
3754 return QualType();
3755
John McCalla2becad2009-10-21 00:40:46 +00003756 QualType Result = TL.getType();
3757 if (getDerived().AlwaysRebuild() ||
3758 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003759 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003760 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003761 if (Result.isNull())
3762 return QualType();
3763 }
Sean Huntc3021132010-05-05 15:23:54 +00003764
John McCalla2becad2009-10-21 00:40:46 +00003765 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3766 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003767
John McCalla2becad2009-10-21 00:40:46 +00003768 return Result;
3769}
3770
3771template<typename Derived>
3772QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003773 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003774 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003775 QualType ElementType = getDerived().TransformType(T->getElementType());
3776 if (ElementType.isNull())
3777 return QualType();
3778
3779 QualType Result = TL.getType();
3780 if (getDerived().AlwaysRebuild() ||
3781 ElementType != T->getElementType()) {
3782 Result = getDerived().RebuildExtVectorType(ElementType,
3783 T->getNumElements(),
3784 /*FIXME*/ SourceLocation());
3785 if (Result.isNull())
3786 return QualType();
3787 }
Sean Huntc3021132010-05-05 15:23:54 +00003788
John McCalla2becad2009-10-21 00:40:46 +00003789 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3790 NewTL.setNameLoc(TL.getNameLoc());
3791
3792 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003793}
Mike Stump1eb44332009-09-09 15:08:12 +00003794
3795template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003796ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003797TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003798 int indexAdjustment,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003799 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003800 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003801 TypeSourceInfo *NewDI = 0;
3802
3803 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3804 // If we're substituting into a pack expansion type and we know the
3805 TypeLoc OldTL = OldDI->getTypeLoc();
3806 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3807
3808 TypeLocBuilder TLB;
3809 TypeLoc NewTL = OldDI->getTypeLoc();
3810 TLB.reserve(NewTL.getFullDataSize());
3811
3812 QualType Result = getDerived().TransformType(TLB,
3813 OldExpansionTL.getPatternLoc());
3814 if (Result.isNull())
3815 return 0;
3816
3817 Result = RebuildPackExpansionType(Result,
3818 OldExpansionTL.getPatternLoc().getSourceRange(),
3819 OldExpansionTL.getEllipsisLoc(),
3820 NumExpansions);
3821 if (Result.isNull())
3822 return 0;
3823
3824 PackExpansionTypeLoc NewExpansionTL
3825 = TLB.push<PackExpansionTypeLoc>(Result);
3826 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3827 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3828 } else
3829 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003830 if (!NewDI)
3831 return 0;
3832
John McCallfb44de92011-05-01 22:35:37 +00003833 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003834 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003835
3836 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3837 OldParm->getDeclContext(),
3838 OldParm->getInnerLocStart(),
3839 OldParm->getLocation(),
3840 OldParm->getIdentifier(),
3841 NewDI->getType(),
3842 NewDI,
3843 OldParm->getStorageClass(),
3844 OldParm->getStorageClassAsWritten(),
3845 /* DefArg */ NULL);
3846 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3847 OldParm->getFunctionScopeIndex() + indexAdjustment);
3848 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003849}
3850
3851template<typename Derived>
3852bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003853 TransformFunctionTypeParams(SourceLocation Loc,
3854 ParmVarDecl **Params, unsigned NumParams,
3855 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003856 SmallVectorImpl<QualType> &OutParamTypes,
3857 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003858 int indexAdjustment = 0;
3859
Douglas Gregora009b592011-01-07 00:20:55 +00003860 for (unsigned i = 0; i != NumParams; ++i) {
3861 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003862 assert(OldParm->getFunctionScopeIndex() == i);
3863
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003864 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003865 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003866 if (OldParm->isParameterPack()) {
3867 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003868 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003869
Douglas Gregor603cfb42011-01-05 23:12:31 +00003870 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003871 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3872 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3873 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3874 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003875 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3876
Douglas Gregor603cfb42011-01-05 23:12:31 +00003877 // Determine whether we should expand the parameter packs.
3878 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003879 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003880 llvm::Optional<unsigned> OrigNumExpansions
3881 = ExpansionTL.getTypePtr()->getNumExpansions();
3882 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003883 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3884 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003885 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003886 ShouldExpand,
3887 RetainExpansion,
3888 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003889 return true;
3890 }
3891
3892 if (ShouldExpand) {
3893 // Expand the function parameter pack into multiple, separate
3894 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003895 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003896 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003897 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3898 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003899 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003900 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003901 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003902 if (!NewParm)
3903 return true;
3904
Douglas Gregora009b592011-01-07 00:20:55 +00003905 OutParamTypes.push_back(NewParm->getType());
3906 if (PVars)
3907 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003908 }
Douglas Gregord3731192011-01-10 07:32:04 +00003909
3910 // If we're supposed to retain a pack expansion, do so by temporarily
3911 // forgetting the partially-substituted parameter pack.
3912 if (RetainExpansion) {
3913 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3914 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003915 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003916 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003917 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003918 if (!NewParm)
3919 return true;
3920
3921 OutParamTypes.push_back(NewParm->getType());
3922 if (PVars)
3923 PVars->push_back(NewParm);
3924 }
3925
John McCallfb44de92011-05-01 22:35:37 +00003926 // The next parameter should have the same adjustment as the
3927 // last thing we pushed, but we post-incremented indexAdjustment
3928 // on every push. Also, if we push nothing, the adjustment should
3929 // go down by one.
3930 indexAdjustment--;
3931
Douglas Gregor603cfb42011-01-05 23:12:31 +00003932 // We're done with the pack expansion.
3933 continue;
3934 }
3935
3936 // We'll substitute the parameter now without expanding the pack
3937 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003938 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3939 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003940 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003941 NumExpansions);
3942 } else {
3943 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003944 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003945 llvm::Optional<unsigned>());
Douglas Gregor603cfb42011-01-05 23:12:31 +00003946 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003947
John McCall21ef0fa2010-03-11 09:03:00 +00003948 if (!NewParm)
3949 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003950
Douglas Gregora009b592011-01-07 00:20:55 +00003951 OutParamTypes.push_back(NewParm->getType());
3952 if (PVars)
3953 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003954 continue;
3955 }
John McCall21ef0fa2010-03-11 09:03:00 +00003956
3957 // Deal with the possibility that we don't have a parameter
3958 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003959 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003960 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003961 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003962 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003963 if (const PackExpansionType *Expansion
3964 = dyn_cast<PackExpansionType>(OldType)) {
3965 // We have a function parameter pack that may need to be expanded.
3966 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00003967 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003968 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3969
3970 // Determine whether we should expand the parameter packs.
3971 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003972 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003973 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003974 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003975 ShouldExpand,
3976 RetainExpansion,
3977 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003978 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003979 }
3980
3981 if (ShouldExpand) {
3982 // Expand the function parameter pack into multiple, separate
3983 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003984 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003985 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3986 QualType NewType = getDerived().TransformType(Pattern);
3987 if (NewType.isNull())
3988 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003989
Douglas Gregora009b592011-01-07 00:20:55 +00003990 OutParamTypes.push_back(NewType);
3991 if (PVars)
3992 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003993 }
3994
3995 // We're done with the pack expansion.
3996 continue;
3997 }
3998
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003999 // If we're supposed to retain a pack expansion, do so by temporarily
4000 // forgetting the partially-substituted parameter pack.
4001 if (RetainExpansion) {
4002 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4003 QualType NewType = getDerived().TransformType(Pattern);
4004 if (NewType.isNull())
4005 return true;
4006
4007 OutParamTypes.push_back(NewType);
4008 if (PVars)
4009 PVars->push_back(0);
4010 }
Douglas Gregord3731192011-01-10 07:32:04 +00004011
Douglas Gregor603cfb42011-01-05 23:12:31 +00004012 // We'll substitute the parameter now without expanding the pack
4013 // expansion.
4014 OldType = Expansion->getPattern();
4015 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004016 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4017 NewType = getDerived().TransformType(OldType);
4018 } else {
4019 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004020 }
4021
Douglas Gregor603cfb42011-01-05 23:12:31 +00004022 if (NewType.isNull())
4023 return true;
4024
4025 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004026 NewType = getSema().Context.getPackExpansionType(NewType,
4027 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004028
Douglas Gregora009b592011-01-07 00:20:55 +00004029 OutParamTypes.push_back(NewType);
4030 if (PVars)
4031 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004032 }
4033
John McCallfb44de92011-05-01 22:35:37 +00004034#ifndef NDEBUG
4035 if (PVars) {
4036 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4037 if (ParmVarDecl *parm = (*PVars)[i])
4038 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004039 }
John McCallfb44de92011-05-01 22:35:37 +00004040#endif
4041
4042 return false;
4043}
John McCall21ef0fa2010-03-11 09:03:00 +00004044
4045template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004046QualType
John McCalla2becad2009-10-21 00:40:46 +00004047TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004048 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004049 // Transform the parameters and return type.
4050 //
4051 // We instantiate in source order, with the return type first followed by
4052 // the parameters, because users tend to expect this (even if they shouldn't
4053 // rely on it!).
4054 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004055 // When the function has a trailing return type, we instantiate the
4056 // parameters before the return type, since the return type can then refer
4057 // to the parameters themselves (via decltype, sizeof, etc.).
4058 //
Chris Lattner686775d2011-07-20 06:58:45 +00004059 SmallVector<QualType, 4> ParamTypes;
4060 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004061 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004062
Douglas Gregordab60ad2010-10-01 18:44:50 +00004063 QualType ResultType;
4064
4065 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004066 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4067 TL.getParmArray(),
4068 TL.getNumArgs(),
4069 TL.getTypePtr()->arg_type_begin(),
4070 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004071 return QualType();
4072
4073 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4074 if (ResultType.isNull())
4075 return QualType();
4076 }
4077 else {
4078 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4079 if (ResultType.isNull())
4080 return QualType();
4081
Douglas Gregora009b592011-01-07 00:20:55 +00004082 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4083 TL.getParmArray(),
4084 TL.getNumArgs(),
4085 TL.getTypePtr()->arg_type_begin(),
4086 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004087 return QualType();
4088 }
4089
John McCalla2becad2009-10-21 00:40:46 +00004090 QualType Result = TL.getType();
4091 if (getDerived().AlwaysRebuild() ||
4092 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004093 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004094 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4095 Result = getDerived().RebuildFunctionProtoType(ResultType,
4096 ParamTypes.data(),
4097 ParamTypes.size(),
4098 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004099 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004100 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004101 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004102 if (Result.isNull())
4103 return QualType();
4104 }
Mike Stump1eb44332009-09-09 15:08:12 +00004105
John McCalla2becad2009-10-21 00:40:46 +00004106 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004107 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4108 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004109 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004110 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4111 NewTL.setArg(i, ParamDecls[i]);
4112
4113 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004114}
Mike Stump1eb44332009-09-09 15:08:12 +00004115
Douglas Gregor577f75a2009-08-04 16:50:30 +00004116template<typename Derived>
4117QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004118 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004119 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004120 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004121 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4122 if (ResultType.isNull())
4123 return QualType();
4124
4125 QualType Result = TL.getType();
4126 if (getDerived().AlwaysRebuild() ||
4127 ResultType != T->getResultType())
4128 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4129
4130 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004131 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4132 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004133 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004134
4135 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004136}
Mike Stump1eb44332009-09-09 15:08:12 +00004137
John McCalled976492009-12-04 22:46:56 +00004138template<typename Derived> QualType
4139TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004140 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004141 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004142 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004143 if (!D)
4144 return QualType();
4145
4146 QualType Result = TL.getType();
4147 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4148 Result = getDerived().RebuildUnresolvedUsingType(D);
4149 if (Result.isNull())
4150 return QualType();
4151 }
4152
4153 // We might get an arbitrary type spec type back. We should at
4154 // least always get a type spec type, though.
4155 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4156 NewTL.setNameLoc(TL.getNameLoc());
4157
4158 return Result;
4159}
4160
Douglas Gregor577f75a2009-08-04 16:50:30 +00004161template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004162QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004163 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004164 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004165 TypedefNameDecl *Typedef
4166 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4167 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004168 if (!Typedef)
4169 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004170
John McCalla2becad2009-10-21 00:40:46 +00004171 QualType Result = TL.getType();
4172 if (getDerived().AlwaysRebuild() ||
4173 Typedef != T->getDecl()) {
4174 Result = getDerived().RebuildTypedefType(Typedef);
4175 if (Result.isNull())
4176 return QualType();
4177 }
Mike Stump1eb44332009-09-09 15:08:12 +00004178
John McCalla2becad2009-10-21 00:40:46 +00004179 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4180 NewTL.setNameLoc(TL.getNameLoc());
4181
4182 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004183}
Mike Stump1eb44332009-09-09 15:08:12 +00004184
Douglas Gregor577f75a2009-08-04 16:50:30 +00004185template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004186QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004187 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004188 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004189 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004190
John McCall60d7b3a2010-08-24 06:29:42 +00004191 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004192 if (E.isInvalid())
4193 return QualType();
4194
John McCalla2becad2009-10-21 00:40:46 +00004195 QualType Result = TL.getType();
4196 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004197 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004198 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004199 if (Result.isNull())
4200 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004201 }
John McCalla2becad2009-10-21 00:40:46 +00004202 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004203
John McCalla2becad2009-10-21 00:40:46 +00004204 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004205 NewTL.setTypeofLoc(TL.getTypeofLoc());
4206 NewTL.setLParenLoc(TL.getLParenLoc());
4207 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004208
4209 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004210}
Mike Stump1eb44332009-09-09 15:08:12 +00004211
4212template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004213QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004214 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004215 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4216 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4217 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004218 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004219
John McCalla2becad2009-10-21 00:40:46 +00004220 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004221 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4222 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004223 if (Result.isNull())
4224 return QualType();
4225 }
Mike Stump1eb44332009-09-09 15:08:12 +00004226
John McCalla2becad2009-10-21 00:40:46 +00004227 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004228 NewTL.setTypeofLoc(TL.getTypeofLoc());
4229 NewTL.setLParenLoc(TL.getLParenLoc());
4230 NewTL.setRParenLoc(TL.getRParenLoc());
4231 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004232
4233 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004234}
Mike Stump1eb44332009-09-09 15:08:12 +00004235
4236template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004237QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004238 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004239 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004240
Douglas Gregor670444e2009-08-04 22:27:00 +00004241 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004242 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004243
John McCall60d7b3a2010-08-24 06:29:42 +00004244 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004245 if (E.isInvalid())
4246 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004247
John McCalla2becad2009-10-21 00:40:46 +00004248 QualType Result = TL.getType();
4249 if (getDerived().AlwaysRebuild() ||
4250 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004251 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004252 if (Result.isNull())
4253 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004254 }
John McCalla2becad2009-10-21 00:40:46 +00004255 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004256
John McCalla2becad2009-10-21 00:40:46 +00004257 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4258 NewTL.setNameLoc(TL.getNameLoc());
4259
4260 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004261}
4262
4263template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004264QualType TreeTransform<Derived>::TransformUnaryTransformType(
4265 TypeLocBuilder &TLB,
4266 UnaryTransformTypeLoc TL) {
4267 QualType Result = TL.getType();
4268 if (Result->isDependentType()) {
4269 const UnaryTransformType *T = TL.getTypePtr();
4270 QualType NewBase =
4271 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4272 Result = getDerived().RebuildUnaryTransformType(NewBase,
4273 T->getUTTKind(),
4274 TL.getKWLoc());
4275 if (Result.isNull())
4276 return QualType();
4277 }
4278
4279 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4280 NewTL.setKWLoc(TL.getKWLoc());
4281 NewTL.setParensRange(TL.getParensRange());
4282 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4283 return Result;
4284}
4285
4286template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004287QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4288 AutoTypeLoc TL) {
4289 const AutoType *T = TL.getTypePtr();
4290 QualType OldDeduced = T->getDeducedType();
4291 QualType NewDeduced;
4292 if (!OldDeduced.isNull()) {
4293 NewDeduced = getDerived().TransformType(OldDeduced);
4294 if (NewDeduced.isNull())
4295 return QualType();
4296 }
4297
4298 QualType Result = TL.getType();
4299 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4300 Result = getDerived().RebuildAutoType(NewDeduced);
4301 if (Result.isNull())
4302 return QualType();
4303 }
4304
4305 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4306 NewTL.setNameLoc(TL.getNameLoc());
4307
4308 return Result;
4309}
4310
4311template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004312QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004313 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004314 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004315 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004316 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4317 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004318 if (!Record)
4319 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004320
John McCalla2becad2009-10-21 00:40:46 +00004321 QualType Result = TL.getType();
4322 if (getDerived().AlwaysRebuild() ||
4323 Record != T->getDecl()) {
4324 Result = getDerived().RebuildRecordType(Record);
4325 if (Result.isNull())
4326 return QualType();
4327 }
Mike Stump1eb44332009-09-09 15:08:12 +00004328
John McCalla2becad2009-10-21 00:40:46 +00004329 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4330 NewTL.setNameLoc(TL.getNameLoc());
4331
4332 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004333}
Mike Stump1eb44332009-09-09 15:08:12 +00004334
4335template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004336QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004337 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004338 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004339 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004340 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4341 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004342 if (!Enum)
4343 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004344
John McCalla2becad2009-10-21 00:40:46 +00004345 QualType Result = TL.getType();
4346 if (getDerived().AlwaysRebuild() ||
4347 Enum != T->getDecl()) {
4348 Result = getDerived().RebuildEnumType(Enum);
4349 if (Result.isNull())
4350 return QualType();
4351 }
Mike Stump1eb44332009-09-09 15:08:12 +00004352
John McCalla2becad2009-10-21 00:40:46 +00004353 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4354 NewTL.setNameLoc(TL.getNameLoc());
4355
4356 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004357}
John McCall7da24312009-09-05 00:15:47 +00004358
John McCall3cb0ebd2010-03-10 03:28:59 +00004359template<typename Derived>
4360QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4361 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004362 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004363 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4364 TL.getTypePtr()->getDecl());
4365 if (!D) return QualType();
4366
4367 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4368 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4369 return T;
4370}
4371
Douglas Gregor577f75a2009-08-04 16:50:30 +00004372template<typename Derived>
4373QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004374 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004375 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004376 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004377}
4378
Mike Stump1eb44332009-09-09 15:08:12 +00004379template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004380QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004381 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004382 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004383 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4384
4385 // Substitute into the replacement type, which itself might involve something
4386 // that needs to be transformed. This only tends to occur with default
4387 // template arguments of template template parameters.
4388 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4389 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4390 if (Replacement.isNull())
4391 return QualType();
4392
4393 // Always canonicalize the replacement type.
4394 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4395 QualType Result
4396 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4397 Replacement);
4398
4399 // Propagate type-source information.
4400 SubstTemplateTypeParmTypeLoc NewTL
4401 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4402 NewTL.setNameLoc(TL.getNameLoc());
4403 return Result;
4404
John McCall49a832b2009-10-18 09:09:24 +00004405}
4406
4407template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004408QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4409 TypeLocBuilder &TLB,
4410 SubstTemplateTypeParmPackTypeLoc TL) {
4411 return TransformTypeSpecType(TLB, TL);
4412}
4413
4414template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004415QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004416 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004417 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004418 const TemplateSpecializationType *T = TL.getTypePtr();
4419
Douglas Gregor1d752d72011-03-02 18:46:51 +00004420 // The nested-name-specifier never matters in a TemplateSpecializationType,
4421 // because we can't have a dependent nested-name-specifier anyway.
4422 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004423 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004424 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4425 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004426 if (Template.isNull())
4427 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004428
John McCall43fed0d2010-11-12 08:19:04 +00004429 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4430}
4431
Eli Friedmanb001de72011-10-06 23:00:33 +00004432template<typename Derived>
4433QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4434 AtomicTypeLoc TL) {
4435 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4436 if (ValueType.isNull())
4437 return QualType();
4438
4439 QualType Result = TL.getType();
4440 if (getDerived().AlwaysRebuild() ||
4441 ValueType != TL.getValueLoc().getType()) {
4442 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4443 if (Result.isNull())
4444 return QualType();
4445 }
4446
4447 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4448 NewTL.setKWLoc(TL.getKWLoc());
4449 NewTL.setLParenLoc(TL.getLParenLoc());
4450 NewTL.setRParenLoc(TL.getRParenLoc());
4451
4452 return Result;
4453}
4454
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004455namespace {
4456 /// \brief Simple iterator that traverses the template arguments in a
4457 /// container that provides a \c getArgLoc() member function.
4458 ///
4459 /// This iterator is intended to be used with the iterator form of
4460 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4461 template<typename ArgLocContainer>
4462 class TemplateArgumentLocContainerIterator {
4463 ArgLocContainer *Container;
4464 unsigned Index;
4465
4466 public:
4467 typedef TemplateArgumentLoc value_type;
4468 typedef TemplateArgumentLoc reference;
4469 typedef int difference_type;
4470 typedef std::input_iterator_tag iterator_category;
4471
4472 class pointer {
4473 TemplateArgumentLoc Arg;
4474
4475 public:
4476 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4477
4478 const TemplateArgumentLoc *operator->() const {
4479 return &Arg;
4480 }
4481 };
4482
4483
4484 TemplateArgumentLocContainerIterator() {}
4485
4486 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4487 unsigned Index)
4488 : Container(&Container), Index(Index) { }
4489
4490 TemplateArgumentLocContainerIterator &operator++() {
4491 ++Index;
4492 return *this;
4493 }
4494
4495 TemplateArgumentLocContainerIterator operator++(int) {
4496 TemplateArgumentLocContainerIterator Old(*this);
4497 ++(*this);
4498 return Old;
4499 }
4500
4501 TemplateArgumentLoc operator*() const {
4502 return Container->getArgLoc(Index);
4503 }
4504
4505 pointer operator->() const {
4506 return pointer(Container->getArgLoc(Index));
4507 }
4508
4509 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004510 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004511 return X.Container == Y.Container && X.Index == Y.Index;
4512 }
4513
4514 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004515 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004516 return !(X == Y);
4517 }
4518 };
4519}
4520
4521
John McCall43fed0d2010-11-12 08:19:04 +00004522template <typename Derived>
4523QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4524 TypeLocBuilder &TLB,
4525 TemplateSpecializationTypeLoc TL,
4526 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004527 TemplateArgumentListInfo NewTemplateArgs;
4528 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4529 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004530 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4531 ArgIterator;
4532 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4533 ArgIterator(TL, TL.getNumArgs()),
4534 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004535 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004536
John McCall833ca992009-10-29 08:12:44 +00004537 // FIXME: maybe don't rebuild if all the template arguments are the same.
4538
4539 QualType Result =
4540 getDerived().RebuildTemplateSpecializationType(Template,
4541 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004542 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004543
4544 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004545 // Specializations of template template parameters are represented as
4546 // TemplateSpecializationTypes, and substitution of type alias templates
4547 // within a dependent context can transform them into
4548 // DependentTemplateSpecializationTypes.
4549 if (isa<DependentTemplateSpecializationType>(Result)) {
4550 DependentTemplateSpecializationTypeLoc NewTL
4551 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4552 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4553 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4554 NewTL.setNameLoc(TL.getTemplateNameLoc());
4555 NewTL.setLAngleLoc(TL.getLAngleLoc());
4556 NewTL.setRAngleLoc(TL.getRAngleLoc());
4557 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4558 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4559 return Result;
4560 }
4561
John McCall833ca992009-10-29 08:12:44 +00004562 TemplateSpecializationTypeLoc NewTL
4563 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4564 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4565 NewTL.setLAngleLoc(TL.getLAngleLoc());
4566 NewTL.setRAngleLoc(TL.getRAngleLoc());
4567 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4568 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004569 }
Mike Stump1eb44332009-09-09 15:08:12 +00004570
John McCall833ca992009-10-29 08:12:44 +00004571 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004572}
Mike Stump1eb44332009-09-09 15:08:12 +00004573
Douglas Gregora88f09f2011-02-28 17:23:35 +00004574template <typename Derived>
4575QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4576 TypeLocBuilder &TLB,
4577 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004578 TemplateName Template,
4579 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004580 TemplateArgumentListInfo NewTemplateArgs;
4581 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4582 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4583 typedef TemplateArgumentLocContainerIterator<
4584 DependentTemplateSpecializationTypeLoc> ArgIterator;
4585 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4586 ArgIterator(TL, TL.getNumArgs()),
4587 NewTemplateArgs))
4588 return QualType();
4589
4590 // FIXME: maybe don't rebuild if all the template arguments are the same.
4591
4592 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4593 QualType Result
4594 = getSema().Context.getDependentTemplateSpecializationType(
4595 TL.getTypePtr()->getKeyword(),
4596 DTN->getQualifier(),
4597 DTN->getIdentifier(),
4598 NewTemplateArgs);
4599
4600 DependentTemplateSpecializationTypeLoc NewTL
4601 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4602 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004603
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004604 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregora88f09f2011-02-28 17:23:35 +00004605 NewTL.setNameLoc(TL.getNameLoc());
4606 NewTL.setLAngleLoc(TL.getLAngleLoc());
4607 NewTL.setRAngleLoc(TL.getRAngleLoc());
4608 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4609 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4610 return Result;
4611 }
4612
4613 QualType Result
4614 = getDerived().RebuildTemplateSpecializationType(Template,
4615 TL.getNameLoc(),
4616 NewTemplateArgs);
4617
4618 if (!Result.isNull()) {
4619 /// FIXME: Wrap this in an elaborated-type-specifier?
4620 TemplateSpecializationTypeLoc NewTL
4621 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4622 NewTL.setTemplateNameLoc(TL.getNameLoc());
4623 NewTL.setLAngleLoc(TL.getLAngleLoc());
4624 NewTL.setRAngleLoc(TL.getRAngleLoc());
4625 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4626 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4627 }
4628
4629 return Result;
4630}
4631
Mike Stump1eb44332009-09-09 15:08:12 +00004632template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004633QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004634TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004635 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004636 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004637
Douglas Gregor9e876872011-03-01 18:12:44 +00004638 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004639 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004640 if (TL.getQualifierLoc()) {
4641 QualifierLoc
4642 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4643 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004644 return QualType();
4645 }
Mike Stump1eb44332009-09-09 15:08:12 +00004646
John McCall43fed0d2010-11-12 08:19:04 +00004647 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4648 if (NamedT.isNull())
4649 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004650
Richard Smith3e4c6c42011-05-05 21:57:07 +00004651 // C++0x [dcl.type.elab]p2:
4652 // If the identifier resolves to a typedef-name or the simple-template-id
4653 // resolves to an alias template specialization, the
4654 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004655 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4656 if (const TemplateSpecializationType *TST =
4657 NamedT->getAs<TemplateSpecializationType>()) {
4658 TemplateName Template = TST->getTemplateName();
4659 if (TypeAliasTemplateDecl *TAT =
4660 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4661 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4662 diag::err_tag_reference_non_tag) << 4;
4663 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4664 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004665 }
4666 }
4667
John McCalla2becad2009-10-21 00:40:46 +00004668 QualType Result = TL.getType();
4669 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004670 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004671 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004672 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004673 T->getKeyword(),
4674 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004675 if (Result.isNull())
4676 return QualType();
4677 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004678
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004679 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004680 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004681 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004682 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004683}
Mike Stump1eb44332009-09-09 15:08:12 +00004684
4685template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004686QualType TreeTransform<Derived>::TransformAttributedType(
4687 TypeLocBuilder &TLB,
4688 AttributedTypeLoc TL) {
4689 const AttributedType *oldType = TL.getTypePtr();
4690 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4691 if (modifiedType.isNull())
4692 return QualType();
4693
4694 QualType result = TL.getType();
4695
4696 // FIXME: dependent operand expressions?
4697 if (getDerived().AlwaysRebuild() ||
4698 modifiedType != oldType->getModifiedType()) {
4699 // TODO: this is really lame; we should really be rebuilding the
4700 // equivalent type from first principles.
4701 QualType equivalentType
4702 = getDerived().TransformType(oldType->getEquivalentType());
4703 if (equivalentType.isNull())
4704 return QualType();
4705 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4706 modifiedType,
4707 equivalentType);
4708 }
4709
4710 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4711 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4712 if (TL.hasAttrOperand())
4713 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4714 if (TL.hasAttrExprOperand())
4715 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4716 else if (TL.hasAttrEnumOperand())
4717 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4718
4719 return result;
4720}
4721
4722template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004723QualType
4724TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4725 ParenTypeLoc TL) {
4726 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4727 if (Inner.isNull())
4728 return QualType();
4729
4730 QualType Result = TL.getType();
4731 if (getDerived().AlwaysRebuild() ||
4732 Inner != TL.getInnerLoc().getType()) {
4733 Result = getDerived().RebuildParenType(Inner);
4734 if (Result.isNull())
4735 return QualType();
4736 }
4737
4738 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4739 NewTL.setLParenLoc(TL.getLParenLoc());
4740 NewTL.setRParenLoc(TL.getRParenLoc());
4741 return Result;
4742}
4743
4744template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004745QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004746 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004747 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004748
Douglas Gregor2494dd02011-03-01 01:34:45 +00004749 NestedNameSpecifierLoc QualifierLoc
4750 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4751 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004752 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004753
John McCall33500952010-06-11 00:33:02 +00004754 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004755 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCall33500952010-06-11 00:33:02 +00004756 TL.getKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004757 QualifierLoc,
4758 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004759 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004760 if (Result.isNull())
4761 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004762
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004763 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4764 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004765 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4766
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004767 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4768 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004769 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004770 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004771 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4772 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004773 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004774 NewTL.setNameLoc(TL.getNameLoc());
4775 }
John McCalla2becad2009-10-21 00:40:46 +00004776 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004777}
Mike Stump1eb44332009-09-09 15:08:12 +00004778
Douglas Gregor577f75a2009-08-04 16:50:30 +00004779template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004780QualType TreeTransform<Derived>::
4781 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004782 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004783 NestedNameSpecifierLoc QualifierLoc;
4784 if (TL.getQualifierLoc()) {
4785 QualifierLoc
4786 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4787 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004788 return QualType();
4789 }
4790
John McCall43fed0d2010-11-12 08:19:04 +00004791 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004792 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004793}
4794
4795template<typename Derived>
4796QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004797TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4798 DependentTemplateSpecializationTypeLoc TL,
4799 NestedNameSpecifierLoc QualifierLoc) {
4800 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4801
4802 TemplateArgumentListInfo NewTemplateArgs;
4803 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4804 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4805
4806 typedef TemplateArgumentLocContainerIterator<
4807 DependentTemplateSpecializationTypeLoc> ArgIterator;
4808 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4809 ArgIterator(TL, TL.getNumArgs()),
4810 NewTemplateArgs))
4811 return QualType();
4812
4813 QualType Result
4814 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4815 QualifierLoc,
4816 T->getIdentifier(),
4817 TL.getNameLoc(),
4818 NewTemplateArgs);
4819 if (Result.isNull())
4820 return QualType();
4821
4822 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4823 QualType NamedT = ElabT->getNamedType();
4824
4825 // Copy information relevant to the template specialization.
4826 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004827 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004828 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004829 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4830 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004831 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004832 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004833
4834 // Copy information relevant to the elaborated type.
4835 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4836 NewTL.setKeywordLoc(TL.getKeywordLoc());
4837 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004838 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4839 DependentTemplateSpecializationTypeLoc SpecTL
4840 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor944cdae2011-03-07 15:13:34 +00004841 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004842 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004843 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004844 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4845 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004846 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004847 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004848 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004849 TemplateSpecializationTypeLoc SpecTL
4850 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004851 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004852 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4853 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004854 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004855 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004856 }
4857 return Result;
4858}
4859
4860template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004861QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4862 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004863 QualType Pattern
4864 = getDerived().TransformType(TLB, TL.getPatternLoc());
4865 if (Pattern.isNull())
4866 return QualType();
4867
4868 QualType Result = TL.getType();
4869 if (getDerived().AlwaysRebuild() ||
4870 Pattern != TL.getPatternLoc().getType()) {
4871 Result = getDerived().RebuildPackExpansionType(Pattern,
4872 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004873 TL.getEllipsisLoc(),
4874 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004875 if (Result.isNull())
4876 return QualType();
4877 }
4878
4879 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4880 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4881 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004882}
4883
4884template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004885QualType
4886TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004887 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004888 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004889 TLB.pushFullCopy(TL);
4890 return TL.getType();
4891}
4892
4893template<typename Derived>
4894QualType
4895TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004896 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004897 // ObjCObjectType is never dependent.
4898 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004899 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004900}
Mike Stump1eb44332009-09-09 15:08:12 +00004901
4902template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004903QualType
4904TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004905 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004906 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004907 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004908 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004909}
4910
Douglas Gregor577f75a2009-08-04 16:50:30 +00004911//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004912// Statement transformation
4913//===----------------------------------------------------------------------===//
4914template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004915StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004916TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004917 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004918}
4919
4920template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004921StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004922TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4923 return getDerived().TransformCompoundStmt(S, false);
4924}
4925
4926template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004927StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004928TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004929 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004930 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004931 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004932 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004933 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4934 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004935 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004936 if (Result.isInvalid()) {
4937 // Immediately fail if this was a DeclStmt, since it's very
4938 // likely that this will cause problems for future statements.
4939 if (isa<DeclStmt>(*B))
4940 return StmtError();
4941
4942 // Otherwise, just keep processing substatements and fail later.
4943 SubStmtInvalid = true;
4944 continue;
4945 }
Mike Stump1eb44332009-09-09 15:08:12 +00004946
Douglas Gregor43959a92009-08-20 07:17:43 +00004947 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4948 Statements.push_back(Result.takeAs<Stmt>());
4949 }
Mike Stump1eb44332009-09-09 15:08:12 +00004950
John McCall7114cba2010-08-27 19:56:05 +00004951 if (SubStmtInvalid)
4952 return StmtError();
4953
Douglas Gregor43959a92009-08-20 07:17:43 +00004954 if (!getDerived().AlwaysRebuild() &&
4955 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004956 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004957
4958 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4959 move_arg(Statements),
4960 S->getRBracLoc(),
4961 IsStmtExpr);
4962}
Mike Stump1eb44332009-09-09 15:08:12 +00004963
Douglas Gregor43959a92009-08-20 07:17:43 +00004964template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004965StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004966TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004967 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004968 {
4969 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004970 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004971
Eli Friedman264c1f82009-11-19 03:14:00 +00004972 // Transform the left-hand case value.
4973 LHS = getDerived().TransformExpr(S->getLHS());
4974 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004975 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004976
Eli Friedman264c1f82009-11-19 03:14:00 +00004977 // Transform the right-hand case value (for the GNU case-range extension).
4978 RHS = getDerived().TransformExpr(S->getRHS());
4979 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004980 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004981 }
Mike Stump1eb44332009-09-09 15:08:12 +00004982
Douglas Gregor43959a92009-08-20 07:17:43 +00004983 // Build the case statement.
4984 // Case statements are always rebuilt so that they will attached to their
4985 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004986 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004987 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004988 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004989 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004990 S->getColonLoc());
4991 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004992 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004993
Douglas Gregor43959a92009-08-20 07:17:43 +00004994 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004995 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004996 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004997 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004998
Douglas Gregor43959a92009-08-20 07:17:43 +00004999 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005000 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005001}
5002
5003template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005004StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005005TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005006 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005007 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005008 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005009 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005010
Douglas Gregor43959a92009-08-20 07:17:43 +00005011 // Default statements are always rebuilt
5012 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005013 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005014}
Mike Stump1eb44332009-09-09 15:08:12 +00005015
Douglas Gregor43959a92009-08-20 07:17:43 +00005016template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005017StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005018TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005019 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005020 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005021 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005022
Chris Lattner57ad3782011-02-17 20:34:02 +00005023 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5024 S->getDecl());
5025 if (!LD)
5026 return StmtError();
5027
5028
Douglas Gregor43959a92009-08-20 07:17:43 +00005029 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005030 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005031 cast<LabelDecl>(LD), SourceLocation(),
5032 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005033}
Mike Stump1eb44332009-09-09 15:08:12 +00005034
Douglas Gregor43959a92009-08-20 07:17:43 +00005035template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005036StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005037TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005038 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005039 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005040 VarDecl *ConditionVar = 0;
5041 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005042 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005043 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005044 getDerived().TransformDefinition(
5045 S->getConditionVariable()->getLocation(),
5046 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005047 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005048 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005049 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005050 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005051
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005052 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005053 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005054
5055 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005056 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005057 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5058 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005059 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005060 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005061
John McCall9ae2f072010-08-23 23:25:46 +00005062 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005063 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005064 }
Sean Huntc3021132010-05-05 15:23:54 +00005065
John McCall9ae2f072010-08-23 23:25:46 +00005066 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5067 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005068 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005069
Douglas Gregor43959a92009-08-20 07:17:43 +00005070 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005071 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005072 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005073 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005074
Douglas Gregor43959a92009-08-20 07:17:43 +00005075 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005076 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005077 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005078 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005079
Douglas Gregor43959a92009-08-20 07:17:43 +00005080 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005081 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005082 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005083 Then.get() == S->getThen() &&
5084 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005085 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005086
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005087 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005088 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005089 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005090}
5091
5092template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005093StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005094TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005095 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005096 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005097 VarDecl *ConditionVar = 0;
5098 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005099 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005100 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005101 getDerived().TransformDefinition(
5102 S->getConditionVariable()->getLocation(),
5103 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005104 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005105 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005106 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005107 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005108
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005109 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005110 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005111 }
Mike Stump1eb44332009-09-09 15:08:12 +00005112
Douglas Gregor43959a92009-08-20 07:17:43 +00005113 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005114 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005115 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005116 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005117 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005118 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005119
Douglas Gregor43959a92009-08-20 07:17:43 +00005120 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005121 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005122 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005123 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005124
Douglas Gregor43959a92009-08-20 07:17:43 +00005125 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005126 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5127 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005128}
Mike Stump1eb44332009-09-09 15:08:12 +00005129
Douglas Gregor43959a92009-08-20 07:17:43 +00005130template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005131StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005132TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005133 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005134 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005135 VarDecl *ConditionVar = 0;
5136 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005137 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005138 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005139 getDerived().TransformDefinition(
5140 S->getConditionVariable()->getLocation(),
5141 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005142 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005143 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005144 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005145 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005146
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005147 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005148 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005149
5150 if (S->getCond()) {
5151 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005152 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5153 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005154 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005155 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005156 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005157 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005158 }
Mike Stump1eb44332009-09-09 15:08:12 +00005159
John McCall9ae2f072010-08-23 23:25:46 +00005160 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5161 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005162 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005163
Douglas Gregor43959a92009-08-20 07:17:43 +00005164 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005165 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005166 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005167 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005168
Douglas Gregor43959a92009-08-20 07:17:43 +00005169 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005170 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005171 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005172 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005173 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005174
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005175 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005176 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005177}
Mike Stump1eb44332009-09-09 15:08:12 +00005178
Douglas Gregor43959a92009-08-20 07:17:43 +00005179template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005180StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005181TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005182 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005183 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005184 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005185 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005186
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005187 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005188 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005189 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005190 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005191
Douglas Gregor43959a92009-08-20 07:17:43 +00005192 if (!getDerived().AlwaysRebuild() &&
5193 Cond.get() == S->getCond() &&
5194 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005195 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005196
John McCall9ae2f072010-08-23 23:25:46 +00005197 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5198 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005199 S->getRParenLoc());
5200}
Mike Stump1eb44332009-09-09 15:08:12 +00005201
Douglas Gregor43959a92009-08-20 07:17:43 +00005202template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005203StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005204TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005205 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005206 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005207 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005208 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Douglas Gregor43959a92009-08-20 07:17:43 +00005210 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005211 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005212 VarDecl *ConditionVar = 0;
5213 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005214 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005215 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005216 getDerived().TransformDefinition(
5217 S->getConditionVariable()->getLocation(),
5218 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005219 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005220 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005221 } else {
5222 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005223
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005224 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005225 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005226
5227 if (S->getCond()) {
5228 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005229 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5230 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005231 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005232 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005233
John McCall9ae2f072010-08-23 23:25:46 +00005234 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005235 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005236 }
Mike Stump1eb44332009-09-09 15:08:12 +00005237
John McCall9ae2f072010-08-23 23:25:46 +00005238 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5239 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005240 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005241
Douglas Gregor43959a92009-08-20 07:17:43 +00005242 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005243 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005244 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005245 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005246
John McCall9ae2f072010-08-23 23:25:46 +00005247 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5248 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005249 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005250
Douglas Gregor43959a92009-08-20 07:17:43 +00005251 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005252 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005253 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005254 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005255
Douglas Gregor43959a92009-08-20 07:17:43 +00005256 if (!getDerived().AlwaysRebuild() &&
5257 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005258 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005259 Inc.get() == S->getInc() &&
5260 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005261 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005262
Douglas Gregor43959a92009-08-20 07:17:43 +00005263 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005264 Init.get(), FullCond, ConditionVar,
5265 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005266}
5267
5268template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005269StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005270TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005271 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5272 S->getLabel());
5273 if (!LD)
5274 return StmtError();
5275
Douglas Gregor43959a92009-08-20 07:17:43 +00005276 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005277 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005278 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005279}
5280
5281template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005282StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005283TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005284 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005285 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005286 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005287
Douglas Gregor43959a92009-08-20 07:17:43 +00005288 if (!getDerived().AlwaysRebuild() &&
5289 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005290 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005291
5292 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005293 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005294}
5295
5296template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005297StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005298TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005299 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005300}
Mike Stump1eb44332009-09-09 15:08:12 +00005301
Douglas Gregor43959a92009-08-20 07:17:43 +00005302template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005303StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005304TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005305 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005306}
Mike Stump1eb44332009-09-09 15:08:12 +00005307
Douglas Gregor43959a92009-08-20 07:17:43 +00005308template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005309StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005310TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005311 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005312 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005313 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005314
Mike Stump1eb44332009-09-09 15:08:12 +00005315 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005316 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005317 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005318}
Mike Stump1eb44332009-09-09 15:08:12 +00005319
Douglas Gregor43959a92009-08-20 07:17:43 +00005320template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005321StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005322TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005323 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005324 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005325 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5326 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005327 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5328 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005329 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005330 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005331
Douglas Gregor43959a92009-08-20 07:17:43 +00005332 if (Transformed != *D)
5333 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005334
Douglas Gregor43959a92009-08-20 07:17:43 +00005335 Decls.push_back(Transformed);
5336 }
Mike Stump1eb44332009-09-09 15:08:12 +00005337
Douglas Gregor43959a92009-08-20 07:17:43 +00005338 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005339 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005340
5341 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005342 S->getStartLoc(), S->getEndLoc());
5343}
Mike Stump1eb44332009-09-09 15:08:12 +00005344
Douglas Gregor43959a92009-08-20 07:17:43 +00005345template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005346StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005347TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005348
John McCallca0408f2010-08-23 06:44:23 +00005349 ASTOwningVector<Expr*> Constraints(getSema());
5350 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005351 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005352
John McCall60d7b3a2010-08-24 06:29:42 +00005353 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005354 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005355
5356 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005357
Anders Carlsson703e3942010-01-24 05:50:09 +00005358 // Go through the outputs.
5359 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005360 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005361
Anders Carlsson703e3942010-01-24 05:50:09 +00005362 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005363 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005364
Anders Carlsson703e3942010-01-24 05:50:09 +00005365 // Transform the output expr.
5366 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005367 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005368 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005369 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005370
Anders Carlsson703e3942010-01-24 05:50:09 +00005371 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005372
John McCall9ae2f072010-08-23 23:25:46 +00005373 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005374 }
Sean Huntc3021132010-05-05 15:23:54 +00005375
Anders Carlsson703e3942010-01-24 05:50:09 +00005376 // Go through the inputs.
5377 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005378 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005379
Anders Carlsson703e3942010-01-24 05:50:09 +00005380 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005381 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005382
Anders Carlsson703e3942010-01-24 05:50:09 +00005383 // Transform the input expr.
5384 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005385 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005386 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005387 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005388
Anders Carlsson703e3942010-01-24 05:50:09 +00005389 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005390
John McCall9ae2f072010-08-23 23:25:46 +00005391 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005392 }
Sean Huntc3021132010-05-05 15:23:54 +00005393
Anders Carlsson703e3942010-01-24 05:50:09 +00005394 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005395 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005396
5397 // Go through the clobbers.
5398 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005399 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005400
5401 // No need to transform the asm string literal.
5402 AsmString = SemaRef.Owned(S->getAsmString());
5403
5404 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5405 S->isSimple(),
5406 S->isVolatile(),
5407 S->getNumOutputs(),
5408 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005409 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005410 move_arg(Constraints),
5411 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005412 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005413 move_arg(Clobbers),
5414 S->getRParenLoc(),
5415 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005416}
5417
5418
5419template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005420StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005421TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005422 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005423 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005424 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005425 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005426
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005427 // Transform the @catch statements (if present).
5428 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005429 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005430 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005431 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005432 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005433 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005434 if (Catch.get() != S->getCatchStmt(I))
5435 AnyCatchChanged = true;
5436 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005437 }
Sean Huntc3021132010-05-05 15:23:54 +00005438
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005439 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005440 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005441 if (S->getFinallyStmt()) {
5442 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5443 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005444 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005445 }
5446
5447 // If nothing changed, just retain this statement.
5448 if (!getDerived().AlwaysRebuild() &&
5449 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005450 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005451 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005452 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005453
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005454 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005455 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5456 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005457}
Mike Stump1eb44332009-09-09 15:08:12 +00005458
Douglas Gregor43959a92009-08-20 07:17:43 +00005459template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005460StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005461TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005462 // Transform the @catch parameter, if there is one.
5463 VarDecl *Var = 0;
5464 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5465 TypeSourceInfo *TSInfo = 0;
5466 if (FromVar->getTypeSourceInfo()) {
5467 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5468 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005469 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005470 }
Sean Huntc3021132010-05-05 15:23:54 +00005471
Douglas Gregorbe270a02010-04-26 17:57:08 +00005472 QualType T;
5473 if (TSInfo)
5474 T = TSInfo->getType();
5475 else {
5476 T = getDerived().TransformType(FromVar->getType());
5477 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005478 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005479 }
Sean Huntc3021132010-05-05 15:23:54 +00005480
Douglas Gregorbe270a02010-04-26 17:57:08 +00005481 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5482 if (!Var)
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
John McCall60d7b3a2010-08-24 06:29:42 +00005486 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005487 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005488 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005489
5490 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005491 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005492 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005493}
Mike Stump1eb44332009-09-09 15:08:12 +00005494
Douglas Gregor43959a92009-08-20 07:17:43 +00005495template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005496StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005497TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005498 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005499 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005500 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005501 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005502
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005503 // If nothing changed, just retain this statement.
5504 if (!getDerived().AlwaysRebuild() &&
5505 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005506 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005507
5508 // Build a new statement.
5509 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005510 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005511}
Mike Stump1eb44332009-09-09 15:08:12 +00005512
Douglas Gregor43959a92009-08-20 07:17:43 +00005513template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005514StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005515TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005516 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005517 if (S->getThrowExpr()) {
5518 Operand = getDerived().TransformExpr(S->getThrowExpr());
5519 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005520 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005521 }
Sean Huntc3021132010-05-05 15:23:54 +00005522
Douglas Gregord1377b22010-04-22 21:44:01 +00005523 if (!getDerived().AlwaysRebuild() &&
5524 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005525 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005526
John McCall9ae2f072010-08-23 23:25:46 +00005527 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005528}
Mike Stump1eb44332009-09-09 15:08:12 +00005529
Douglas Gregor43959a92009-08-20 07:17:43 +00005530template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005531StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005532TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005533 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005534 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005535 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005536 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005537 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005538 Object =
5539 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5540 Object.get());
5541 if (Object.isInvalid())
5542 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005543
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005544 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005545 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005546 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005547 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005548
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005549 // If nothing change, just retain the current statement.
5550 if (!getDerived().AlwaysRebuild() &&
5551 Object.get() == S->getSynchExpr() &&
5552 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005553 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005554
5555 // Build a new statement.
5556 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005557 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005558}
5559
5560template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005561StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005562TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5563 ObjCAutoreleasePoolStmt *S) {
5564 // Transform the body.
5565 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5566 if (Body.isInvalid())
5567 return StmtError();
5568
5569 // If nothing changed, just retain this statement.
5570 if (!getDerived().AlwaysRebuild() &&
5571 Body.get() == S->getSubStmt())
5572 return SemaRef.Owned(S);
5573
5574 // Build a new statement.
5575 return getDerived().RebuildObjCAutoreleasePoolStmt(
5576 S->getAtLoc(), Body.get());
5577}
5578
5579template<typename Derived>
5580StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005581TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005582 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005583 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005584 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005585 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005586 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005587
Douglas Gregorc3203e72010-04-22 23:10:45 +00005588 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005589 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005590 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005591 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005592 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5593 Collection.take());
5594 if (Collection.isInvalid())
5595 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005596
Douglas Gregorc3203e72010-04-22 23:10:45 +00005597 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005598 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005599 if (Body.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 // If nothing changed, just retain this statement.
5603 if (!getDerived().AlwaysRebuild() &&
5604 Element.get() == S->getElement() &&
5605 Collection.get() == S->getCollection() &&
5606 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005607 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005608
Douglas Gregorc3203e72010-04-22 23:10:45 +00005609 // Build a new statement.
5610 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5611 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005612 Element.get(),
5613 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005614 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005615 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005616}
5617
5618
5619template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005620StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005621TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5622 // Transform the exception declaration, if any.
5623 VarDecl *Var = 0;
5624 if (S->getExceptionDecl()) {
5625 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005626 TypeSourceInfo *T = getDerived().TransformType(
5627 ExceptionDecl->getTypeSourceInfo());
5628 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005629 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005630
Douglas Gregor83cb9422010-09-09 17:09:21 +00005631 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005632 ExceptionDecl->getInnerLocStart(),
5633 ExceptionDecl->getLocation(),
5634 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005635 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005636 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005637 }
Mike Stump1eb44332009-09-09 15:08:12 +00005638
Douglas Gregor43959a92009-08-20 07:17:43 +00005639 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005640 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005641 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005642 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005643
Douglas Gregor43959a92009-08-20 07:17:43 +00005644 if (!getDerived().AlwaysRebuild() &&
5645 !Var &&
5646 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005647 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005648
5649 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5650 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005651 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005652}
Mike Stump1eb44332009-09-09 15:08:12 +00005653
Douglas Gregor43959a92009-08-20 07:17:43 +00005654template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005655StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005656TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5657 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005658 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005659 = getDerived().TransformCompoundStmt(S->getTryBlock());
5660 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005661 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005662
Douglas Gregor43959a92009-08-20 07:17:43 +00005663 // Transform the handlers.
5664 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005665 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005666 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005667 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005668 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5669 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005670 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005671
Douglas Gregor43959a92009-08-20 07:17:43 +00005672 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5673 Handlers.push_back(Handler.takeAs<Stmt>());
5674 }
Mike Stump1eb44332009-09-09 15:08:12 +00005675
Douglas Gregor43959a92009-08-20 07:17:43 +00005676 if (!getDerived().AlwaysRebuild() &&
5677 TryBlock.get() == S->getTryBlock() &&
5678 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005679 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005680
John McCall9ae2f072010-08-23 23:25:46 +00005681 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005682 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005683}
Mike Stump1eb44332009-09-09 15:08:12 +00005684
Richard Smithad762fc2011-04-14 22:09:26 +00005685template<typename Derived>
5686StmtResult
5687TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5688 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5689 if (Range.isInvalid())
5690 return StmtError();
5691
5692 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5693 if (BeginEnd.isInvalid())
5694 return StmtError();
5695
5696 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5697 if (Cond.isInvalid())
5698 return StmtError();
5699
5700 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5701 if (Inc.isInvalid())
5702 return StmtError();
5703
5704 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5705 if (LoopVar.isInvalid())
5706 return StmtError();
5707
5708 StmtResult NewStmt = S;
5709 if (getDerived().AlwaysRebuild() ||
5710 Range.get() != S->getRangeStmt() ||
5711 BeginEnd.get() != S->getBeginEndStmt() ||
5712 Cond.get() != S->getCond() ||
5713 Inc.get() != S->getInc() ||
5714 LoopVar.get() != S->getLoopVarStmt())
5715 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5716 S->getColonLoc(), Range.get(),
5717 BeginEnd.get(), Cond.get(),
5718 Inc.get(), LoopVar.get(),
5719 S->getRParenLoc());
5720
5721 StmtResult Body = getDerived().TransformStmt(S->getBody());
5722 if (Body.isInvalid())
5723 return StmtError();
5724
5725 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5726 // it now so we have a new statement to attach the body to.
5727 if (Body.get() != S->getBody() && NewStmt.get() == S)
5728 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5729 S->getColonLoc(), Range.get(),
5730 BeginEnd.get(), Cond.get(),
5731 Inc.get(), LoopVar.get(),
5732 S->getRParenLoc());
5733
5734 if (NewStmt.get() == S)
5735 return SemaRef.Owned(S);
5736
5737 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5738}
5739
John Wiegley28bbe4b2011-04-28 01:08:34 +00005740template<typename Derived>
5741StmtResult
5742TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5743 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5744 if(TryBlock.isInvalid()) return StmtError();
5745
5746 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5747 if(!getDerived().AlwaysRebuild() &&
5748 TryBlock.get() == S->getTryBlock() &&
5749 Handler.get() == S->getHandler())
5750 return SemaRef.Owned(S);
5751
5752 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5753 S->getTryLoc(),
5754 TryBlock.take(),
5755 Handler.take());
5756}
5757
5758template<typename Derived>
5759StmtResult
5760TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5761 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5762 if(Block.isInvalid()) return StmtError();
5763
5764 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5765 Block.take());
5766}
5767
5768template<typename Derived>
5769StmtResult
5770TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5771 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5772 if(FilterExpr.isInvalid()) return StmtError();
5773
5774 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5775 if(Block.isInvalid()) return StmtError();
5776
5777 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5778 FilterExpr.take(),
5779 Block.take());
5780}
5781
5782template<typename Derived>
5783StmtResult
5784TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5785 if(isa<SEHFinallyStmt>(Handler))
5786 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5787 else
5788 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5789}
5790
Douglas Gregor43959a92009-08-20 07:17:43 +00005791//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005792// Expression transformation
5793//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005794template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005795ExprResult
John McCall454feb92009-12-08 09:21:05 +00005796TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005797 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005798}
Mike Stump1eb44332009-09-09 15:08:12 +00005799
5800template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005801ExprResult
John McCall454feb92009-12-08 09:21:05 +00005802TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005803 NestedNameSpecifierLoc QualifierLoc;
5804 if (E->getQualifierLoc()) {
5805 QualifierLoc
5806 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5807 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005808 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005809 }
John McCalldbd872f2009-12-08 09:08:17 +00005810
5811 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005812 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5813 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005814 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005815 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005816
John McCallec8045d2010-08-17 21:27:17 +00005817 DeclarationNameInfo NameInfo = E->getNameInfo();
5818 if (NameInfo.getName()) {
5819 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5820 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005821 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005822 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005823
5824 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005825 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005826 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005827 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005828 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005829
5830 // Mark it referenced in the new context regardless.
5831 // FIXME: this is a bit instantiation-specific.
5832 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5833
John McCall3fa5cae2010-10-26 07:05:15 +00005834 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005835 }
John McCalldbd872f2009-12-08 09:08:17 +00005836
5837 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005838 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005839 TemplateArgs = &TransArgs;
5840 TransArgs.setLAngleLoc(E->getLAngleLoc());
5841 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005842 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5843 E->getNumTemplateArgs(),
5844 TransArgs))
5845 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005846 }
5847
Douglas Gregor40d96a62011-02-28 21:54:11 +00005848 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5849 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005850}
Mike Stump1eb44332009-09-09 15:08:12 +00005851
Douglas Gregorb98b1992009-08-11 05:31:07 +00005852template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005853ExprResult
John McCall454feb92009-12-08 09:21:05 +00005854TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005855 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005856}
Mike Stump1eb44332009-09-09 15:08:12 +00005857
Douglas Gregorb98b1992009-08-11 05:31:07 +00005858template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005859ExprResult
John McCall454feb92009-12-08 09:21:05 +00005860TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005861 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005862}
Mike Stump1eb44332009-09-09 15:08:12 +00005863
Douglas Gregorb98b1992009-08-11 05:31:07 +00005864template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005865ExprResult
John McCall454feb92009-12-08 09:21:05 +00005866TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005867 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005868}
Mike Stump1eb44332009-09-09 15:08:12 +00005869
Douglas Gregorb98b1992009-08-11 05:31:07 +00005870template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005871ExprResult
John McCall454feb92009-12-08 09:21:05 +00005872TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005873 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005874}
Mike Stump1eb44332009-09-09 15:08:12 +00005875
Douglas Gregorb98b1992009-08-11 05:31:07 +00005876template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005877ExprResult
John McCall454feb92009-12-08 09:21:05 +00005878TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005879 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005880}
5881
5882template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005883ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00005884TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5885 ExprResult ControllingExpr =
5886 getDerived().TransformExpr(E->getControllingExpr());
5887 if (ControllingExpr.isInvalid())
5888 return ExprError();
5889
Chris Lattner686775d2011-07-20 06:58:45 +00005890 SmallVector<Expr *, 4> AssocExprs;
5891 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00005892 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5893 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5894 if (TS) {
5895 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5896 if (!AssocType)
5897 return ExprError();
5898 AssocTypes.push_back(AssocType);
5899 } else {
5900 AssocTypes.push_back(0);
5901 }
5902
5903 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5904 if (AssocExpr.isInvalid())
5905 return ExprError();
5906 AssocExprs.push_back(AssocExpr.release());
5907 }
5908
5909 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5910 E->getDefaultLoc(),
5911 E->getRParenLoc(),
5912 ControllingExpr.release(),
5913 AssocTypes.data(),
5914 AssocExprs.data(),
5915 E->getNumAssocs());
5916}
5917
5918template<typename Derived>
5919ExprResult
John McCall454feb92009-12-08 09:21:05 +00005920TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005921 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005922 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005923 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005924
Douglas Gregorb98b1992009-08-11 05:31:07 +00005925 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005926 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005927
John McCall9ae2f072010-08-23 23:25:46 +00005928 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005929 E->getRParen());
5930}
5931
Mike Stump1eb44332009-09-09 15:08:12 +00005932template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005933ExprResult
John McCall454feb92009-12-08 09:21:05 +00005934TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005935 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005936 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005937 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005938
Douglas Gregorb98b1992009-08-11 05:31:07 +00005939 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005940 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005941
Douglas Gregorb98b1992009-08-11 05:31:07 +00005942 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5943 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005944 SubExpr.get());
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
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005949TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5950 // Transform the type.
5951 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5952 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005953 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005954
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005955 // Transform all of the components into components similar to what the
5956 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005957 // FIXME: It would be slightly more efficient in the non-dependent case to
5958 // just map FieldDecls, rather than requiring the rebuilder to look for
5959 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005960 // template code that we don't care.
5961 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005962 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005963 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00005964 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005965 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5966 const Node &ON = E->getComponent(I);
5967 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005968 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00005969 Comp.LocStart = ON.getSourceRange().getBegin();
5970 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005971 switch (ON.getKind()) {
5972 case Node::Array: {
5973 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005974 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005975 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005976 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005977
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005978 ExprChanged = ExprChanged || Index.get() != FromIndex;
5979 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005980 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005981 break;
5982 }
Sean Huntc3021132010-05-05 15:23:54 +00005983
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005984 case Node::Field:
5985 case Node::Identifier:
5986 Comp.isBrackets = false;
5987 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005988 if (!Comp.U.IdentInfo)
5989 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005990
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005991 break;
Sean Huntc3021132010-05-05 15:23:54 +00005992
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005993 case Node::Base:
5994 // Will be recomputed during the rebuild.
5995 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005996 }
Sean Huntc3021132010-05-05 15:23:54 +00005997
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005998 Components.push_back(Comp);
5999 }
Sean Huntc3021132010-05-05 15:23:54 +00006000
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006001 // If nothing changed, retain the existing expression.
6002 if (!getDerived().AlwaysRebuild() &&
6003 Type == E->getTypeSourceInfo() &&
6004 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006005 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006006
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006007 // Build a new offsetof expression.
6008 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6009 Components.data(), Components.size(),
6010 E->getRParenLoc());
6011}
6012
6013template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006014ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006015TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6016 assert(getDerived().AlreadyTransformed(E->getType()) &&
6017 "opaque value expression requires transformation");
6018 return SemaRef.Owned(E);
6019}
6020
6021template<typename Derived>
6022ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006023TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6024 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006025 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006026 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006027
John McCalla93c9342009-12-07 02:54:59 +00006028 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006029 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006030 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006031
John McCall5ab75172009-11-04 07:28:41 +00006032 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006033 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006034
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006035 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6036 E->getKind(),
6037 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006038 }
Mike Stump1eb44332009-09-09 15:08:12 +00006039
John McCall60d7b3a2010-08-24 06:29:42 +00006040 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00006041 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006042 // C++0x [expr.sizeof]p1:
6043 // The operand is either an expression, which is an unevaluated operand
6044 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00006045 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006046
Douglas Gregorb98b1992009-08-11 05:31:07 +00006047 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6048 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006049 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006050
Douglas Gregorb98b1992009-08-11 05:31:07 +00006051 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006052 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006053 }
Mike Stump1eb44332009-09-09 15:08:12 +00006054
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006055 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6056 E->getOperatorLoc(),
6057 E->getKind(),
6058 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006059}
Mike Stump1eb44332009-09-09 15:08:12 +00006060
Douglas Gregorb98b1992009-08-11 05:31:07 +00006061template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006062ExprResult
John McCall454feb92009-12-08 09:21:05 +00006063TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006064 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006065 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006066 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006067
John McCall60d7b3a2010-08-24 06:29:42 +00006068 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006069 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006070 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006071
6072
Douglas Gregorb98b1992009-08-11 05:31:07 +00006073 if (!getDerived().AlwaysRebuild() &&
6074 LHS.get() == E->getLHS() &&
6075 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006076 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006077
John McCall9ae2f072010-08-23 23:25:46 +00006078 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006079 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006080 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006081 E->getRBracketLoc());
6082}
Mike Stump1eb44332009-09-09 15:08:12 +00006083
6084template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006085ExprResult
John McCall454feb92009-12-08 09:21:05 +00006086TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006087 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006088 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006089 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006090 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006091
6092 // Transform arguments.
6093 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006094 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006095 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6096 &ArgChanged))
6097 return ExprError();
6098
Douglas Gregorb98b1992009-08-11 05:31:07 +00006099 if (!getDerived().AlwaysRebuild() &&
6100 Callee.get() == E->getCallee() &&
6101 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006102 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006103
Douglas Gregorb98b1992009-08-11 05:31:07 +00006104 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006105 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006106 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006107 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006108 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006109 E->getRParenLoc());
6110}
Mike Stump1eb44332009-09-09 15:08:12 +00006111
6112template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006113ExprResult
John McCall454feb92009-12-08 09:21:05 +00006114TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006115 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006116 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006117 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006118
Douglas Gregor40d96a62011-02-28 21:54:11 +00006119 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006120 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006121 QualifierLoc
6122 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6123
6124 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006125 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006126 }
Mike Stump1eb44332009-09-09 15:08:12 +00006127
Eli Friedmanf595cc42009-12-04 06:40:45 +00006128 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006129 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6130 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006131 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006132 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006133
John McCall6bb80172010-03-30 21:47:33 +00006134 NamedDecl *FoundDecl = E->getFoundDecl();
6135 if (FoundDecl == E->getMemberDecl()) {
6136 FoundDecl = Member;
6137 } else {
6138 FoundDecl = cast_or_null<NamedDecl>(
6139 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6140 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006141 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006142 }
6143
Douglas Gregorb98b1992009-08-11 05:31:07 +00006144 if (!getDerived().AlwaysRebuild() &&
6145 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006146 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006147 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006148 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006149 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006150
Anders Carlsson1f240322009-12-22 05:24:09 +00006151 // Mark it referenced in the new context regardless.
6152 // FIXME: this is a bit instantiation-specific.
6153 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00006154 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006155 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006156
John McCalld5532b62009-11-23 01:53:49 +00006157 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006158 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006159 TransArgs.setLAngleLoc(E->getLAngleLoc());
6160 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006161 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6162 E->getNumTemplateArgs(),
6163 TransArgs))
6164 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006165 }
Sean Huntc3021132010-05-05 15:23:54 +00006166
Douglas Gregorb98b1992009-08-11 05:31:07 +00006167 // FIXME: Bogus source location for the operator
6168 SourceLocation FakeOperatorLoc
6169 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6170
John McCallc2233c52010-01-15 08:34:02 +00006171 // FIXME: to do this check properly, we will need to preserve the
6172 // first-qualifier-in-scope here, just in case we had a dependent
6173 // base (and therefore couldn't do the check) and a
6174 // nested-name-qualifier (and therefore could do the lookup).
6175 NamedDecl *FirstQualifierInScope = 0;
6176
John McCall9ae2f072010-08-23 23:25:46 +00006177 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006178 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006179 QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006180 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006181 Member,
John McCall6bb80172010-03-30 21:47:33 +00006182 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006183 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006184 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006185 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006186}
Mike Stump1eb44332009-09-09 15:08:12 +00006187
Douglas Gregorb98b1992009-08-11 05:31:07 +00006188template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006189ExprResult
John McCall454feb92009-12-08 09:21:05 +00006190TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006191 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006192 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006193 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006194
John McCall60d7b3a2010-08-24 06:29:42 +00006195 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006196 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006197 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006198
Douglas Gregorb98b1992009-08-11 05:31:07 +00006199 if (!getDerived().AlwaysRebuild() &&
6200 LHS.get() == E->getLHS() &&
6201 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006202 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006203
Douglas Gregorb98b1992009-08-11 05:31:07 +00006204 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006205 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006206}
6207
Mike Stump1eb44332009-09-09 15:08:12 +00006208template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006209ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006210TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006211 CompoundAssignOperator *E) {
6212 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006213}
Mike Stump1eb44332009-09-09 15:08:12 +00006214
Douglas Gregorb98b1992009-08-11 05:31:07 +00006215template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006216ExprResult TreeTransform<Derived>::
6217TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6218 // Just rebuild the common and RHS expressions and see whether we
6219 // get any changes.
6220
6221 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6222 if (commonExpr.isInvalid())
6223 return ExprError();
6224
6225 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6226 if (rhs.isInvalid())
6227 return ExprError();
6228
6229 if (!getDerived().AlwaysRebuild() &&
6230 commonExpr.get() == e->getCommon() &&
6231 rhs.get() == e->getFalseExpr())
6232 return SemaRef.Owned(e);
6233
6234 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6235 e->getQuestionLoc(),
6236 0,
6237 e->getColonLoc(),
6238 rhs.get());
6239}
6240
6241template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006242ExprResult
John McCall454feb92009-12-08 09:21:05 +00006243TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006244 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006245 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006246 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006247
John McCall60d7b3a2010-08-24 06:29:42 +00006248 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006249 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006250 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006251
John McCall60d7b3a2010-08-24 06:29:42 +00006252 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006253 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006254 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006255
Douglas Gregorb98b1992009-08-11 05:31:07 +00006256 if (!getDerived().AlwaysRebuild() &&
6257 Cond.get() == E->getCond() &&
6258 LHS.get() == E->getLHS() &&
6259 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006260 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006261
John McCall9ae2f072010-08-23 23:25:46 +00006262 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006263 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006264 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006265 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006266 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006267}
Mike Stump1eb44332009-09-09 15:08:12 +00006268
6269template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006270ExprResult
John McCall454feb92009-12-08 09:21:05 +00006271TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006272 // Implicit casts are eliminated during transformation, since they
6273 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006274 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006275}
Mike Stump1eb44332009-09-09 15:08:12 +00006276
Douglas Gregorb98b1992009-08-11 05:31:07 +00006277template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006278ExprResult
John McCall454feb92009-12-08 09:21:05 +00006279TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006280 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6281 if (!Type)
6282 return ExprError();
6283
John McCall60d7b3a2010-08-24 06:29:42 +00006284 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006285 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006286 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006287 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006288
Douglas Gregorb98b1992009-08-11 05:31:07 +00006289 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006290 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006291 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006292 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006293
John McCall9d125032010-01-15 18:39:57 +00006294 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006295 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006296 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006297 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006298}
Mike Stump1eb44332009-09-09 15:08:12 +00006299
Douglas Gregorb98b1992009-08-11 05:31:07 +00006300template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006301ExprResult
John McCall454feb92009-12-08 09:21:05 +00006302TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006303 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6304 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6305 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006306 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006307
John McCall60d7b3a2010-08-24 06:29:42 +00006308 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006309 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006310 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006311
Douglas Gregorb98b1992009-08-11 05:31:07 +00006312 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006313 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006314 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00006315 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006316
John McCall1d7d8d62010-01-19 22:33:45 +00006317 // Note: the expression type doesn't necessarily match the
6318 // type-as-written, but that's okay, because it should always be
6319 // derivable from the initializer.
6320
John McCall42f56b52010-01-18 19:35:47 +00006321 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006322 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006323 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006324}
Mike Stump1eb44332009-09-09 15:08:12 +00006325
Douglas Gregorb98b1992009-08-11 05:31:07 +00006326template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006327ExprResult
John McCall454feb92009-12-08 09:21:05 +00006328TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006329 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006330 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006331 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006332
Douglas Gregorb98b1992009-08-11 05:31:07 +00006333 if (!getDerived().AlwaysRebuild() &&
6334 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006335 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006336
Douglas Gregorb98b1992009-08-11 05:31:07 +00006337 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006338 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006339 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006340 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006341 E->getAccessorLoc(),
6342 E->getAccessor());
6343}
Mike Stump1eb44332009-09-09 15:08:12 +00006344
Douglas Gregorb98b1992009-08-11 05:31:07 +00006345template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006346ExprResult
John McCall454feb92009-12-08 09:21:05 +00006347TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006348 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006349
John McCallca0408f2010-08-23 06:44:23 +00006350 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006351 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6352 Inits, &InitChanged))
6353 return ExprError();
6354
Douglas Gregorb98b1992009-08-11 05:31:07 +00006355 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006356 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006357
Douglas Gregorb98b1992009-08-11 05:31:07 +00006358 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006359 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006360}
Mike Stump1eb44332009-09-09 15:08:12 +00006361
Douglas Gregorb98b1992009-08-11 05:31:07 +00006362template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006363ExprResult
John McCall454feb92009-12-08 09:21:05 +00006364TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006365 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006366
Douglas Gregor43959a92009-08-20 07:17:43 +00006367 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006368 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006369 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006370 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006371
Douglas Gregor43959a92009-08-20 07:17:43 +00006372 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006373 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006374 bool ExprChanged = false;
6375 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6376 DEnd = E->designators_end();
6377 D != DEnd; ++D) {
6378 if (D->isFieldDesignator()) {
6379 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6380 D->getDotLoc(),
6381 D->getFieldLoc()));
6382 continue;
6383 }
Mike Stump1eb44332009-09-09 15:08:12 +00006384
Douglas Gregorb98b1992009-08-11 05:31:07 +00006385 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006386 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006387 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006388 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006389
6390 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006391 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006392
Douglas Gregorb98b1992009-08-11 05:31:07 +00006393 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6394 ArrayExprs.push_back(Index.release());
6395 continue;
6396 }
Mike Stump1eb44332009-09-09 15:08:12 +00006397
Douglas Gregorb98b1992009-08-11 05:31:07 +00006398 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006399 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006400 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6401 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006402 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006403
John McCall60d7b3a2010-08-24 06:29:42 +00006404 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006405 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006406 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006407
6408 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006409 End.get(),
6410 D->getLBracketLoc(),
6411 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006412
Douglas Gregorb98b1992009-08-11 05:31:07 +00006413 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6414 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006415
Douglas Gregorb98b1992009-08-11 05:31:07 +00006416 ArrayExprs.push_back(Start.release());
6417 ArrayExprs.push_back(End.release());
6418 }
Mike Stump1eb44332009-09-09 15:08:12 +00006419
Douglas Gregorb98b1992009-08-11 05:31:07 +00006420 if (!getDerived().AlwaysRebuild() &&
6421 Init.get() == E->getInit() &&
6422 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006423 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006424
Douglas Gregorb98b1992009-08-11 05:31:07 +00006425 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6426 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006427 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006428}
Mike Stump1eb44332009-09-09 15:08:12 +00006429
Douglas Gregorb98b1992009-08-11 05:31:07 +00006430template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006431ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006432TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006433 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006434 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006435
Douglas Gregor5557b252009-10-28 00:29:27 +00006436 // FIXME: Will we ever have proper type location here? Will we actually
6437 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438 QualType T = getDerived().TransformType(E->getType());
6439 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006440 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006441
Douglas Gregorb98b1992009-08-11 05:31:07 +00006442 if (!getDerived().AlwaysRebuild() &&
6443 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006444 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006445
Douglas Gregorb98b1992009-08-11 05:31:07 +00006446 return getDerived().RebuildImplicitValueInitExpr(T);
6447}
Mike Stump1eb44332009-09-09 15:08:12 +00006448
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006450ExprResult
John McCall454feb92009-12-08 09:21:05 +00006451TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006452 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6453 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006454 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006455
John McCall60d7b3a2010-08-24 06:29:42 +00006456 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006457 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006458 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006459
Douglas Gregorb98b1992009-08-11 05:31:07 +00006460 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006461 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006462 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006463 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006464
John McCall9ae2f072010-08-23 23:25:46 +00006465 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006466 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006467}
6468
6469template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006470ExprResult
John McCall454feb92009-12-08 09:21:05 +00006471TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006472 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006473 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006474 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6475 &ArgumentChanged))
6476 return ExprError();
6477
Douglas Gregorb98b1992009-08-11 05:31:07 +00006478 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6479 move_arg(Inits),
6480 E->getRParenLoc());
6481}
Mike Stump1eb44332009-09-09 15:08:12 +00006482
Douglas Gregorb98b1992009-08-11 05:31:07 +00006483/// \brief Transform an address-of-label expression.
6484///
6485/// By default, the transformation of an address-of-label expression always
6486/// rebuilds the expression, so that the label identifier can be resolved to
6487/// the corresponding label statement by semantic analysis.
6488template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006489ExprResult
John McCall454feb92009-12-08 09:21:05 +00006490TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006491 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6492 E->getLabel());
6493 if (!LD)
6494 return ExprError();
6495
Douglas Gregorb98b1992009-08-11 05:31:07 +00006496 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006497 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006498}
Mike Stump1eb44332009-09-09 15:08:12 +00006499
6500template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006501ExprResult
John McCall454feb92009-12-08 09:21:05 +00006502TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006503 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6505 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006506 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006507
Douglas Gregorb98b1992009-08-11 05:31:07 +00006508 if (!getDerived().AlwaysRebuild() &&
6509 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00006510 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006511
6512 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006513 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006514 E->getRParenLoc());
6515}
Mike Stump1eb44332009-09-09 15:08:12 +00006516
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006518ExprResult
John McCall454feb92009-12-08 09:21:05 +00006519TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006520 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006521 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006522 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006523
John McCall60d7b3a2010-08-24 06:29:42 +00006524 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006525 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006526 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006527
John McCall60d7b3a2010-08-24 06:29:42 +00006528 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006529 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006530 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006531
Douglas Gregorb98b1992009-08-11 05:31:07 +00006532 if (!getDerived().AlwaysRebuild() &&
6533 Cond.get() == E->getCond() &&
6534 LHS.get() == E->getLHS() &&
6535 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006536 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006537
Douglas Gregorb98b1992009-08-11 05:31:07 +00006538 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006539 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006540 E->getRParenLoc());
6541}
Mike Stump1eb44332009-09-09 15:08:12 +00006542
Douglas Gregorb98b1992009-08-11 05:31:07 +00006543template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006544ExprResult
John McCall454feb92009-12-08 09:21:05 +00006545TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006546 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006547}
6548
6549template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006550ExprResult
John McCall454feb92009-12-08 09:21:05 +00006551TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006552 switch (E->getOperator()) {
6553 case OO_New:
6554 case OO_Delete:
6555 case OO_Array_New:
6556 case OO_Array_Delete:
6557 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006558 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006559
Douglas Gregor668d6d92009-12-13 20:44:55 +00006560 case OO_Call: {
6561 // This is a call to an object's operator().
6562 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6563
6564 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006565 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006566 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006567 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006568
6569 // FIXME: Poor location information
6570 SourceLocation FakeLParenLoc
6571 = SemaRef.PP.getLocForEndOfToken(
6572 static_cast<Expr *>(Object.get())->getLocEnd());
6573
6574 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006575 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006576 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6577 Args))
6578 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006579
John McCall9ae2f072010-08-23 23:25:46 +00006580 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006581 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006582 E->getLocEnd());
6583 }
6584
6585#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6586 case OO_##Name:
6587#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6588#include "clang/Basic/OperatorKinds.def"
6589 case OO_Subscript:
6590 // Handled below.
6591 break;
6592
6593 case OO_Conditional:
6594 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006595 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006596
6597 case OO_None:
6598 case NUM_OVERLOADED_OPERATORS:
6599 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006600 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006601 }
6602
John McCall60d7b3a2010-08-24 06:29:42 +00006603 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006604 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006605 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006606
John McCall60d7b3a2010-08-24 06:29:42 +00006607 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006609 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610
John McCall60d7b3a2010-08-24 06:29:42 +00006611 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006612 if (E->getNumArgs() == 2) {
6613 Second = getDerived().TransformExpr(E->getArg(1));
6614 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006615 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006616 }
Mike Stump1eb44332009-09-09 15:08:12 +00006617
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618 if (!getDerived().AlwaysRebuild() &&
6619 Callee.get() == E->getCallee() &&
6620 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006621 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00006622 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006623
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6625 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006626 Callee.get(),
6627 First.get(),
6628 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629}
Mike Stump1eb44332009-09-09 15:08:12 +00006630
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006632ExprResult
John McCall454feb92009-12-08 09:21:05 +00006633TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6634 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635}
Mike Stump1eb44332009-09-09 15:08:12 +00006636
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006638ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006639TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6640 // Transform the callee.
6641 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6642 if (Callee.isInvalid())
6643 return ExprError();
6644
6645 // Transform exec config.
6646 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6647 if (EC.isInvalid())
6648 return ExprError();
6649
6650 // Transform arguments.
6651 bool ArgChanged = false;
6652 ASTOwningVector<Expr*> Args(SemaRef);
6653 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6654 &ArgChanged))
6655 return ExprError();
6656
6657 if (!getDerived().AlwaysRebuild() &&
6658 Callee.get() == E->getCallee() &&
6659 !ArgChanged)
6660 return SemaRef.Owned(E);
6661
6662 // FIXME: Wrong source location information for the '('.
6663 SourceLocation FakeLParenLoc
6664 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6665 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6666 move_arg(Args),
6667 E->getRParenLoc(), EC.get());
6668}
6669
6670template<typename Derived>
6671ExprResult
John McCall454feb92009-12-08 09:21:05 +00006672TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006673 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6674 if (!Type)
6675 return ExprError();
6676
John McCall60d7b3a2010-08-24 06:29:42 +00006677 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006678 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006679 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006680 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006681
Douglas Gregorb98b1992009-08-11 05:31:07 +00006682 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006683 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006685 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006686
Douglas Gregorb98b1992009-08-11 05:31:07 +00006687 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006688 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006689 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6690 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6691 SourceLocation FakeRParenLoc
6692 = SemaRef.PP.getLocForEndOfToken(
6693 E->getSubExpr()->getSourceRange().getEnd());
6694 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006695 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006696 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006697 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698 FakeRAngleLoc,
6699 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006700 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006701 FakeRParenLoc);
6702}
Mike Stump1eb44332009-09-09 15:08:12 +00006703
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006705ExprResult
John McCall454feb92009-12-08 09:21:05 +00006706TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6707 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006708}
Mike Stump1eb44332009-09-09 15:08:12 +00006709
6710template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006711ExprResult
John McCall454feb92009-12-08 09:21:05 +00006712TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6713 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006714}
6715
Douglas Gregorb98b1992009-08-11 05:31:07 +00006716template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006717ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006718TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006719 CXXReinterpretCastExpr *E) {
6720 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006721}
Mike Stump1eb44332009-09-09 15:08:12 +00006722
Douglas Gregorb98b1992009-08-11 05:31:07 +00006723template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006724ExprResult
John McCall454feb92009-12-08 09:21:05 +00006725TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6726 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006727}
Mike Stump1eb44332009-09-09 15:08:12 +00006728
Douglas Gregorb98b1992009-08-11 05:31:07 +00006729template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006730ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006731TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006732 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006733 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6734 if (!Type)
6735 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006736
John McCall60d7b3a2010-08-24 06:29:42 +00006737 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006738 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006740 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006741
Douglas Gregorb98b1992009-08-11 05:31:07 +00006742 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006743 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006744 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006745 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006746
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006747 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006748 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006749 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006750 E->getRParenLoc());
6751}
Mike Stump1eb44332009-09-09 15:08:12 +00006752
Douglas Gregorb98b1992009-08-11 05:31:07 +00006753template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006754ExprResult
John McCall454feb92009-12-08 09:21:05 +00006755TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006757 TypeSourceInfo *TInfo
6758 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6759 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006760 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006761
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006763 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006764 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006765
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006766 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6767 E->getLocStart(),
6768 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 E->getLocEnd());
6770 }
Mike Stump1eb44332009-09-09 15:08:12 +00006771
Douglas Gregorb98b1992009-08-11 05:31:07 +00006772 // We don't know whether the expression is potentially evaluated until
6773 // after we perform semantic analysis, so the expression is potentially
6774 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006775 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006776 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006777
John McCall60d7b3a2010-08-24 06:29:42 +00006778 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006779 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006780 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006781
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782 if (!getDerived().AlwaysRebuild() &&
6783 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006784 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006785
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006786 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6787 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006788 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006789 E->getLocEnd());
6790}
6791
6792template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006793ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006794TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6795 if (E->isTypeOperand()) {
6796 TypeSourceInfo *TInfo
6797 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6798 if (!TInfo)
6799 return ExprError();
6800
6801 if (!getDerived().AlwaysRebuild() &&
6802 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006803 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006804
Douglas Gregor3c52a212011-03-06 17:40:41 +00006805 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006806 E->getLocStart(),
6807 TInfo,
6808 E->getLocEnd());
6809 }
6810
6811 // We don't know whether the expression is potentially evaluated until
6812 // after we perform semantic analysis, so the expression is potentially
6813 // potentially evaluated.
6814 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6815
6816 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6817 if (SubExpr.isInvalid())
6818 return ExprError();
6819
6820 if (!getDerived().AlwaysRebuild() &&
6821 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006822 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006823
6824 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6825 E->getLocStart(),
6826 SubExpr.get(),
6827 E->getLocEnd());
6828}
6829
6830template<typename Derived>
6831ExprResult
John McCall454feb92009-12-08 09:21:05 +00006832TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006833 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834}
Mike Stump1eb44332009-09-09 15:08:12 +00006835
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006837ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006838TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006839 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006840 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841}
Mike Stump1eb44332009-09-09 15:08:12 +00006842
Douglas Gregorb98b1992009-08-11 05:31:07 +00006843template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006844ExprResult
John McCall454feb92009-12-08 09:21:05 +00006845TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006846 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00006847 QualType T;
6848 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6849 T = MD->getThisType(getSema().Context);
6850 else
6851 T = getSema().Context.getPointerType(
6852 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00006853
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006854 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006855 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006856
Douglas Gregor828a1972010-01-07 23:12:05 +00006857 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006858}
Mike Stump1eb44332009-09-09 15:08:12 +00006859
Douglas Gregorb98b1992009-08-11 05:31:07 +00006860template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006861ExprResult
John McCall454feb92009-12-08 09:21:05 +00006862TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006863 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006864 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006865 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006866
Douglas Gregorb98b1992009-08-11 05:31:07 +00006867 if (!getDerived().AlwaysRebuild() &&
6868 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006869 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870
Douglas Gregorbca01b42011-07-06 22:04:06 +00006871 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6872 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006873}
Mike Stump1eb44332009-09-09 15:08:12 +00006874
Douglas Gregorb98b1992009-08-11 05:31:07 +00006875template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006876ExprResult
John McCall454feb92009-12-08 09:21:05 +00006877TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006878 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006879 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6880 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006881 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006882 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006883
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006884 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006885 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006886 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006887
Douglas Gregor036aed12009-12-23 23:03:06 +00006888 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006889}
Mike Stump1eb44332009-09-09 15:08:12 +00006890
Douglas Gregorb98b1992009-08-11 05:31:07 +00006891template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006892ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006893TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6894 CXXScalarValueInitExpr *E) {
6895 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6896 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006897 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006898
Douglas Gregorb98b1992009-08-11 05:31:07 +00006899 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006900 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006901 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006902
Douglas Gregorab6677e2010-09-08 00:15:04 +00006903 return getDerived().RebuildCXXScalarValueInitExpr(T,
6904 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006905 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006906}
Mike Stump1eb44332009-09-09 15:08:12 +00006907
Douglas Gregorb98b1992009-08-11 05:31:07 +00006908template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006909ExprResult
John McCall454feb92009-12-08 09:21:05 +00006910TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006911 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006912 TypeSourceInfo *AllocTypeInfo
6913 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6914 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006915 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006916
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006918 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006920 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006921
Douglas Gregorb98b1992009-08-11 05:31:07 +00006922 // Transform the placement arguments (if any).
6923 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006924 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006925 if (getDerived().TransformExprs(E->getPlacementArgs(),
6926 E->getNumPlacementArgs(), true,
6927 PlacementArgs, &ArgumentChanged))
6928 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006929
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00006930 // Transform the constructor arguments (if any).
6931 // As an annoying corner case, we may have introduced an implicit value-
6932 // initialization expression when allocating a new array, which we implicitly
6933 // drop. It will be re-created during type checking.
John McCallca0408f2010-08-23 06:44:23 +00006934 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00006935 if (!(E->isArray() && E->getNumConstructorArgs() == 1 &&
6936 isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) &&
6937 TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006938 ConstructorArgs, &ArgumentChanged))
6939 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006940
Douglas Gregor1af74512010-02-26 00:38:10 +00006941 // Transform constructor, new operator, and delete operator.
6942 CXXConstructorDecl *Constructor = 0;
6943 if (E->getConstructor()) {
6944 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006945 getDerived().TransformDecl(E->getLocStart(),
6946 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006947 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006948 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006949 }
6950
6951 FunctionDecl *OperatorNew = 0;
6952 if (E->getOperatorNew()) {
6953 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006954 getDerived().TransformDecl(E->getLocStart(),
6955 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006956 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006957 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006958 }
6959
6960 FunctionDecl *OperatorDelete = 0;
6961 if (E->getOperatorDelete()) {
6962 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006963 getDerived().TransformDecl(E->getLocStart(),
6964 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006965 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006966 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006967 }
Sean Huntc3021132010-05-05 15:23:54 +00006968
Douglas Gregorb98b1992009-08-11 05:31:07 +00006969 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006970 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006971 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006972 Constructor == E->getConstructor() &&
6973 OperatorNew == E->getOperatorNew() &&
6974 OperatorDelete == E->getOperatorDelete() &&
6975 !ArgumentChanged) {
6976 // Mark any declarations we need as referenced.
6977 // FIXME: instantiation-specific.
6978 if (Constructor)
6979 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6980 if (OperatorNew)
6981 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6982 if (OperatorDelete)
6983 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00006984
6985 if (E->isArray() && Constructor &&
6986 !E->getAllocatedType()->isDependentType()) {
6987 QualType ElementType
6988 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
6989 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
6990 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
6991 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
6992 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
6993 }
6994 }
6995 }
6996
John McCall3fa5cae2010-10-26 07:05:15 +00006997 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006998 }
Mike Stump1eb44332009-09-09 15:08:12 +00006999
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007000 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007001 if (!ArraySize.get()) {
7002 // If no array size was specified, but the new expression was
7003 // instantiated with an array type (e.g., "new T" where T is
7004 // instantiated with "int[4]"), extract the outer bound from the
7005 // array type as our array size. We do this with constant and
7006 // dependently-sized array types.
7007 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7008 if (!ArrayT) {
7009 // Do nothing
7010 } else if (const ConstantArrayType *ConsArrayT
7011 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007012 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007013 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7014 ConsArrayT->getSize(),
7015 SemaRef.Context.getSizeType(),
7016 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007017 AllocType = ConsArrayT->getElementType();
7018 } else if (const DependentSizedArrayType *DepArrayT
7019 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7020 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007021 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007022 AllocType = DepArrayT->getElementType();
7023 }
7024 }
7025 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007026
Douglas Gregorb98b1992009-08-11 05:31:07 +00007027 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7028 E->isGlobalNew(),
7029 /*FIXME:*/E->getLocStart(),
7030 move_arg(PlacementArgs),
7031 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007032 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007034 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007035 ArraySize.get(),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007036 E->getConstructorLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037 move_arg(ConstructorArgs),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007038 E->getConstructorRParen());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007039}
Mike Stump1eb44332009-09-09 15:08:12 +00007040
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007042ExprResult
John McCall454feb92009-12-08 09:21:05 +00007043TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007044 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007046 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007047
Douglas Gregor1af74512010-02-26 00:38:10 +00007048 // Transform the delete operator, if known.
7049 FunctionDecl *OperatorDelete = 0;
7050 if (E->getOperatorDelete()) {
7051 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007052 getDerived().TransformDecl(E->getLocStart(),
7053 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007054 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007055 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007056 }
Sean Huntc3021132010-05-05 15:23:54 +00007057
Douglas Gregorb98b1992009-08-11 05:31:07 +00007058 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007059 Operand.get() == E->getArgument() &&
7060 OperatorDelete == E->getOperatorDelete()) {
7061 // Mark any declarations we need as referenced.
7062 // FIXME: instantiation-specific.
7063 if (OperatorDelete)
7064 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007065
7066 if (!E->getArgument()->isTypeDependent()) {
7067 QualType Destroyed = SemaRef.Context.getBaseElementType(
7068 E->getDestroyedType());
7069 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7070 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7071 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
7072 SemaRef.LookupDestructor(Record));
7073 }
7074 }
7075
John McCall3fa5cae2010-10-26 07:05:15 +00007076 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007077 }
Mike Stump1eb44332009-09-09 15:08:12 +00007078
Douglas Gregorb98b1992009-08-11 05:31:07 +00007079 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7080 E->isGlobalDelete(),
7081 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007082 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007083}
Mike Stump1eb44332009-09-09 15:08:12 +00007084
Douglas Gregorb98b1992009-08-11 05:31:07 +00007085template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007086ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007087TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007088 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007089 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007090 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007091 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007092
John McCallb3d87482010-08-24 05:47:05 +00007093 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007094 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007095 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007096 E->getOperatorLoc(),
7097 E->isArrow()? tok::arrow : tok::period,
7098 ObjectTypePtr,
7099 MayBePseudoDestructor);
7100 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007101 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007102
John McCallb3d87482010-08-24 05:47:05 +00007103 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007104 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7105 if (QualifierLoc) {
7106 QualifierLoc
7107 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7108 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007109 return ExprError();
7110 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007111 CXXScopeSpec SS;
7112 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007113
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007114 PseudoDestructorTypeStorage Destroyed;
7115 if (E->getDestroyedTypeInfo()) {
7116 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007117 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007118 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007119 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007120 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007121 Destroyed = DestroyedTypeInfo;
7122 } else if (ObjectType->isDependentType()) {
7123 // We aren't likely to be able to resolve the identifier down to a type
7124 // now anyway, so just retain the identifier.
7125 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7126 E->getDestroyedTypeLoc());
7127 } else {
7128 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007129 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007130 *E->getDestroyedTypeIdentifier(),
7131 E->getDestroyedTypeLoc(),
7132 /*Scope=*/0,
7133 SS, ObjectTypePtr,
7134 false);
7135 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007136 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007137
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007138 Destroyed
7139 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7140 E->getDestroyedTypeLoc());
7141 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007142
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007143 TypeSourceInfo *ScopeTypeInfo = 0;
7144 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007145 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007146 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007147 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007148 }
Sean Huntc3021132010-05-05 15:23:54 +00007149
John McCall9ae2f072010-08-23 23:25:46 +00007150 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007151 E->getOperatorLoc(),
7152 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007153 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007154 ScopeTypeInfo,
7155 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007156 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007157 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007158}
Mike Stump1eb44332009-09-09 15:08:12 +00007159
Douglas Gregora71d8192009-09-04 17:36:40 +00007160template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007161ExprResult
John McCallba135432009-11-21 08:51:07 +00007162TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007163 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007164 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7165 Sema::LookupOrdinaryName);
7166
7167 // Transform all the decls.
7168 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7169 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007170 NamedDecl *InstD = static_cast<NamedDecl*>(
7171 getDerived().TransformDecl(Old->getNameLoc(),
7172 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007173 if (!InstD) {
7174 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7175 // This can happen because of dependent hiding.
7176 if (isa<UsingShadowDecl>(*I))
7177 continue;
7178 else
John McCallf312b1e2010-08-26 23:41:50 +00007179 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007180 }
John McCallf7a1a742009-11-24 19:00:30 +00007181
7182 // Expand using declarations.
7183 if (isa<UsingDecl>(InstD)) {
7184 UsingDecl *UD = cast<UsingDecl>(InstD);
7185 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7186 E = UD->shadow_end(); I != E; ++I)
7187 R.addDecl(*I);
7188 continue;
7189 }
7190
7191 R.addDecl(InstD);
7192 }
7193
7194 // Resolve a kind, but don't do any further analysis. If it's
7195 // ambiguous, the callee needs to deal with it.
7196 R.resolveKind();
7197
7198 // Rebuild the nested-name qualifier, if present.
7199 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007200 if (Old->getQualifierLoc()) {
7201 NestedNameSpecifierLoc QualifierLoc
7202 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7203 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007204 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007205
Douglas Gregor4c9be892011-02-28 20:01:57 +00007206 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007207 }
7208
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007209 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007210 CXXRecordDecl *NamingClass
7211 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7212 Old->getNameLoc(),
7213 Old->getNamingClass()));
7214 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007215 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007216
Douglas Gregor66c45152010-04-27 16:10:10 +00007217 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007218 }
7219
7220 // If we have no template arguments, it's a normal declaration name.
7221 if (!Old->hasExplicitTemplateArgs())
7222 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7223
7224 // If we have template arguments, rebuild them, then rebuild the
7225 // templateid expression.
7226 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007227 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7228 Old->getNumTemplateArgs(),
7229 TransArgs))
7230 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007231
7232 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7233 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007234}
Mike Stump1eb44332009-09-09 15:08:12 +00007235
Douglas Gregorb98b1992009-08-11 05:31:07 +00007236template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007237ExprResult
John McCall454feb92009-12-08 09:21:05 +00007238TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007239 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7240 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007241 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007242
Douglas Gregorb98b1992009-08-11 05:31:07 +00007243 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007244 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007245 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007246
Mike Stump1eb44332009-09-09 15:08:12 +00007247 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007248 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007249 T,
7250 E->getLocEnd());
7251}
Mike Stump1eb44332009-09-09 15:08:12 +00007252
Douglas Gregorb98b1992009-08-11 05:31:07 +00007253template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007254ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007255TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7256 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7257 if (!LhsT)
7258 return ExprError();
7259
7260 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7261 if (!RhsT)
7262 return ExprError();
7263
7264 if (!getDerived().AlwaysRebuild() &&
7265 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7266 return SemaRef.Owned(E);
7267
7268 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7269 E->getLocStart(),
7270 LhsT, RhsT,
7271 E->getLocEnd());
7272}
7273
7274template<typename Derived>
7275ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007276TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7277 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7278 if (!T)
7279 return ExprError();
7280
7281 if (!getDerived().AlwaysRebuild() &&
7282 T == E->getQueriedTypeSourceInfo())
7283 return SemaRef.Owned(E);
7284
7285 ExprResult SubExpr;
7286 {
7287 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7288 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7289 if (SubExpr.isInvalid())
7290 return ExprError();
7291
7292 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7293 return SemaRef.Owned(E);
7294 }
7295
7296 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7297 E->getLocStart(),
7298 T,
7299 SubExpr.get(),
7300 E->getLocEnd());
7301}
7302
7303template<typename Derived>
7304ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007305TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7306 ExprResult SubExpr;
7307 {
7308 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7309 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7310 if (SubExpr.isInvalid())
7311 return ExprError();
7312
7313 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7314 return SemaRef.Owned(E);
7315 }
7316
7317 return getDerived().RebuildExpressionTrait(
7318 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7319}
7320
7321template<typename Derived>
7322ExprResult
John McCall865d4472009-11-19 22:55:06 +00007323TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007324 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007325 NestedNameSpecifierLoc QualifierLoc
7326 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7327 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007328 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007329
John McCall43fed0d2010-11-12 08:19:04 +00007330 // TODO: If this is a conversion-function-id, verify that the
7331 // destination type name (if present) resolves the same way after
7332 // instantiation as it did in the local scope.
7333
Abramo Bagnara25777432010-08-11 22:01:17 +00007334 DeclarationNameInfo NameInfo
7335 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7336 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007337 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007338
John McCallf7a1a742009-11-24 19:00:30 +00007339 if (!E->hasExplicitTemplateArgs()) {
7340 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007341 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007342 // Note: it is sufficient to compare the Name component of NameInfo:
7343 // if name has not changed, DNLoc has not changed either.
7344 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007345 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007346
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007347 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007348 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007349 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007350 }
John McCalld5532b62009-11-23 01:53:49 +00007351
7352 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007353 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7354 E->getNumTemplateArgs(),
7355 TransArgs))
7356 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007357
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007358 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007359 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007360 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007361}
7362
7363template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007364ExprResult
John McCall454feb92009-12-08 09:21:05 +00007365TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007366 // CXXConstructExprs are always implicit, so when we have a
7367 // 1-argument construction we just transform that argument.
7368 if (E->getNumArgs() == 1 ||
7369 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7370 return getDerived().TransformExpr(E->getArg(0));
7371
Douglas Gregorb98b1992009-08-11 05:31:07 +00007372 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7373
7374 QualType T = getDerived().TransformType(E->getType());
7375 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007376 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007377
7378 CXXConstructorDecl *Constructor
7379 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007380 getDerived().TransformDecl(E->getLocStart(),
7381 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007382 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007383 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007384
Douglas Gregorb98b1992009-08-11 05:31:07 +00007385 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007386 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007387 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7388 &ArgumentChanged))
7389 return ExprError();
7390
Douglas Gregorb98b1992009-08-11 05:31:07 +00007391 if (!getDerived().AlwaysRebuild() &&
7392 T == E->getType() &&
7393 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007394 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007395 // Mark the constructor as referenced.
7396 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00007397 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007398 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007399 }
Mike Stump1eb44332009-09-09 15:08:12 +00007400
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007401 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7402 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007403 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007404 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007405 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007406 E->getConstructionKind(),
7407 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007408}
Mike Stump1eb44332009-09-09 15:08:12 +00007409
Douglas Gregorb98b1992009-08-11 05:31:07 +00007410/// \brief Transform a C++ temporary-binding expression.
7411///
Douglas Gregor51326552009-12-24 18:51:59 +00007412/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7413/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007414template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007415ExprResult
John McCall454feb92009-12-08 09:21:05 +00007416TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007417 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007418}
Mike Stump1eb44332009-09-09 15:08:12 +00007419
John McCall4765fa02010-12-06 08:20:24 +00007420/// \brief Transform a C++ expression that contains cleanups that should
7421/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007422///
John McCall4765fa02010-12-06 08:20:24 +00007423/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007424/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007425template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007426ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007427TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007428 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007429}
Mike Stump1eb44332009-09-09 15:08:12 +00007430
Douglas Gregorb98b1992009-08-11 05:31:07 +00007431template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007432ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007433TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007434 CXXTemporaryObjectExpr *E) {
7435 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7436 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007437 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007438
Douglas Gregorb98b1992009-08-11 05:31:07 +00007439 CXXConstructorDecl *Constructor
7440 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007441 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007442 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007443 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007444 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007445
Douglas Gregorb98b1992009-08-11 05:31:07 +00007446 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007447 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007448 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007449 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7450 &ArgumentChanged))
7451 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007452
Douglas Gregorb98b1992009-08-11 05:31:07 +00007453 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007454 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007455 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007456 !ArgumentChanged) {
7457 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00007458 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007459 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007460 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007461
7462 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7463 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007464 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007465 E->getLocEnd());
7466}
Mike Stump1eb44332009-09-09 15:08:12 +00007467
Douglas Gregorb98b1992009-08-11 05:31:07 +00007468template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007469ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007470TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007471 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007472 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7473 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007474 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007475
Douglas Gregorb98b1992009-08-11 05:31:07 +00007476 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007477 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007478 Args.reserve(E->arg_size());
7479 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7480 &ArgumentChanged))
7481 return ExprError();
7482
Douglas Gregorb98b1992009-08-11 05:31:07 +00007483 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007484 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007485 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007486 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007487
Douglas Gregorb98b1992009-08-11 05:31:07 +00007488 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007489 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007490 E->getLParenLoc(),
7491 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007492 E->getRParenLoc());
7493}
Mike Stump1eb44332009-09-09 15:08:12 +00007494
Douglas Gregorb98b1992009-08-11 05:31:07 +00007495template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007496ExprResult
John McCall865d4472009-11-19 22:55:06 +00007497TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007498 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007499 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007500 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007501 Expr *OldBase;
7502 QualType BaseType;
7503 QualType ObjectType;
7504 if (!E->isImplicitAccess()) {
7505 OldBase = E->getBase();
7506 Base = getDerived().TransformExpr(OldBase);
7507 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007508 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007509
John McCallaa81e162009-12-01 22:10:20 +00007510 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007511 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007512 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007513 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007514 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007515 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007516 ObjectTy,
7517 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007518 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007519 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007520
John McCallb3d87482010-08-24 05:47:05 +00007521 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007522 BaseType = ((Expr*) Base.get())->getType();
7523 } else {
7524 OldBase = 0;
7525 BaseType = getDerived().TransformType(E->getBaseType());
7526 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7527 }
Mike Stump1eb44332009-09-09 15:08:12 +00007528
Douglas Gregor6cd21982009-10-20 05:58:46 +00007529 // Transform the first part of the nested-name-specifier that qualifies
7530 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007531 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007532 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007533 E->getFirstQualifierFoundInScope(),
7534 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007535
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007536 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007537 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007538 QualifierLoc
7539 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7540 ObjectType,
7541 FirstQualifierInScope);
7542 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007543 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007544 }
Mike Stump1eb44332009-09-09 15:08:12 +00007545
John McCall43fed0d2010-11-12 08:19:04 +00007546 // TODO: If this is a conversion-function-id, verify that the
7547 // destination type name (if present) resolves the same way after
7548 // instantiation as it did in the local scope.
7549
Abramo Bagnara25777432010-08-11 22:01:17 +00007550 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007551 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007552 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007553 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007554
John McCallaa81e162009-12-01 22:10:20 +00007555 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007556 // This is a reference to a member without an explicitly-specified
7557 // template argument list. Optimize for this common case.
7558 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007559 Base.get() == OldBase &&
7560 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007561 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007562 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007563 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007564 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007565
John McCall9ae2f072010-08-23 23:25:46 +00007566 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007567 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007568 E->isArrow(),
7569 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007570 QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00007571 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007572 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007573 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007574 }
7575
John McCalld5532b62009-11-23 01:53:49 +00007576 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007577 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7578 E->getNumTemplateArgs(),
7579 TransArgs))
7580 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007581
John McCall9ae2f072010-08-23 23:25:46 +00007582 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007583 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007584 E->isArrow(),
7585 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007586 QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007587 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007588 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007589 &TransArgs);
7590}
7591
7592template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007593ExprResult
John McCall454feb92009-12-08 09:21:05 +00007594TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007595 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007596 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007597 QualType BaseType;
7598 if (!Old->isImplicitAccess()) {
7599 Base = getDerived().TransformExpr(Old->getBase());
7600 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007601 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007602 BaseType = ((Expr*) Base.get())->getType();
7603 } else {
7604 BaseType = getDerived().TransformType(Old->getBaseType());
7605 }
John McCall129e2df2009-11-30 22:42:35 +00007606
Douglas Gregor4c9be892011-02-28 20:01:57 +00007607 NestedNameSpecifierLoc QualifierLoc;
7608 if (Old->getQualifierLoc()) {
7609 QualifierLoc
7610 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7611 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007612 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007613 }
7614
Abramo Bagnara25777432010-08-11 22:01:17 +00007615 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007616 Sema::LookupOrdinaryName);
7617
7618 // Transform all the decls.
7619 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7620 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007621 NamedDecl *InstD = static_cast<NamedDecl*>(
7622 getDerived().TransformDecl(Old->getMemberLoc(),
7623 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007624 if (!InstD) {
7625 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7626 // This can happen because of dependent hiding.
7627 if (isa<UsingShadowDecl>(*I))
7628 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007629 else {
7630 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007631 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007632 }
John McCall9f54ad42009-12-10 09:41:52 +00007633 }
John McCall129e2df2009-11-30 22:42:35 +00007634
7635 // Expand using declarations.
7636 if (isa<UsingDecl>(InstD)) {
7637 UsingDecl *UD = cast<UsingDecl>(InstD);
7638 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7639 E = UD->shadow_end(); I != E; ++I)
7640 R.addDecl(*I);
7641 continue;
7642 }
7643
7644 R.addDecl(InstD);
7645 }
7646
7647 R.resolveKind();
7648
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007649 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007650 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007651 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007652 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007653 Old->getMemberLoc(),
7654 Old->getNamingClass()));
7655 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007656 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007657
Douglas Gregor66c45152010-04-27 16:10:10 +00007658 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007659 }
Sean Huntc3021132010-05-05 15:23:54 +00007660
John McCall129e2df2009-11-30 22:42:35 +00007661 TemplateArgumentListInfo TransArgs;
7662 if (Old->hasExplicitTemplateArgs()) {
7663 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7664 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007665 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7666 Old->getNumTemplateArgs(),
7667 TransArgs))
7668 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007669 }
John McCallc2233c52010-01-15 08:34:02 +00007670
7671 // FIXME: to do this check properly, we will need to preserve the
7672 // first-qualifier-in-scope here, just in case we had a dependent
7673 // base (and therefore couldn't do the check) and a
7674 // nested-name-qualifier (and therefore could do the lookup).
7675 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007676
John McCall9ae2f072010-08-23 23:25:46 +00007677 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007678 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007679 Old->getOperatorLoc(),
7680 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007681 QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00007682 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007683 R,
7684 (Old->hasExplicitTemplateArgs()
7685 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007686}
7687
7688template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007689ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007690TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00007691 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00007692 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7693 if (SubExpr.isInvalid())
7694 return ExprError();
7695
7696 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007697 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007698
7699 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7700}
7701
7702template<typename Derived>
7703ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007704TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007705 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7706 if (Pattern.isInvalid())
7707 return ExprError();
7708
7709 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7710 return SemaRef.Owned(E);
7711
Douglas Gregor67fd1252011-01-14 21:20:45 +00007712 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7713 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007714}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007715
7716template<typename Derived>
7717ExprResult
7718TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7719 // If E is not value-dependent, then nothing will change when we transform it.
7720 // Note: This is an instantiation-centric view.
7721 if (!E->isValueDependent())
7722 return SemaRef.Owned(E);
7723
7724 // Note: None of the implementations of TryExpandParameterPacks can ever
7725 // produce a diagnostic when given only a single unexpanded parameter pack,
7726 // so
7727 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7728 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007729 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007730 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007731 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00007732 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00007733 ShouldExpand, RetainExpansion,
7734 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007735 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007736
Douglas Gregor089e8932011-10-10 18:59:29 +00007737 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007738 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00007739
7740 NamedDecl *Pack = E->getPack();
7741 if (!ShouldExpand) {
7742 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
7743 Pack));
7744 if (!Pack)
7745 return ExprError();
7746 }
7747
Douglas Gregoree8aff02011-01-04 17:33:58 +00007748
7749 // We now know the length of the parameter pack, so build a new expression
7750 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00007751 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00007752 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00007753 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007754}
7755
Douglas Gregorbe230c32011-01-03 17:17:50 +00007756template<typename Derived>
7757ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007758TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7759 SubstNonTypeTemplateParmPackExpr *E) {
7760 // Default behavior is to do nothing with this transformation.
7761 return SemaRef.Owned(E);
7762}
7763
7764template<typename Derived>
7765ExprResult
John McCall91a57552011-07-15 05:09:51 +00007766TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7767 SubstNonTypeTemplateParmExpr *E) {
7768 // Default behavior is to do nothing with this transformation.
7769 return SemaRef.Owned(E);
7770}
7771
7772template<typename Derived>
7773ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00007774TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7775 MaterializeTemporaryExpr *E) {
7776 return getDerived().TransformExpr(E->GetTemporaryExpr());
7777}
7778
7779template<typename Derived>
7780ExprResult
John McCall454feb92009-12-08 09:21:05 +00007781TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007782 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007783}
7784
Mike Stump1eb44332009-09-09 15:08:12 +00007785template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007786ExprResult
John McCall454feb92009-12-08 09:21:05 +00007787TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007788 TypeSourceInfo *EncodedTypeInfo
7789 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7790 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007791 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007792
Douglas Gregorb98b1992009-08-11 05:31:07 +00007793 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007794 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007795 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007796
7797 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007798 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007799 E->getRParenLoc());
7800}
Mike Stump1eb44332009-09-09 15:08:12 +00007801
Douglas Gregorb98b1992009-08-11 05:31:07 +00007802template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00007803ExprResult TreeTransform<Derived>::
7804TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7805 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7806 if (result.isInvalid()) return ExprError();
7807 Expr *subExpr = result.take();
7808
7809 if (!getDerived().AlwaysRebuild() &&
7810 subExpr == E->getSubExpr())
7811 return SemaRef.Owned(E);
7812
7813 return SemaRef.Owned(new(SemaRef.Context)
7814 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7815}
7816
7817template<typename Derived>
7818ExprResult TreeTransform<Derived>::
7819TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7820 TypeSourceInfo *TSInfo
7821 = getDerived().TransformType(E->getTypeInfoAsWritten());
7822 if (!TSInfo)
7823 return ExprError();
7824
7825 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7826 if (Result.isInvalid())
7827 return ExprError();
7828
7829 if (!getDerived().AlwaysRebuild() &&
7830 TSInfo == E->getTypeInfoAsWritten() &&
7831 Result.get() == E->getSubExpr())
7832 return SemaRef.Owned(E);
7833
7834 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7835 E->getBridgeKeywordLoc(), TSInfo,
7836 Result.get());
7837}
7838
7839template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007840ExprResult
John McCall454feb92009-12-08 09:21:05 +00007841TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007842 // Transform arguments.
7843 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007844 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007845 Args.reserve(E->getNumArgs());
7846 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7847 &ArgChanged))
7848 return ExprError();
7849
Douglas Gregor92e986e2010-04-22 16:44:27 +00007850 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7851 // Class message: transform the receiver type.
7852 TypeSourceInfo *ReceiverTypeInfo
7853 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7854 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007855 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007856
Douglas Gregor92e986e2010-04-22 16:44:27 +00007857 // If nothing changed, just retain the existing message send.
7858 if (!getDerived().AlwaysRebuild() &&
7859 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007860 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007861
7862 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007863 SmallVector<SourceLocation, 16> SelLocs;
7864 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007865 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7866 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007867 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00007868 E->getMethodDecl(),
7869 E->getLeftLoc(),
7870 move_arg(Args),
7871 E->getRightLoc());
7872 }
7873
7874 // Instance message: transform the receiver
7875 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7876 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007877 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007878 = getDerived().TransformExpr(E->getInstanceReceiver());
7879 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007880 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007881
7882 // If nothing changed, just retain the existing message send.
7883 if (!getDerived().AlwaysRebuild() &&
7884 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007885 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007886
Douglas Gregor92e986e2010-04-22 16:44:27 +00007887 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007888 SmallVector<SourceLocation, 16> SelLocs;
7889 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00007890 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007891 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007892 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00007893 E->getMethodDecl(),
7894 E->getLeftLoc(),
7895 move_arg(Args),
7896 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007897}
7898
Mike Stump1eb44332009-09-09 15:08:12 +00007899template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007900ExprResult
John McCall454feb92009-12-08 09:21:05 +00007901TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007902 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007903}
7904
Mike Stump1eb44332009-09-09 15:08:12 +00007905template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007906ExprResult
John McCall454feb92009-12-08 09:21:05 +00007907TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007908 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007909}
7910
Mike Stump1eb44332009-09-09 15:08:12 +00007911template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007912ExprResult
John McCall454feb92009-12-08 09:21:05 +00007913TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007914 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007915 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007916 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007917 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007918
7919 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007920
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007921 // If nothing changed, just retain the existing expression.
7922 if (!getDerived().AlwaysRebuild() &&
7923 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007924 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007925
John McCall9ae2f072010-08-23 23:25:46 +00007926 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007927 E->getLocation(),
7928 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007929}
7930
Mike Stump1eb44332009-09-09 15:08:12 +00007931template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007932ExprResult
John McCall454feb92009-12-08 09:21:05 +00007933TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00007934 // 'super' and types never change. Property never changes. Just
7935 // retain the existing expression.
7936 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00007937 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00007938
Douglas Gregore3303542010-04-26 20:47:02 +00007939 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007940 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00007941 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007942 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007943
Douglas Gregore3303542010-04-26 20:47:02 +00007944 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007945
Douglas Gregore3303542010-04-26 20:47:02 +00007946 // If nothing changed, just retain the existing expression.
7947 if (!getDerived().AlwaysRebuild() &&
7948 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007949 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007950
John McCall12f78a62010-12-02 01:19:52 +00007951 if (E->isExplicitProperty())
7952 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7953 E->getExplicitProperty(),
7954 E->getLocation());
7955
7956 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7957 E->getType(),
7958 E->getImplicitPropertyGetter(),
7959 E->getImplicitPropertySetter(),
7960 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007961}
7962
Mike Stump1eb44332009-09-09 15:08:12 +00007963template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007964ExprResult
John McCall454feb92009-12-08 09:21:05 +00007965TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007966 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007967 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007968 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007969 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007970
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007971 // If nothing changed, just retain the existing expression.
7972 if (!getDerived().AlwaysRebuild() &&
7973 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007974 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007975
John McCall9ae2f072010-08-23 23:25:46 +00007976 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007977 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007978}
7979
Mike Stump1eb44332009-09-09 15:08:12 +00007980template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007981ExprResult
John McCall454feb92009-12-08 09:21:05 +00007982TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007983 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007984 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007985 SubExprs.reserve(E->getNumSubExprs());
7986 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7987 SubExprs, &ArgumentChanged))
7988 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007989
Douglas Gregorb98b1992009-08-11 05:31:07 +00007990 if (!getDerived().AlwaysRebuild() &&
7991 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007992 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007993
Douglas Gregorb98b1992009-08-11 05:31:07 +00007994 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7995 move_arg(SubExprs),
7996 E->getRParenLoc());
7997}
7998
Mike Stump1eb44332009-09-09 15:08:12 +00007999template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008000ExprResult
John McCall454feb92009-12-08 09:21:05 +00008001TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008002 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008003
John McCallc6ac9c32011-02-04 18:33:18 +00008004 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8005 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8006
8007 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008008 // We built a new blockScopeInfo in call to ActOnBlockStart
8009 // in above, CapturesCXXThis need be set here from the block
8010 // expression.
8011 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
8012
Chris Lattner686775d2011-07-20 06:58:45 +00008013 SmallVector<ParmVarDecl*, 4> params;
8014 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008015
8016 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008017 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8018 oldBlock->param_begin(),
8019 oldBlock->param_size(),
8020 0, paramTypes, &params))
Douglas Gregora779d9c2011-01-19 21:32:01 +00008021 return true;
John McCallc6ac9c32011-02-04 18:33:18 +00008022
8023 const FunctionType *exprFunctionType = E->getFunctionType();
8024 QualType exprResultType = exprFunctionType->getResultType();
8025 if (!exprResultType.isNull()) {
8026 if (!exprResultType->isDependentType())
8027 blockScope->ReturnType = exprResultType;
8028 else if (exprResultType != getSema().Context.DependentTy)
8029 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008030 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008031
8032 // If the return type has not been determined yet, leave it as a dependent
8033 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00008034 if (blockScope->ReturnType.isNull())
8035 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00008036
8037 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00008038 if (blockScope->ReturnType->isObjCObjectType()) {
8039 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008040 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00008041 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00008042 return ExprError();
8043 }
John McCall711c52b2011-01-05 12:14:39 +00008044
John McCallc6ac9c32011-02-04 18:33:18 +00008045 QualType functionType = getDerived().RebuildFunctionProtoType(
8046 blockScope->ReturnType,
8047 paramTypes.data(),
8048 paramTypes.size(),
8049 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00008050 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008051 exprFunctionType->getExtInfo());
8052 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008053
8054 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008055 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008056 blockScope->TheDecl->setParams(params);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008057
8058 // If the return type wasn't explicitly set, it will have been marked as a
8059 // dependent type (DependentTy); clear out the return type setting so
8060 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00008061 if (blockScope->ReturnType == getSema().Context.DependentTy)
8062 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00008063
John McCall711c52b2011-01-05 12:14:39 +00008064 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008065 StmtResult body = getDerived().TransformStmt(E->getBody());
8066 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00008067 return ExprError();
8068
John McCallc6ac9c32011-02-04 18:33:18 +00008069#ifndef NDEBUG
8070 // In builds with assertions, make sure that we captured everything we
8071 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008072 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8073 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8074 e = oldBlock->capture_end(); i != e; ++i) {
8075 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008076
Douglas Gregorfc921372011-05-20 15:32:55 +00008077 // Ignore parameter packs.
8078 if (isa<ParmVarDecl>(oldCapture) &&
8079 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8080 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008081
Douglas Gregorfc921372011-05-20 15:32:55 +00008082 VarDecl *newCapture =
8083 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8084 oldCapture));
8085 assert(blockScope->CaptureMap.count(newCapture));
8086 }
John McCallc6ac9c32011-02-04 18:33:18 +00008087 }
8088#endif
8089
8090 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8091 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008092}
8093
Mike Stump1eb44332009-09-09 15:08:12 +00008094template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008095ExprResult
John McCall454feb92009-12-08 09:21:05 +00008096TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008097 ValueDecl *ND
8098 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8099 E->getDecl()));
8100 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00008101 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00008102
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008103 if (!getDerived().AlwaysRebuild() &&
8104 ND == E->getDecl()) {
8105 // Mark it referenced in the new context regardless.
8106 // FIXME: this is a bit instantiation-specific.
8107 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8108
John McCall3fa5cae2010-10-26 07:05:15 +00008109 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008110 }
8111
Abramo Bagnara25777432010-08-11 22:01:17 +00008112 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00008113 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00008114 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008115}
Mike Stump1eb44332009-09-09 15:08:12 +00008116
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008117template<typename Derived>
8118ExprResult
8119TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008120 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008121}
Eli Friedman276b0612011-10-11 02:20:01 +00008122
8123template<typename Derived>
8124ExprResult
8125TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008126 QualType RetTy = getDerived().TransformType(E->getType());
8127 bool ArgumentChanged = false;
8128 ASTOwningVector<Expr*> SubExprs(SemaRef);
8129 SubExprs.reserve(E->getNumSubExprs());
8130 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8131 SubExprs, &ArgumentChanged))
8132 return ExprError();
8133
8134 if (!getDerived().AlwaysRebuild() &&
8135 !ArgumentChanged)
8136 return SemaRef.Owned(E);
8137
8138 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8139 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008140}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008141
Douglas Gregorb98b1992009-08-11 05:31:07 +00008142//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008143// Type reconstruction
8144//===----------------------------------------------------------------------===//
8145
Mike Stump1eb44332009-09-09 15:08:12 +00008146template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008147QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8148 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008149 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008150 getDerived().getBaseEntity());
8151}
8152
Mike Stump1eb44332009-09-09 15:08:12 +00008153template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008154QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8155 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008156 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008157 getDerived().getBaseEntity());
8158}
8159
Mike Stump1eb44332009-09-09 15:08:12 +00008160template<typename Derived>
8161QualType
John McCall85737a72009-10-30 00:06:24 +00008162TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8163 bool WrittenAsLValue,
8164 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008165 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008166 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008167}
8168
8169template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008170QualType
John McCall85737a72009-10-30 00:06:24 +00008171TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8172 QualType ClassType,
8173 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008174 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008175 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008176}
8177
8178template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008179QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008180TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8181 ArrayType::ArraySizeModifier SizeMod,
8182 const llvm::APInt *Size,
8183 Expr *SizeExpr,
8184 unsigned IndexTypeQuals,
8185 SourceRange BracketsRange) {
8186 if (SizeExpr || !Size)
8187 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8188 IndexTypeQuals, BracketsRange,
8189 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008190
8191 QualType Types[] = {
8192 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8193 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8194 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008195 };
8196 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8197 QualType SizeType;
8198 for (unsigned I = 0; I != NumTypes; ++I)
8199 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8200 SizeType = Types[I];
8201 break;
8202 }
Mike Stump1eb44332009-09-09 15:08:12 +00008203
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008204 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8205 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00008206 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008207 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008208 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008209}
Mike Stump1eb44332009-09-09 15:08:12 +00008210
Douglas Gregor577f75a2009-08-04 16:50:30 +00008211template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008212QualType
8213TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008214 ArrayType::ArraySizeModifier SizeMod,
8215 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008216 unsigned IndexTypeQuals,
8217 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008218 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008219 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008220}
8221
8222template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008223QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008224TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008225 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008226 unsigned IndexTypeQuals,
8227 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008228 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008229 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008230}
Mike Stump1eb44332009-09-09 15:08:12 +00008231
Douglas Gregor577f75a2009-08-04 16:50:30 +00008232template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008233QualType
8234TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008235 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008236 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008237 unsigned IndexTypeQuals,
8238 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008239 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008240 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008241 IndexTypeQuals, BracketsRange);
8242}
8243
8244template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008245QualType
8246TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008247 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008248 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008249 unsigned IndexTypeQuals,
8250 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008251 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008252 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008253 IndexTypeQuals, BracketsRange);
8254}
8255
8256template<typename Derived>
8257QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008258 unsigned NumElements,
8259 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008260 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008261 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008262}
Mike Stump1eb44332009-09-09 15:08:12 +00008263
Douglas Gregor577f75a2009-08-04 16:50:30 +00008264template<typename Derived>
8265QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8266 unsigned NumElements,
8267 SourceLocation AttributeLoc) {
8268 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8269 NumElements, true);
8270 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008271 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8272 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008273 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008274}
Mike Stump1eb44332009-09-09 15:08:12 +00008275
Douglas Gregor577f75a2009-08-04 16:50:30 +00008276template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008277QualType
8278TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008279 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008280 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008281 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008282}
Mike Stump1eb44332009-09-09 15:08:12 +00008283
Douglas Gregor577f75a2009-08-04 16:50:30 +00008284template<typename Derived>
8285QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008286 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008287 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008288 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00008289 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008290 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008291 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008292 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00008293 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008294 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008295 getDerived().getBaseEntity(),
8296 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008297}
Mike Stump1eb44332009-09-09 15:08:12 +00008298
Douglas Gregor577f75a2009-08-04 16:50:30 +00008299template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008300QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8301 return SemaRef.Context.getFunctionNoProtoType(T);
8302}
8303
8304template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008305QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8306 assert(D && "no decl found");
8307 if (D->isInvalidDecl()) return QualType();
8308
Douglas Gregor92e986e2010-04-22 16:44:27 +00008309 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008310 TypeDecl *Ty;
8311 if (isa<UsingDecl>(D)) {
8312 UsingDecl *Using = cast<UsingDecl>(D);
8313 assert(Using->isTypeName() &&
8314 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8315
8316 // A valid resolved using typename decl points to exactly one type decl.
8317 assert(++Using->shadow_begin() == Using->shadow_end());
8318 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008319
John McCalled976492009-12-04 22:46:56 +00008320 } else {
8321 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8322 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8323 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8324 }
8325
8326 return SemaRef.Context.getTypeDeclType(Ty);
8327}
8328
8329template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008330QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8331 SourceLocation Loc) {
8332 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008333}
8334
8335template<typename Derived>
8336QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8337 return SemaRef.Context.getTypeOfType(Underlying);
8338}
8339
8340template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008341QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8342 SourceLocation Loc) {
8343 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008344}
8345
8346template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008347QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8348 UnaryTransformType::UTTKind UKind,
8349 SourceLocation Loc) {
8350 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8351}
8352
8353template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008354QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008355 TemplateName Template,
8356 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008357 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008358 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008359}
Mike Stump1eb44332009-09-09 15:08:12 +00008360
Douglas Gregordcee1a12009-08-06 05:28:30 +00008361template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00008362QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8363 SourceLocation KWLoc) {
8364 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8365}
8366
8367template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008368TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008369TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008370 bool TemplateKW,
8371 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008372 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008373 Template);
8374}
8375
8376template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008377TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008378TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8379 const IdentifierInfo &Name,
8380 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008381 QualType ObjectType,
8382 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008383 UnqualifiedId TemplateName;
8384 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008385 Sema::TemplateTy Template;
8386 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008387 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008388 SS,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008389 TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008390 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008391 /*EnteringContext=*/false,
8392 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008393 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008394}
Mike Stump1eb44332009-09-09 15:08:12 +00008395
Douglas Gregorb98b1992009-08-11 05:31:07 +00008396template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008397TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008398TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008399 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008400 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008401 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008402 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008403 // FIXME: Bogus location information.
8404 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8405 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008406 Sema::TemplateTy Template;
8407 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008408 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008409 SS,
8410 Name,
John McCallb3d87482010-08-24 05:47:05 +00008411 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008412 /*EnteringContext=*/false,
8413 Template);
8414 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008415}
Sean Huntc3021132010-05-05 15:23:54 +00008416
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008417template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008418ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008419TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8420 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008421 Expr *OrigCallee,
8422 Expr *First,
8423 Expr *Second) {
8424 Expr *Callee = OrigCallee->IgnoreParenCasts();
8425 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008426
Douglas Gregorb98b1992009-08-11 05:31:07 +00008427 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008428 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008429 if (!First->getType()->isOverloadableType() &&
8430 !Second->getType()->isOverloadableType())
8431 return getSema().CreateBuiltinArraySubscriptExpr(First,
8432 Callee->getLocStart(),
8433 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008434 } else if (Op == OO_Arrow) {
8435 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008436 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8437 } else if (Second == 0 || isPostIncDec) {
8438 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008439 // The argument is not of overloadable type, so try to create a
8440 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008441 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008442 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008443
John McCall9ae2f072010-08-23 23:25:46 +00008444 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008445 }
8446 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008447 if (!First->getType()->isOverloadableType() &&
8448 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008449 // Neither of the arguments is an overloadable type, so try to
8450 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008451 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008452 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008453 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008454 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008455 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008456
Douglas Gregorb98b1992009-08-11 05:31:07 +00008457 return move(Result);
8458 }
8459 }
Mike Stump1eb44332009-09-09 15:08:12 +00008460
8461 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008462 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008463 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008464
John McCall9ae2f072010-08-23 23:25:46 +00008465 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008466 assert(ULE->requiresADL());
8467
8468 // FIXME: Do we have to check
8469 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008470 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008471 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008472 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008473 }
Mike Stump1eb44332009-09-09 15:08:12 +00008474
Douglas Gregorb98b1992009-08-11 05:31:07 +00008475 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008476 Expr *Args[2] = { First, Second };
8477 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008478
Douglas Gregorb98b1992009-08-11 05:31:07 +00008479 // Create the overloaded operator invocation for unary operators.
8480 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008481 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008482 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008483 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008484 }
Mike Stump1eb44332009-09-09 15:08:12 +00008485
Douglas Gregor5b8968c2011-07-15 16:25:15 +00008486 if (Op == OO_Subscript) {
8487 SourceLocation LBrace;
8488 SourceLocation RBrace;
8489
8490 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8491 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8492 LBrace = SourceLocation::getFromRawEncoding(
8493 NameLoc.CXXOperatorName.BeginOpNameLoc);
8494 RBrace = SourceLocation::getFromRawEncoding(
8495 NameLoc.CXXOperatorName.EndOpNameLoc);
8496 } else {
8497 LBrace = Callee->getLocStart();
8498 RBrace = OpLoc;
8499 }
8500
8501 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8502 First, Second);
8503 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00008504
Douglas Gregorb98b1992009-08-11 05:31:07 +00008505 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008506 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008507 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008508 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8509 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008510 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008511
Mike Stump1eb44332009-09-09 15:08:12 +00008512 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008513}
Mike Stump1eb44332009-09-09 15:08:12 +00008514
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008515template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008516ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008517TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008518 SourceLocation OperatorLoc,
8519 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008520 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008521 TypeSourceInfo *ScopeType,
8522 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008523 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008524 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008525 QualType BaseType = Base->getType();
8526 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008527 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008528 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008529 !BaseType->getAs<PointerType>()->getPointeeType()
8530 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008531 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008532 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008533 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008534 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008535 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008536 /*FIXME?*/true);
8537 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008538
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008539 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008540 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8541 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8542 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8543 NameInfo.setNamedTypeInfo(DestroyedType);
8544
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008545 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008546
John McCall9ae2f072010-08-23 23:25:46 +00008547 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008548 OperatorLoc, isArrow,
8549 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008550 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008551 /*TemplateArgs*/ 0);
8552}
8553
Douglas Gregor577f75a2009-08-04 16:50:30 +00008554} // end namespace clang
8555
8556#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H