blob: b4073eb650e883351a0d4df96a45e21a868d9387 [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();
Richard Smith97f9fe02011-10-25 00:41:24 +00001488 if (isArrow) {
1489 BaseResult = getSema().DefaultLvalueConversion(BaseResult.get());
1490 if (BaseResult.isInvalid())
1491 return ExprError();
1492 }
John Wiegley429bb272011-04-08 18:41:53 +00001493 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001494 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001495
John McCall6bb80172010-03-30 21:47:33 +00001496 // FIXME: this involves duplicating earlier analysis in a lot of
1497 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001498 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001499 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001500 R.resolveKind();
1501
John McCall9ae2f072010-08-23 23:25:46 +00001502 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001503 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001504 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 }
Mike Stump1eb44332009-09-09 15:08:12 +00001506
Douglas Gregorb98b1992009-08-11 05:31:07 +00001507 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001508 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001509 /// By default, performs semantic analysis to build the new expression.
1510 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001511 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001512 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001513 Expr *LHS, Expr *RHS) {
1514 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 }
1516
1517 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001518 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001519 /// By default, performs semantic analysis to build the new expression.
1520 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001521 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001522 SourceLocation QuestionLoc,
1523 Expr *LHS,
1524 SourceLocation ColonLoc,
1525 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001526 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1527 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001528 }
1529
Douglas Gregorb98b1992009-08-11 05:31:07 +00001530 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001531 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001532 /// By default, performs semantic analysis to build the new expression.
1533 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001534 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001535 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001536 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001537 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001538 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001539 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001540 }
Mike Stump1eb44332009-09-09 15:08:12 +00001541
Douglas Gregorb98b1992009-08-11 05:31:07 +00001542 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001543 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001544 /// By default, performs semantic analysis to build the new expression.
1545 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001546 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001547 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001548 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001549 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001550 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001551 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001552 }
Mike Stump1eb44332009-09-09 15:08:12 +00001553
Douglas Gregorb98b1992009-08-11 05:31:07 +00001554 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001555 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001556 /// By default, performs semantic analysis to build the new expression.
1557 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001558 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 SourceLocation OpLoc,
1560 SourceLocation AccessorLoc,
1561 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001562
John McCall129e2df2009-11-30 22:42:35 +00001563 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001564 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001565 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001566 OpLoc, /*IsArrow*/ false,
1567 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001568 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001569 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 }
Mike Stump1eb44332009-09-09 15:08:12 +00001571
Douglas Gregorb98b1992009-08-11 05:31:07 +00001572 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001573 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001574 /// By default, performs semantic analysis to build the new expression.
1575 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001576 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001577 MultiExprArg Inits,
1578 SourceLocation RBraceLoc,
1579 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001580 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001581 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1582 if (Result.isInvalid() || ResultTy->isDependentType())
1583 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001584
Douglas Gregore48319a2009-11-09 17:16:50 +00001585 // Patch in the result type we were given, which may have been computed
1586 // when the initial InitListExpr was built.
1587 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1588 ILE->setType(ResultTy);
1589 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 }
Mike Stump1eb44332009-09-09 15:08:12 +00001591
Douglas Gregorb98b1992009-08-11 05:31:07 +00001592 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001593 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001594 /// By default, performs semantic analysis to build the new expression.
1595 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001596 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001597 MultiExprArg ArrayExprs,
1598 SourceLocation EqualOrColonLoc,
1599 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001600 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001601 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001603 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001605 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001606
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 ArrayExprs.release();
1608 return move(Result);
1609 }
Mike Stump1eb44332009-09-09 15:08:12 +00001610
Douglas Gregorb98b1992009-08-11 05:31:07 +00001611 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001612 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001613 /// By default, builds the implicit value initialization without performing
1614 /// any semantic analysis. Subclasses may override this routine to provide
1615 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001616 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001617 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1618 }
Mike Stump1eb44332009-09-09 15:08:12 +00001619
Douglas Gregorb98b1992009-08-11 05:31:07 +00001620 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001621 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001622 /// By default, performs semantic analysis to build the new expression.
1623 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001624 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001625 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001626 SourceLocation RParenLoc) {
1627 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001628 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001629 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 }
1631
1632 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001633 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001634 /// By default, performs semantic analysis to build the new expression.
1635 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001636 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001637 MultiExprArg SubExprs,
1638 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001639 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001640 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001641 }
Mike Stump1eb44332009-09-09 15:08:12 +00001642
Douglas Gregorb98b1992009-08-11 05:31:07 +00001643 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001644 ///
1645 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 /// rather than attempting to map the label statement itself.
1647 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001648 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001649 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001650 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001651 }
Mike Stump1eb44332009-09-09 15:08:12 +00001652
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001654 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 /// By default, performs semantic analysis to build the new expression.
1656 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001657 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001658 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001659 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001660 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001661 }
Mike Stump1eb44332009-09-09 15:08:12 +00001662
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 /// \brief Build a new __builtin_choose_expr expression.
1664 ///
1665 /// By default, performs semantic analysis to build the new expression.
1666 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001667 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001668 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001669 SourceLocation RParenLoc) {
1670 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001671 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 RParenLoc);
1673 }
Mike Stump1eb44332009-09-09 15:08:12 +00001674
Peter Collingbournef111d932011-04-15 00:35:48 +00001675 /// \brief Build a new generic selection expression.
1676 ///
1677 /// By default, performs semantic analysis to build the new expression.
1678 /// Subclasses may override this routine to provide different behavior.
1679 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1680 SourceLocation DefaultLoc,
1681 SourceLocation RParenLoc,
1682 Expr *ControllingExpr,
1683 TypeSourceInfo **Types,
1684 Expr **Exprs,
1685 unsigned NumAssocs) {
1686 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1687 ControllingExpr, Types, Exprs,
1688 NumAssocs);
1689 }
1690
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 /// \brief Build a new overloaded operator call expression.
1692 ///
1693 /// By default, performs semantic analysis to build the new expression.
1694 /// The semantic analysis provides the behavior of template instantiation,
1695 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001696 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697 /// argument-dependent lookup, etc. Subclasses may override this routine to
1698 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001699 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001700 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001701 Expr *Callee,
1702 Expr *First,
1703 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001704
1705 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001706 /// reinterpret_cast.
1707 ///
1708 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001709 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001710 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001711 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 Stmt::StmtClass Class,
1713 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001714 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001715 SourceLocation RAngleLoc,
1716 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001717 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 SourceLocation RParenLoc) {
1719 switch (Class) {
1720 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001721 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001722 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001723 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001724
1725 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001726 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001727 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001728 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001729
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001731 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001732 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001733 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001734 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001735
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001737 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001738 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001739 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001740
Douglas Gregorb98b1992009-08-11 05:31:07 +00001741 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001742 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001743 }
Mike Stump1eb44332009-09-09 15:08:12 +00001744
John McCallf312b1e2010-08-26 23:41:50 +00001745 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 }
Mike Stump1eb44332009-09-09 15:08:12 +00001747
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 /// \brief Build a new C++ static_cast expression.
1749 ///
1750 /// By default, performs semantic analysis to build the new expression.
1751 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001752 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001754 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 SourceLocation RAngleLoc,
1756 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001757 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001758 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001759 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001760 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001761 SourceRange(LAngleLoc, RAngleLoc),
1762 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001763 }
1764
1765 /// \brief Build a new C++ dynamic_cast expression.
1766 ///
1767 /// By default, performs semantic analysis to build the new expression.
1768 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001769 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001771 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001772 SourceLocation RAngleLoc,
1773 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001774 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001776 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001777 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001778 SourceRange(LAngleLoc, RAngleLoc),
1779 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001780 }
1781
1782 /// \brief Build a new C++ reinterpret_cast expression.
1783 ///
1784 /// By default, performs semantic analysis to build the new expression.
1785 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001786 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001788 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 SourceLocation RAngleLoc,
1790 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001791 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001793 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001794 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001795 SourceRange(LAngleLoc, RAngleLoc),
1796 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 }
1798
1799 /// \brief Build a new C++ const_cast expression.
1800 ///
1801 /// By default, performs semantic analysis to build the new expression.
1802 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001803 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001805 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001806 SourceLocation RAngleLoc,
1807 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001808 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001810 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001811 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001812 SourceRange(LAngleLoc, RAngleLoc),
1813 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001814 }
Mike Stump1eb44332009-09-09 15:08:12 +00001815
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 /// \brief Build a new C++ functional-style cast expression.
1817 ///
1818 /// By default, performs semantic analysis to build the new expression.
1819 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001820 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1821 SourceLocation LParenLoc,
1822 Expr *Sub,
1823 SourceLocation RParenLoc) {
1824 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001825 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 RParenLoc);
1827 }
Mike Stump1eb44332009-09-09 15:08:12 +00001828
Douglas Gregorb98b1992009-08-11 05:31:07 +00001829 /// \brief Build a new C++ typeid(type) expression.
1830 ///
1831 /// By default, performs semantic analysis to build the new expression.
1832 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001833 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001834 SourceLocation TypeidLoc,
1835 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001836 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001837 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001838 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001839 }
Mike Stump1eb44332009-09-09 15:08:12 +00001840
Francois Pichet01b7c302010-09-08 12:20:18 +00001841
Douglas Gregorb98b1992009-08-11 05:31:07 +00001842 /// \brief Build a new C++ typeid(expr) expression.
1843 ///
1844 /// By default, performs semantic analysis to build the new expression.
1845 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001846 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001847 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001848 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001849 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001850 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001851 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001852 }
1853
Francois Pichet01b7c302010-09-08 12:20:18 +00001854 /// \brief Build a new C++ __uuidof(type) expression.
1855 ///
1856 /// By default, performs semantic analysis to build the new expression.
1857 /// Subclasses may override this routine to provide different behavior.
1858 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1859 SourceLocation TypeidLoc,
1860 TypeSourceInfo *Operand,
1861 SourceLocation RParenLoc) {
1862 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1863 RParenLoc);
1864 }
1865
1866 /// \brief Build a new C++ __uuidof(expr) expression.
1867 ///
1868 /// By default, performs semantic analysis to build the new expression.
1869 /// Subclasses may override this routine to provide different behavior.
1870 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1871 SourceLocation TypeidLoc,
1872 Expr *Operand,
1873 SourceLocation RParenLoc) {
1874 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1875 RParenLoc);
1876 }
1877
Douglas Gregorb98b1992009-08-11 05:31:07 +00001878 /// \brief Build a new C++ "this" expression.
1879 ///
1880 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001881 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001882 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001883 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001884 QualType ThisType,
1885 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001886 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001887 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1888 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 }
1890
1891 /// \brief Build a new C++ throw expression.
1892 ///
1893 /// By default, performs semantic analysis to build the new expression.
1894 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001895 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1896 bool IsThrownVariableInScope) {
1897 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001898 }
1899
1900 /// \brief Build a new C++ default-argument expression.
1901 ///
1902 /// By default, builds a new default-argument expression, which does not
1903 /// require any semantic analysis. Subclasses may override this routine to
1904 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001905 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001906 ParmVarDecl *Param) {
1907 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1908 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001909 }
1910
1911 /// \brief Build a new C++ zero-initialization expression.
1912 ///
1913 /// By default, performs semantic analysis to build the new expression.
1914 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001915 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1916 SourceLocation LParenLoc,
1917 SourceLocation RParenLoc) {
1918 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001919 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001920 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001921 }
Mike Stump1eb44332009-09-09 15:08:12 +00001922
Douglas Gregorb98b1992009-08-11 05:31:07 +00001923 /// \brief Build a new C++ "new" expression.
1924 ///
1925 /// By default, performs semantic analysis to build the new expression.
1926 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001927 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001928 bool UseGlobal,
1929 SourceLocation PlacementLParen,
1930 MultiExprArg PlacementArgs,
1931 SourceLocation PlacementRParen,
1932 SourceRange TypeIdParens,
1933 QualType AllocatedType,
1934 TypeSourceInfo *AllocatedTypeInfo,
1935 Expr *ArraySize,
1936 SourceLocation ConstructorLParen,
1937 MultiExprArg ConstructorArgs,
1938 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001939 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001940 PlacementLParen,
1941 move(PlacementArgs),
1942 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001943 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001944 AllocatedType,
1945 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001946 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001947 ConstructorLParen,
1948 move(ConstructorArgs),
1949 ConstructorRParen);
1950 }
Mike Stump1eb44332009-09-09 15:08:12 +00001951
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 /// \brief Build a new C++ "delete" expression.
1953 ///
1954 /// By default, performs semantic analysis to build the new expression.
1955 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001956 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001957 bool IsGlobalDelete,
1958 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001959 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001961 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001962 }
Mike Stump1eb44332009-09-09 15:08:12 +00001963
Douglas Gregorb98b1992009-08-11 05:31:07 +00001964 /// \brief Build a new unary type trait expression.
1965 ///
1966 /// By default, performs semantic analysis to build the new expression.
1967 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001968 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001969 SourceLocation StartLoc,
1970 TypeSourceInfo *T,
1971 SourceLocation RParenLoc) {
1972 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 }
1974
Francois Pichet6ad6f282010-12-07 00:08:36 +00001975 /// \brief Build a new binary type trait expression.
1976 ///
1977 /// By default, performs semantic analysis to build the new expression.
1978 /// Subclasses may override this routine to provide different behavior.
1979 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1980 SourceLocation StartLoc,
1981 TypeSourceInfo *LhsT,
1982 TypeSourceInfo *RhsT,
1983 SourceLocation RParenLoc) {
1984 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1985 }
1986
John Wiegley21ff2e52011-04-28 00:16:57 +00001987 /// \brief Build a new array type trait expression.
1988 ///
1989 /// By default, performs semantic analysis to build the new expression.
1990 /// Subclasses may override this routine to provide different behavior.
1991 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1992 SourceLocation StartLoc,
1993 TypeSourceInfo *TSInfo,
1994 Expr *DimExpr,
1995 SourceLocation RParenLoc) {
1996 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1997 }
1998
John Wiegley55262202011-04-25 06:54:41 +00001999 /// \brief Build a new expression trait expression.
2000 ///
2001 /// By default, performs semantic analysis to build the new expression.
2002 /// Subclasses may override this routine to provide different behavior.
2003 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2004 SourceLocation StartLoc,
2005 Expr *Queried,
2006 SourceLocation RParenLoc) {
2007 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2008 }
2009
Mike Stump1eb44332009-09-09 15:08:12 +00002010 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002011 /// expression.
2012 ///
2013 /// By default, performs semantic analysis to build the new expression.
2014 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002015 ExprResult RebuildDependentScopeDeclRefExpr(
2016 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002017 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002018 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002019 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002020 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002021
2022 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00002023 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002024 *TemplateArgs);
2025
Abramo Bagnara25777432010-08-11 22:01:17 +00002026 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002027 }
2028
2029 /// \brief Build a new template-id expression.
2030 ///
2031 /// By default, performs semantic analysis to build the new expression.
2032 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002033 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00002034 LookupResult &R,
2035 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00002036 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00002037 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002038 }
2039
2040 /// \brief Build a new object-construction expression.
2041 ///
2042 /// By default, performs semantic analysis to build the new expression.
2043 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002044 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002045 SourceLocation Loc,
2046 CXXConstructorDecl *Constructor,
2047 bool IsElidable,
2048 MultiExprArg Args,
2049 bool HadMultipleCandidates,
2050 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002051 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002052 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002053 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002054 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002055 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002056 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002057
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002058 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002059 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002060 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002061 RequiresZeroInit, ConstructKind,
2062 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002063 }
2064
2065 /// \brief Build a new object-construction expression.
2066 ///
2067 /// By default, performs semantic analysis to build the new expression.
2068 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002069 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2070 SourceLocation LParenLoc,
2071 MultiExprArg Args,
2072 SourceLocation RParenLoc) {
2073 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002074 LParenLoc,
2075 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002076 RParenLoc);
2077 }
2078
2079 /// \brief Build a new object-construction expression.
2080 ///
2081 /// By default, performs semantic analysis to build the new expression.
2082 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002083 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2084 SourceLocation LParenLoc,
2085 MultiExprArg Args,
2086 SourceLocation RParenLoc) {
2087 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002088 LParenLoc,
2089 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002090 RParenLoc);
2091 }
Mike Stump1eb44332009-09-09 15:08:12 +00002092
Douglas Gregorb98b1992009-08-11 05:31:07 +00002093 /// \brief Build a new member reference expression.
2094 ///
2095 /// By default, performs semantic analysis to build the new expression.
2096 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002097 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002098 QualType BaseType,
2099 bool IsArrow,
2100 SourceLocation OperatorLoc,
2101 NestedNameSpecifierLoc QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00002102 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002103 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002104 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002105 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002106 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002107
John McCall9ae2f072010-08-23 23:25:46 +00002108 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002109 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00002110 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002111 MemberNameInfo,
2112 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002113 }
2114
John McCall129e2df2009-11-30 22:42:35 +00002115 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002116 ///
2117 /// By default, performs semantic analysis to build the new expression.
2118 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002119 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00002120 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00002121 SourceLocation OperatorLoc,
2122 bool IsArrow,
Douglas Gregor4c9be892011-02-28 20:01:57 +00002123 NestedNameSpecifierLoc QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00002124 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00002125 LookupResult &R,
2126 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002127 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002128 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002129
John McCall9ae2f072010-08-23 23:25:46 +00002130 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002131 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00002132 SS, FirstQualifierInScope,
2133 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002134 }
Mike Stump1eb44332009-09-09 15:08:12 +00002135
Sebastian Redl2e156222010-09-10 20:55:43 +00002136 /// \brief Build a new noexcept expression.
2137 ///
2138 /// By default, performs semantic analysis to build the new expression.
2139 /// Subclasses may override this routine to provide different behavior.
2140 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2141 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2142 }
2143
Douglas Gregoree8aff02011-01-04 17:33:58 +00002144 /// \brief Build a new expression to compute the length of a parameter pack.
2145 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2146 SourceLocation PackLoc,
2147 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002148 llvm::Optional<unsigned> Length) {
2149 if (Length)
2150 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2151 OperatorLoc, Pack, PackLoc,
2152 RParenLoc, *Length);
2153
Douglas Gregoree8aff02011-01-04 17:33:58 +00002154 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2155 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002156 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002157 }
2158
Douglas Gregorb98b1992009-08-11 05:31:07 +00002159 /// \brief Build a new Objective-C @encode expression.
2160 ///
2161 /// By default, performs semantic analysis to build the new expression.
2162 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002163 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002164 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002165 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002166 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002167 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002168 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002169
Douglas Gregor92e986e2010-04-22 16:44:27 +00002170 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002171 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002172 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002173 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002174 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002175 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002176 MultiExprArg Args,
2177 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002178 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2179 ReceiverTypeInfo->getType(),
2180 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002181 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002182 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002183 }
2184
2185 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002186 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002187 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002188 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002189 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002190 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002191 MultiExprArg Args,
2192 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002193 return SemaRef.BuildInstanceMessage(Receiver,
2194 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002195 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002196 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002197 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002198 }
2199
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002200 /// \brief Build a new Objective-C ivar reference expression.
2201 ///
2202 /// By default, performs semantic analysis to build the new expression.
2203 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002204 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002205 SourceLocation IvarLoc,
2206 bool IsArrow, bool IsFreeIvar) {
2207 // FIXME: We lose track of the IsFreeIvar bit.
2208 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002209 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002210 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2211 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002212 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002213 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002214 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002215 false);
John Wiegley429bb272011-04-08 18:41:53 +00002216 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002217 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002218
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002219 if (Result.get())
2220 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002221
John Wiegley429bb272011-04-08 18:41:53 +00002222 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002223 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002224 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002225 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002226 /*TemplateArgs=*/0);
2227 }
Douglas Gregore3303542010-04-26 20:47:02 +00002228
2229 /// \brief Build a new Objective-C property reference expression.
2230 ///
2231 /// By default, performs semantic analysis to build the new expression.
2232 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002233 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002234 ObjCPropertyDecl *Property,
2235 SourceLocation PropertyLoc) {
2236 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002237 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002238 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2239 Sema::LookupMemberName);
2240 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002241 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002242 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002243 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002244 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002245 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002246
Douglas Gregore3303542010-04-26 20:47:02 +00002247 if (Result.get())
2248 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002249
John Wiegley429bb272011-04-08 18:41:53 +00002250 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002251 /*FIXME:*/PropertyLoc, IsArrow,
2252 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002253 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002254 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002255 /*TemplateArgs=*/0);
2256 }
Sean Huntc3021132010-05-05 15:23:54 +00002257
John McCall12f78a62010-12-02 01:19:52 +00002258 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002259 ///
2260 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002261 /// Subclasses may override this routine to provide different behavior.
2262 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2263 ObjCMethodDecl *Getter,
2264 ObjCMethodDecl *Setter,
2265 SourceLocation PropertyLoc) {
2266 // Since these expressions can only be value-dependent, we do not
2267 // need to perform semantic analysis again.
2268 return Owned(
2269 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2270 VK_LValue, OK_ObjCProperty,
2271 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002272 }
2273
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002274 /// \brief Build a new Objective-C "isa" expression.
2275 ///
2276 /// By default, performs semantic analysis to build the new expression.
2277 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002278 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002279 bool IsArrow) {
2280 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002281 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002282 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2283 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002284 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002285 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002286 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002287 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002288 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002289
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002290 if (Result.get())
2291 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002292
John Wiegley429bb272011-04-08 18:41:53 +00002293 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002294 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002295 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002296 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002297 /*TemplateArgs=*/0);
2298 }
Sean Huntc3021132010-05-05 15:23:54 +00002299
Douglas Gregorb98b1992009-08-11 05:31:07 +00002300 /// \brief Build a new shuffle vector expression.
2301 ///
2302 /// By default, performs semantic analysis to build the new expression.
2303 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002304 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002305 MultiExprArg SubExprs,
2306 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002307 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002308 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002309 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2310 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2311 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2312 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002313
Douglas Gregorb98b1992009-08-11 05:31:07 +00002314 // Build a reference to the __builtin_shufflevector builtin
2315 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002316 ExprResult Callee
2317 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2318 VK_LValue, BuiltinLoc));
2319 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2320 if (Callee.isInvalid())
2321 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002322
2323 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002324 unsigned NumSubExprs = SubExprs.size();
2325 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002326 ExprResult TheCall = SemaRef.Owned(
2327 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002328 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002329 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002330 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002331 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002332
Douglas Gregorb98b1992009-08-11 05:31:07 +00002333 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002334 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002335 }
John McCall43fed0d2010-11-12 08:19:04 +00002336
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002337 /// \brief Build a new template argument pack expansion.
2338 ///
2339 /// By default, performs semantic analysis to build a new pack expansion
2340 /// for a template argument. Subclasses may override this routine to provide
2341 /// different behavior.
2342 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002343 SourceLocation EllipsisLoc,
2344 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002345 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002346 case TemplateArgument::Expression: {
2347 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002348 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2349 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002350 if (Result.isInvalid())
2351 return TemplateArgumentLoc();
2352
2353 return TemplateArgumentLoc(Result.get(), Result.get());
2354 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002355
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002356 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002357 return TemplateArgumentLoc(TemplateArgument(
2358 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002359 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002360 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002361 Pattern.getTemplateNameLoc(),
2362 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002363
2364 case TemplateArgument::Null:
2365 case TemplateArgument::Integral:
2366 case TemplateArgument::Declaration:
2367 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002368 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002369 llvm_unreachable("Pack expansion pattern has no parameter packs");
2370
2371 case TemplateArgument::Type:
2372 if (TypeSourceInfo *Expansion
2373 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002374 EllipsisLoc,
2375 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002376 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2377 Expansion);
2378 break;
2379 }
2380
2381 return TemplateArgumentLoc();
2382 }
2383
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002384 /// \brief Build a new expression pack expansion.
2385 ///
2386 /// By default, performs semantic analysis to build a new pack expansion
2387 /// for an expression. Subclasses may override this routine to provide
2388 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002389 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2390 llvm::Optional<unsigned> NumExpansions) {
2391 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002392 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002393
2394 /// \brief Build a new atomic operation expression.
2395 ///
2396 /// By default, performs semantic analysis to build the new expression.
2397 /// Subclasses may override this routine to provide different behavior.
2398 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2399 MultiExprArg SubExprs,
2400 QualType RetTy,
2401 AtomicExpr::AtomicOp Op,
2402 SourceLocation RParenLoc) {
2403 // Just create the expression; there is not any interesting semantic
2404 // analysis here because we can't actually build an AtomicExpr until
2405 // we are sure it is semantically sound.
2406 unsigned NumSubExprs = SubExprs.size();
2407 Expr **Subs = (Expr **)SubExprs.release();
2408 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2409 NumSubExprs, RetTy, Op,
2410 RParenLoc);
2411 }
2412
John McCall43fed0d2010-11-12 08:19:04 +00002413private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002414 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2415 QualType ObjectType,
2416 NamedDecl *FirstQualifierInScope,
2417 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002418
2419 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2420 QualType ObjectType,
2421 NamedDecl *FirstQualifierInScope,
2422 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002423};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002424
Douglas Gregor43959a92009-08-20 07:17:43 +00002425template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002426StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002427 if (!S)
2428 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002429
Douglas Gregor43959a92009-08-20 07:17:43 +00002430 switch (S->getStmtClass()) {
2431 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002432
Douglas Gregor43959a92009-08-20 07:17:43 +00002433 // Transform individual statement nodes
2434#define STMT(Node, Parent) \
2435 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002436#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002437#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002438#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002439
Douglas Gregor43959a92009-08-20 07:17:43 +00002440 // Transform expressions by calling TransformExpr.
2441#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002442#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002443#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002444#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002445 {
John McCall60d7b3a2010-08-24 06:29:42 +00002446 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002447 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002448 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002449
John McCall9ae2f072010-08-23 23:25:46 +00002450 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002451 }
Mike Stump1eb44332009-09-09 15:08:12 +00002452 }
2453
John McCall3fa5cae2010-10-26 07:05:15 +00002454 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002455}
Mike Stump1eb44332009-09-09 15:08:12 +00002456
2457
Douglas Gregor670444e2009-08-04 22:27:00 +00002458template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002459ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002460 if (!E)
2461 return SemaRef.Owned(E);
2462
2463 switch (E->getStmtClass()) {
2464 case Stmt::NoStmtClass: break;
2465#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002466#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002467#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002468 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002469#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002470 }
2471
John McCall3fa5cae2010-10-26 07:05:15 +00002472 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002473}
2474
2475template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002476bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2477 unsigned NumInputs,
2478 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002479 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002480 bool *ArgChanged) {
2481 for (unsigned I = 0; I != NumInputs; ++I) {
2482 // If requested, drop call arguments that need to be dropped.
2483 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2484 if (ArgChanged)
2485 *ArgChanged = true;
2486
2487 break;
2488 }
2489
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002490 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2491 Expr *Pattern = Expansion->getPattern();
2492
Chris Lattner686775d2011-07-20 06:58:45 +00002493 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002494 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2495 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2496
2497 // Determine whether the set of unexpanded parameter packs can and should
2498 // be expanded.
2499 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002500 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002501 llvm::Optional<unsigned> OrigNumExpansions
2502 = Expansion->getNumExpansions();
2503 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002504 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2505 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002506 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002507 Expand, RetainExpansion,
2508 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002509 return true;
2510
2511 if (!Expand) {
2512 // The transform has determined that we should perform a simple
2513 // transformation on the pack expansion, producing another pack
2514 // expansion.
2515 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2516 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2517 if (OutPattern.isInvalid())
2518 return true;
2519
2520 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002521 Expansion->getEllipsisLoc(),
2522 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002523 if (Out.isInvalid())
2524 return true;
2525
2526 if (ArgChanged)
2527 *ArgChanged = true;
2528 Outputs.push_back(Out.get());
2529 continue;
2530 }
John McCallc8fc90a2011-07-06 07:30:07 +00002531
2532 // Record right away that the argument was changed. This needs
2533 // to happen even if the array expands to nothing.
2534 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002535
2536 // The transform has determined that we should perform an elementwise
2537 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002538 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002539 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2540 ExprResult Out = getDerived().TransformExpr(Pattern);
2541 if (Out.isInvalid())
2542 return true;
2543
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002544 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002545 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2546 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002547 if (Out.isInvalid())
2548 return true;
2549 }
2550
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002551 Outputs.push_back(Out.get());
2552 }
2553
2554 continue;
2555 }
2556
Douglas Gregoraa165f82011-01-03 19:04:46 +00002557 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2558 if (Result.isInvalid())
2559 return true;
2560
2561 if (Result.get() != Inputs[I] && ArgChanged)
2562 *ArgChanged = true;
2563
2564 Outputs.push_back(Result.get());
2565 }
2566
2567 return false;
2568}
2569
2570template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002571NestedNameSpecifierLoc
2572TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2573 NestedNameSpecifierLoc NNS,
2574 QualType ObjectType,
2575 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002576 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002577 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2578 Qualifier = Qualifier.getPrefix())
2579 Qualifiers.push_back(Qualifier);
2580
2581 CXXScopeSpec SS;
2582 while (!Qualifiers.empty()) {
2583 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2584 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2585
2586 switch (QNNS->getKind()) {
2587 case NestedNameSpecifier::Identifier:
2588 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2589 *QNNS->getAsIdentifier(),
2590 Q.getLocalBeginLoc(),
2591 Q.getLocalEndLoc(),
2592 ObjectType, false, SS,
2593 FirstQualifierInScope, false))
2594 return NestedNameSpecifierLoc();
2595
2596 break;
2597
2598 case NestedNameSpecifier::Namespace: {
2599 NamespaceDecl *NS
2600 = cast_or_null<NamespaceDecl>(
2601 getDerived().TransformDecl(
2602 Q.getLocalBeginLoc(),
2603 QNNS->getAsNamespace()));
2604 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2605 break;
2606 }
2607
2608 case NestedNameSpecifier::NamespaceAlias: {
2609 NamespaceAliasDecl *Alias
2610 = cast_or_null<NamespaceAliasDecl>(
2611 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2612 QNNS->getAsNamespaceAlias()));
2613 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2614 Q.getLocalEndLoc());
2615 break;
2616 }
2617
2618 case NestedNameSpecifier::Global:
2619 // There is no meaningful transformation that one could perform on the
2620 // global scope.
2621 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2622 break;
2623
2624 case NestedNameSpecifier::TypeSpecWithTemplate:
2625 case NestedNameSpecifier::TypeSpec: {
2626 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2627 FirstQualifierInScope, SS);
2628
2629 if (!TL)
2630 return NestedNameSpecifierLoc();
2631
2632 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2633 (SemaRef.getLangOptions().CPlusPlus0x &&
2634 TL.getType()->isEnumeralType())) {
2635 assert(!TL.getType().hasLocalQualifiers() &&
2636 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002637 if (TL.getType()->isEnumeralType())
2638 SemaRef.Diag(TL.getBeginLoc(),
2639 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002640 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2641 Q.getLocalEndLoc());
2642 break;
2643 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002644 // If the nested-name-specifier is an invalid type def, don't emit an
2645 // error because a previous error should have already been emitted.
2646 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2647 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2648 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2649 << TL.getType() << SS.getRange();
2650 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002651 return NestedNameSpecifierLoc();
2652 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002653 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002654
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002655 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002656 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002657 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002658 }
2659
2660 // Don't rebuild the nested-name-specifier if we don't have to.
2661 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2662 !getDerived().AlwaysRebuild())
2663 return NNS;
2664
2665 // If we can re-use the source-location data from the original
2666 // nested-name-specifier, do so.
2667 if (SS.location_size() == NNS.getDataLength() &&
2668 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2669 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2670
2671 // Allocate new nested-name-specifier location information.
2672 return SS.getWithLocInContext(SemaRef.Context);
2673}
2674
2675template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002676DeclarationNameInfo
2677TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002678::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002679 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002680 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002681 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002682
2683 switch (Name.getNameKind()) {
2684 case DeclarationName::Identifier:
2685 case DeclarationName::ObjCZeroArgSelector:
2686 case DeclarationName::ObjCOneArgSelector:
2687 case DeclarationName::ObjCMultiArgSelector:
2688 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002689 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002690 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002691 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002692
Douglas Gregor81499bb2009-09-03 22:13:48 +00002693 case DeclarationName::CXXConstructorName:
2694 case DeclarationName::CXXDestructorName:
2695 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002696 TypeSourceInfo *NewTInfo;
2697 CanQualType NewCanTy;
2698 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002699 NewTInfo = getDerived().TransformType(OldTInfo);
2700 if (!NewTInfo)
2701 return DeclarationNameInfo();
2702 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002703 }
2704 else {
2705 NewTInfo = 0;
2706 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002707 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002708 if (NewT.isNull())
2709 return DeclarationNameInfo();
2710 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2711 }
Mike Stump1eb44332009-09-09 15:08:12 +00002712
Abramo Bagnara25777432010-08-11 22:01:17 +00002713 DeclarationName NewName
2714 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2715 NewCanTy);
2716 DeclarationNameInfo NewNameInfo(NameInfo);
2717 NewNameInfo.setName(NewName);
2718 NewNameInfo.setNamedTypeInfo(NewTInfo);
2719 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002720 }
Mike Stump1eb44332009-09-09 15:08:12 +00002721 }
2722
David Blaikieb219cfc2011-09-23 05:06:16 +00002723 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002724}
2725
2726template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002727TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002728TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2729 TemplateName Name,
2730 SourceLocation NameLoc,
2731 QualType ObjectType,
2732 NamedDecl *FirstQualifierInScope) {
2733 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2734 TemplateDecl *Template = QTN->getTemplateDecl();
2735 assert(Template && "qualified template name must refer to a template");
2736
2737 TemplateDecl *TransTemplate
2738 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2739 Template));
2740 if (!TransTemplate)
2741 return TemplateName();
2742
2743 if (!getDerived().AlwaysRebuild() &&
2744 SS.getScopeRep() == QTN->getQualifier() &&
2745 TransTemplate == Template)
2746 return Name;
2747
2748 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2749 TransTemplate);
2750 }
2751
2752 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2753 if (SS.getScopeRep()) {
2754 // These apply to the scope specifier, not the template.
2755 ObjectType = QualType();
2756 FirstQualifierInScope = 0;
2757 }
2758
2759 if (!getDerived().AlwaysRebuild() &&
2760 SS.getScopeRep() == DTN->getQualifier() &&
2761 ObjectType.isNull())
2762 return Name;
2763
2764 if (DTN->isIdentifier()) {
2765 return getDerived().RebuildTemplateName(SS,
2766 *DTN->getIdentifier(),
2767 NameLoc,
2768 ObjectType,
2769 FirstQualifierInScope);
2770 }
2771
2772 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2773 ObjectType);
2774 }
2775
2776 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2777 TemplateDecl *TransTemplate
2778 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2779 Template));
2780 if (!TransTemplate)
2781 return TemplateName();
2782
2783 if (!getDerived().AlwaysRebuild() &&
2784 TransTemplate == Template)
2785 return Name;
2786
2787 return TemplateName(TransTemplate);
2788 }
2789
2790 if (SubstTemplateTemplateParmPackStorage *SubstPack
2791 = Name.getAsSubstTemplateTemplateParmPack()) {
2792 TemplateTemplateParmDecl *TransParam
2793 = cast_or_null<TemplateTemplateParmDecl>(
2794 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2795 if (!TransParam)
2796 return TemplateName();
2797
2798 if (!getDerived().AlwaysRebuild() &&
2799 TransParam == SubstPack->getParameterPack())
2800 return Name;
2801
2802 return getDerived().RebuildTemplateName(TransParam,
2803 SubstPack->getArgumentPack());
2804 }
2805
2806 // These should be getting filtered out before they reach the AST.
2807 llvm_unreachable("overloaded function decl survived to here");
2808 return TemplateName();
2809}
2810
2811template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002812void TreeTransform<Derived>::InventTemplateArgumentLoc(
2813 const TemplateArgument &Arg,
2814 TemplateArgumentLoc &Output) {
2815 SourceLocation Loc = getDerived().getBaseLocation();
2816 switch (Arg.getKind()) {
2817 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002818 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002819 break;
2820
2821 case TemplateArgument::Type:
2822 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002823 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002824
John McCall833ca992009-10-29 08:12:44 +00002825 break;
2826
Douglas Gregor788cd062009-11-11 01:00:40 +00002827 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002828 case TemplateArgument::TemplateExpansion: {
2829 NestedNameSpecifierLocBuilder Builder;
2830 TemplateName Template = Arg.getAsTemplate();
2831 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2832 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2833 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2834 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2835
2836 if (Arg.getKind() == TemplateArgument::Template)
2837 Output = TemplateArgumentLoc(Arg,
2838 Builder.getWithLocInContext(SemaRef.Context),
2839 Loc);
2840 else
2841 Output = TemplateArgumentLoc(Arg,
2842 Builder.getWithLocInContext(SemaRef.Context),
2843 Loc, Loc);
2844
Douglas Gregor788cd062009-11-11 01:00:40 +00002845 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002846 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002847
John McCall833ca992009-10-29 08:12:44 +00002848 case TemplateArgument::Expression:
2849 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2850 break;
2851
2852 case TemplateArgument::Declaration:
2853 case TemplateArgument::Integral:
2854 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002855 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002856 break;
2857 }
2858}
2859
2860template<typename Derived>
2861bool TreeTransform<Derived>::TransformTemplateArgument(
2862 const TemplateArgumentLoc &Input,
2863 TemplateArgumentLoc &Output) {
2864 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002865 switch (Arg.getKind()) {
2866 case TemplateArgument::Null:
2867 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002868 Output = Input;
2869 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002870
Douglas Gregor670444e2009-08-04 22:27:00 +00002871 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002872 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002873 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002874 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002875
2876 DI = getDerived().TransformType(DI);
2877 if (!DI) return true;
2878
2879 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2880 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002881 }
Mike Stump1eb44332009-09-09 15:08:12 +00002882
Douglas Gregor670444e2009-08-04 22:27:00 +00002883 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002884 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002885 DeclarationName Name;
2886 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2887 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002888 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002889 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002890 if (!D) return true;
2891
John McCall828bff22009-10-29 18:45:58 +00002892 Expr *SourceExpr = Input.getSourceDeclExpression();
2893 if (SourceExpr) {
2894 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002895 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002896 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002897 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002898 }
2899
2900 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002901 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002902 }
Mike Stump1eb44332009-09-09 15:08:12 +00002903
Douglas Gregor788cd062009-11-11 01:00:40 +00002904 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002905 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2906 if (QualifierLoc) {
2907 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2908 if (!QualifierLoc)
2909 return true;
2910 }
2911
Douglas Gregor1d752d72011-03-02 18:46:51 +00002912 CXXScopeSpec SS;
2913 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002914 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002915 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2916 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002917 if (Template.isNull())
2918 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002919
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002920 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002921 Input.getTemplateNameLoc());
2922 return false;
2923 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002924
2925 case TemplateArgument::TemplateExpansion:
2926 llvm_unreachable("Caller should expand pack expansions");
2927
Douglas Gregor670444e2009-08-04 22:27:00 +00002928 case TemplateArgument::Expression: {
2929 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002930 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002931 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002932
John McCall833ca992009-10-29 08:12:44 +00002933 Expr *InputExpr = Input.getSourceExpression();
2934 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2935
Chris Lattner223de242011-04-25 20:37:58 +00002936 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall833ca992009-10-29 08:12:44 +00002937 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002938 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002939 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002940 }
Mike Stump1eb44332009-09-09 15:08:12 +00002941
Douglas Gregor670444e2009-08-04 22:27:00 +00002942 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00002943 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00002944 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002945 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002946 AEnd = Arg.pack_end();
2947 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002948
John McCall833ca992009-10-29 08:12:44 +00002949 // FIXME: preserve source information here when we start
2950 // caring about parameter packs.
2951
John McCall828bff22009-10-29 18:45:58 +00002952 TemplateArgumentLoc InputArg;
2953 TemplateArgumentLoc OutputArg;
2954 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2955 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002956 return true;
2957
John McCall828bff22009-10-29 18:45:58 +00002958 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002959 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002960
2961 TemplateArgument *TransformedArgsPtr
2962 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2963 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2964 TransformedArgsPtr);
2965 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2966 TransformedArgs.size()),
2967 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002968 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002969 }
2970 }
Mike Stump1eb44332009-09-09 15:08:12 +00002971
Douglas Gregor670444e2009-08-04 22:27:00 +00002972 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002973 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002974}
2975
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002976/// \brief Iterator adaptor that invents template argument location information
2977/// for each of the template arguments in its underlying iterator.
2978template<typename Derived, typename InputIterator>
2979class TemplateArgumentLocInventIterator {
2980 TreeTransform<Derived> &Self;
2981 InputIterator Iter;
2982
2983public:
2984 typedef TemplateArgumentLoc value_type;
2985 typedef TemplateArgumentLoc reference;
2986 typedef typename std::iterator_traits<InputIterator>::difference_type
2987 difference_type;
2988 typedef std::input_iterator_tag iterator_category;
2989
2990 class pointer {
2991 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002992
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002993 public:
2994 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2995
2996 const TemplateArgumentLoc *operator->() const { return &Arg; }
2997 };
2998
2999 TemplateArgumentLocInventIterator() { }
3000
3001 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3002 InputIterator Iter)
3003 : Self(Self), Iter(Iter) { }
3004
3005 TemplateArgumentLocInventIterator &operator++() {
3006 ++Iter;
3007 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003008 }
3009
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003010 TemplateArgumentLocInventIterator operator++(int) {
3011 TemplateArgumentLocInventIterator Old(*this);
3012 ++(*this);
3013 return Old;
3014 }
3015
3016 reference operator*() const {
3017 TemplateArgumentLoc Result;
3018 Self.InventTemplateArgumentLoc(*Iter, Result);
3019 return Result;
3020 }
3021
3022 pointer operator->() const { return pointer(**this); }
3023
3024 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3025 const TemplateArgumentLocInventIterator &Y) {
3026 return X.Iter == Y.Iter;
3027 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003028
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003029 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3030 const TemplateArgumentLocInventIterator &Y) {
3031 return X.Iter != Y.Iter;
3032 }
3033};
3034
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003035template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003036template<typename InputIterator>
3037bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3038 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003039 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003040 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003041 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003042 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003043
3044 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3045 // Unpack argument packs, which we translate them into separate
3046 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003047 // FIXME: We could do much better if we could guarantee that the
3048 // TemplateArgumentLocInfo for the pack expansion would be usable for
3049 // all of the template arguments in the argument pack.
3050 typedef TemplateArgumentLocInventIterator<Derived,
3051 TemplateArgument::pack_iterator>
3052 PackLocIterator;
3053 if (TransformTemplateArguments(PackLocIterator(*this,
3054 In.getArgument().pack_begin()),
3055 PackLocIterator(*this,
3056 In.getArgument().pack_end()),
3057 Outputs))
3058 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003059
3060 continue;
3061 }
3062
3063 if (In.getArgument().isPackExpansion()) {
3064 // We have a pack expansion, for which we will be substituting into
3065 // the pattern.
3066 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003067 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003068 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003069 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3070 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003071
Chris Lattner686775d2011-07-20 06:58:45 +00003072 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003073 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3074 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3075
3076 // Determine whether the set of unexpanded parameter packs can and should
3077 // be expanded.
3078 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003079 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003080 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003081 if (getDerived().TryExpandParameterPacks(Ellipsis,
3082 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003083 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003084 Expand,
3085 RetainExpansion,
3086 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003087 return true;
3088
3089 if (!Expand) {
3090 // The transform has determined that we should perform a simple
3091 // transformation on the pack expansion, producing another pack
3092 // expansion.
3093 TemplateArgumentLoc OutPattern;
3094 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3095 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3096 return true;
3097
Douglas Gregorcded4f62011-01-14 17:04:44 +00003098 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3099 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003100 if (Out.getArgument().isNull())
3101 return true;
3102
3103 Outputs.addArgument(Out);
3104 continue;
3105 }
3106
3107 // The transform has determined that we should perform an elementwise
3108 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003109 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003110 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3111
3112 if (getDerived().TransformTemplateArgument(Pattern, Out))
3113 return true;
3114
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003115 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003116 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3117 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003118 if (Out.getArgument().isNull())
3119 return true;
3120 }
3121
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003122 Outputs.addArgument(Out);
3123 }
3124
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003125 // If we're supposed to retain a pack expansion, do so by temporarily
3126 // forgetting the partially-substituted parameter pack.
3127 if (RetainExpansion) {
3128 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3129
3130 if (getDerived().TransformTemplateArgument(Pattern, Out))
3131 return true;
3132
Douglas Gregorcded4f62011-01-14 17:04:44 +00003133 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3134 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003135 if (Out.getArgument().isNull())
3136 return true;
3137
3138 Outputs.addArgument(Out);
3139 }
Douglas Gregord3731192011-01-10 07:32:04 +00003140
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003141 continue;
3142 }
3143
3144 // The simple case:
3145 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003146 return true;
3147
3148 Outputs.addArgument(Out);
3149 }
3150
3151 return false;
3152
3153}
3154
Douglas Gregor577f75a2009-08-04 16:50:30 +00003155//===----------------------------------------------------------------------===//
3156// Type transformation
3157//===----------------------------------------------------------------------===//
3158
3159template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003160QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003161 if (getDerived().AlreadyTransformed(T))
3162 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003163
John McCalla2becad2009-10-21 00:40:46 +00003164 // Temporary workaround. All of these transformations should
3165 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003166 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3167 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003168
John McCall43fed0d2010-11-12 08:19:04 +00003169 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003170
John McCalla2becad2009-10-21 00:40:46 +00003171 if (!NewDI)
3172 return QualType();
3173
3174 return NewDI->getType();
3175}
3176
3177template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003178TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00003179 if (getDerived().AlreadyTransformed(DI->getType()))
3180 return DI;
3181
3182 TypeLocBuilder TLB;
3183
3184 TypeLoc TL = DI->getTypeLoc();
3185 TLB.reserve(TL.getFullDataSize());
3186
John McCall43fed0d2010-11-12 08:19:04 +00003187 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003188 if (Result.isNull())
3189 return 0;
3190
John McCalla93c9342009-12-07 02:54:59 +00003191 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003192}
3193
3194template<typename Derived>
3195QualType
John McCall43fed0d2010-11-12 08:19:04 +00003196TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003197 switch (T.getTypeLocClass()) {
3198#define ABSTRACT_TYPELOC(CLASS, PARENT)
3199#define TYPELOC(CLASS, PARENT) \
3200 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003201 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003202#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003203 }
Mike Stump1eb44332009-09-09 15:08:12 +00003204
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003205 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003206 return QualType();
3207}
3208
3209/// FIXME: By default, this routine adds type qualifiers only to types
3210/// that can have qualifiers, and silently suppresses those qualifiers
3211/// that are not permitted (e.g., qualifiers on reference or function
3212/// types). This is the right thing for template instantiation, but
3213/// probably not for other clients.
3214template<typename Derived>
3215QualType
3216TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003217 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003218 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003219
John McCall43fed0d2010-11-12 08:19:04 +00003220 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003221 if (Result.isNull())
3222 return QualType();
3223
3224 // Silently suppress qualifiers if the result type can't be qualified.
3225 // FIXME: this is the right thing for template instantiation, but
3226 // probably not for other clients.
3227 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003228 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003229
John McCallf85e1932011-06-15 23:02:42 +00003230 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003231 // resulting type.
3232 if (Quals.hasObjCLifetime()) {
3233 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3234 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003235 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003236 // Objective-C ARC:
3237 // A lifetime qualifier applied to a substituted template parameter
3238 // overrides the lifetime qualifier from the template argument.
3239 if (const SubstTemplateTypeParmType *SubstTypeParam
3240 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3241 QualType Replacement = SubstTypeParam->getReplacementType();
3242 Qualifiers Qs = Replacement.getQualifiers();
3243 Qs.removeObjCLifetime();
3244 Replacement
3245 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3246 Qs);
3247 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3248 SubstTypeParam->getReplacedParameter(),
3249 Replacement);
3250 TLB.TypeWasModifiedSafely(Result);
3251 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003252 // Otherwise, complain about the addition of a qualifier to an
3253 // already-qualified type.
3254 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003255 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003256 << Result << R;
3257
Douglas Gregore559ca12011-06-17 22:11:49 +00003258 Quals.removeObjCLifetime();
3259 }
3260 }
3261 }
John McCall28654742010-06-05 06:41:15 +00003262 if (!Quals.empty()) {
3263 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3264 TLB.push<QualifiedTypeLoc>(Result);
3265 // No location information to preserve.
3266 }
John McCalla2becad2009-10-21 00:40:46 +00003267
3268 return Result;
3269}
3270
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003271template<typename Derived>
3272TypeLoc
3273TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3274 QualType ObjectType,
3275 NamedDecl *UnqualLookup,
3276 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003277 QualType T = TL.getType();
3278 if (getDerived().AlreadyTransformed(T))
3279 return TL;
3280
3281 TypeLocBuilder TLB;
3282 QualType Result;
3283
3284 if (isa<TemplateSpecializationType>(T)) {
3285 TemplateSpecializationTypeLoc SpecTL
3286 = cast<TemplateSpecializationTypeLoc>(TL);
3287
3288 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003289 getDerived().TransformTemplateName(SS,
3290 SpecTL.getTypePtr()->getTemplateName(),
3291 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003292 ObjectType, UnqualLookup);
3293 if (Template.isNull())
3294 return TypeLoc();
3295
3296 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3297 Template);
3298 } else if (isa<DependentTemplateSpecializationType>(T)) {
3299 DependentTemplateSpecializationTypeLoc SpecTL
3300 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3301
Douglas Gregora88f09f2011-02-28 17:23:35 +00003302 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003303 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003304 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003305 SpecTL.getNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003306 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003307 if (Template.isNull())
3308 return TypeLoc();
3309
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003310 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003311 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003312 Template,
3313 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003314 } else {
3315 // Nothing special needs to be done for these.
3316 Result = getDerived().TransformType(TLB, TL);
3317 }
3318
3319 if (Result.isNull())
3320 return TypeLoc();
3321
3322 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3323}
3324
Douglas Gregorb71d8212011-03-02 18:32:08 +00003325template<typename Derived>
3326TypeSourceInfo *
3327TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3328 QualType ObjectType,
3329 NamedDecl *UnqualLookup,
3330 CXXScopeSpec &SS) {
3331 // FIXME: Painfully copy-paste from the above!
3332
3333 QualType T = TSInfo->getType();
3334 if (getDerived().AlreadyTransformed(T))
3335 return TSInfo;
3336
3337 TypeLocBuilder TLB;
3338 QualType Result;
3339
3340 TypeLoc TL = TSInfo->getTypeLoc();
3341 if (isa<TemplateSpecializationType>(T)) {
3342 TemplateSpecializationTypeLoc SpecTL
3343 = cast<TemplateSpecializationTypeLoc>(TL);
3344
3345 TemplateName Template
3346 = getDerived().TransformTemplateName(SS,
3347 SpecTL.getTypePtr()->getTemplateName(),
3348 SpecTL.getTemplateNameLoc(),
3349 ObjectType, UnqualLookup);
3350 if (Template.isNull())
3351 return 0;
3352
3353 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3354 Template);
3355 } else if (isa<DependentTemplateSpecializationType>(T)) {
3356 DependentTemplateSpecializationTypeLoc SpecTL
3357 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3358
3359 TemplateName Template
3360 = getDerived().RebuildTemplateName(SS,
3361 *SpecTL.getTypePtr()->getIdentifier(),
3362 SpecTL.getNameLoc(),
3363 ObjectType, UnqualLookup);
3364 if (Template.isNull())
3365 return 0;
3366
3367 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3368 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003369 Template,
3370 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003371 } else {
3372 // Nothing special needs to be done for these.
3373 Result = getDerived().TransformType(TLB, TL);
3374 }
3375
3376 if (Result.isNull())
3377 return 0;
3378
3379 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3380}
3381
John McCalla2becad2009-10-21 00:40:46 +00003382template <class TyLoc> static inline
3383QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3384 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3385 NewT.setNameLoc(T.getNameLoc());
3386 return T.getType();
3387}
3388
John McCalla2becad2009-10-21 00:40:46 +00003389template<typename Derived>
3390QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003391 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003392 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3393 NewT.setBuiltinLoc(T.getBuiltinLoc());
3394 if (T.needsExtraLocalData())
3395 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3396 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003397}
Mike Stump1eb44332009-09-09 15:08:12 +00003398
Douglas Gregor577f75a2009-08-04 16:50:30 +00003399template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003400QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003401 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003402 // FIXME: recurse?
3403 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003404}
Mike Stump1eb44332009-09-09 15:08:12 +00003405
Douglas Gregor577f75a2009-08-04 16:50:30 +00003406template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003407QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003408 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003409 QualType PointeeType
3410 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003411 if (PointeeType.isNull())
3412 return QualType();
3413
3414 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003415 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003416 // A dependent pointer type 'T *' has is being transformed such
3417 // that an Objective-C class type is being replaced for 'T'. The
3418 // resulting pointer type is an ObjCObjectPointerType, not a
3419 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003420 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003421
John McCallc12c5bb2010-05-15 11:32:37 +00003422 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3423 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003424 return Result;
3425 }
John McCall43fed0d2010-11-12 08:19:04 +00003426
Douglas Gregor92e986e2010-04-22 16:44:27 +00003427 if (getDerived().AlwaysRebuild() ||
3428 PointeeType != TL.getPointeeLoc().getType()) {
3429 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3430 if (Result.isNull())
3431 return QualType();
3432 }
John McCallf85e1932011-06-15 23:02:42 +00003433
3434 // Objective-C ARC can add lifetime qualifiers to the type that we're
3435 // pointing to.
3436 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3437
Douglas Gregor92e986e2010-04-22 16:44:27 +00003438 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3439 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003440 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003441}
Mike Stump1eb44332009-09-09 15:08:12 +00003442
3443template<typename Derived>
3444QualType
John McCalla2becad2009-10-21 00:40:46 +00003445TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003446 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003447 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003448 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3449 if (PointeeType.isNull())
3450 return QualType();
3451
3452 QualType Result = TL.getType();
3453 if (getDerived().AlwaysRebuild() ||
3454 PointeeType != TL.getPointeeLoc().getType()) {
3455 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003456 TL.getSigilLoc());
3457 if (Result.isNull())
3458 return QualType();
3459 }
3460
Douglas Gregor39968ad2010-04-22 16:50:51 +00003461 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003462 NewT.setSigilLoc(TL.getSigilLoc());
3463 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003464}
3465
John McCall85737a72009-10-30 00:06:24 +00003466/// Transforms a reference type. Note that somewhat paradoxically we
3467/// don't care whether the type itself is an l-value type or an r-value
3468/// type; we only care if the type was *written* as an l-value type
3469/// or an r-value type.
3470template<typename Derived>
3471QualType
3472TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003473 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003474 const ReferenceType *T = TL.getTypePtr();
3475
3476 // Note that this works with the pointee-as-written.
3477 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3478 if (PointeeType.isNull())
3479 return QualType();
3480
3481 QualType Result = TL.getType();
3482 if (getDerived().AlwaysRebuild() ||
3483 PointeeType != T->getPointeeTypeAsWritten()) {
3484 Result = getDerived().RebuildReferenceType(PointeeType,
3485 T->isSpelledAsLValue(),
3486 TL.getSigilLoc());
3487 if (Result.isNull())
3488 return QualType();
3489 }
3490
John McCallf85e1932011-06-15 23:02:42 +00003491 // Objective-C ARC can add lifetime qualifiers to the type that we're
3492 // referring to.
3493 TLB.TypeWasModifiedSafely(
3494 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3495
John McCall85737a72009-10-30 00:06:24 +00003496 // r-value references can be rebuilt as l-value references.
3497 ReferenceTypeLoc NewTL;
3498 if (isa<LValueReferenceType>(Result))
3499 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3500 else
3501 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3502 NewTL.setSigilLoc(TL.getSigilLoc());
3503
3504 return Result;
3505}
3506
Mike Stump1eb44332009-09-09 15:08:12 +00003507template<typename Derived>
3508QualType
John McCalla2becad2009-10-21 00:40:46 +00003509TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003510 LValueReferenceTypeLoc TL) {
3511 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003512}
3513
Mike Stump1eb44332009-09-09 15:08:12 +00003514template<typename Derived>
3515QualType
John McCalla2becad2009-10-21 00:40:46 +00003516TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003517 RValueReferenceTypeLoc TL) {
3518 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003519}
Mike Stump1eb44332009-09-09 15:08:12 +00003520
Douglas Gregor577f75a2009-08-04 16:50:30 +00003521template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003522QualType
John McCalla2becad2009-10-21 00:40:46 +00003523TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003524 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003525 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003526 if (PointeeType.isNull())
3527 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003528
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003529 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3530 TypeSourceInfo* NewClsTInfo = 0;
3531 if (OldClsTInfo) {
3532 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3533 if (!NewClsTInfo)
3534 return QualType();
3535 }
3536
3537 const MemberPointerType *T = TL.getTypePtr();
3538 QualType OldClsType = QualType(T->getClass(), 0);
3539 QualType NewClsType;
3540 if (NewClsTInfo)
3541 NewClsType = NewClsTInfo->getType();
3542 else {
3543 NewClsType = getDerived().TransformType(OldClsType);
3544 if (NewClsType.isNull())
3545 return QualType();
3546 }
Mike Stump1eb44332009-09-09 15:08:12 +00003547
John McCalla2becad2009-10-21 00:40:46 +00003548 QualType Result = TL.getType();
3549 if (getDerived().AlwaysRebuild() ||
3550 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003551 NewClsType != OldClsType) {
3552 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003553 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003554 if (Result.isNull())
3555 return QualType();
3556 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003557
John McCalla2becad2009-10-21 00:40:46 +00003558 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3559 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003560 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003561
3562 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003563}
3564
Mike Stump1eb44332009-09-09 15:08:12 +00003565template<typename Derived>
3566QualType
John McCalla2becad2009-10-21 00:40:46 +00003567TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003568 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003569 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003570 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003571 if (ElementType.isNull())
3572 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003573
John McCalla2becad2009-10-21 00:40:46 +00003574 QualType Result = TL.getType();
3575 if (getDerived().AlwaysRebuild() ||
3576 ElementType != T->getElementType()) {
3577 Result = getDerived().RebuildConstantArrayType(ElementType,
3578 T->getSizeModifier(),
3579 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003580 T->getIndexTypeCVRQualifiers(),
3581 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003582 if (Result.isNull())
3583 return QualType();
3584 }
Sean Huntc3021132010-05-05 15:23:54 +00003585
John McCalla2becad2009-10-21 00:40:46 +00003586 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3587 NewTL.setLBracketLoc(TL.getLBracketLoc());
3588 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003589
John McCalla2becad2009-10-21 00:40:46 +00003590 Expr *Size = TL.getSizeExpr();
3591 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003592 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003593 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3594 }
3595 NewTL.setSizeExpr(Size);
3596
3597 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003598}
Mike Stump1eb44332009-09-09 15:08:12 +00003599
Douglas Gregor577f75a2009-08-04 16:50:30 +00003600template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003601QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003602 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003603 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003604 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003605 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003606 if (ElementType.isNull())
3607 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003608
John McCalla2becad2009-10-21 00:40:46 +00003609 QualType Result = TL.getType();
3610 if (getDerived().AlwaysRebuild() ||
3611 ElementType != T->getElementType()) {
3612 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003613 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003614 T->getIndexTypeCVRQualifiers(),
3615 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003616 if (Result.isNull())
3617 return QualType();
3618 }
Sean Huntc3021132010-05-05 15:23:54 +00003619
John McCalla2becad2009-10-21 00:40:46 +00003620 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3621 NewTL.setLBracketLoc(TL.getLBracketLoc());
3622 NewTL.setRBracketLoc(TL.getRBracketLoc());
3623 NewTL.setSizeExpr(0);
3624
3625 return Result;
3626}
3627
3628template<typename Derived>
3629QualType
3630TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003631 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003632 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003633 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3634 if (ElementType.isNull())
3635 return QualType();
3636
3637 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003638 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003639
John McCall60d7b3a2010-08-24 06:29:42 +00003640 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003641 = getDerived().TransformExpr(T->getSizeExpr());
3642 if (SizeResult.isInvalid())
3643 return QualType();
3644
John McCall9ae2f072010-08-23 23:25:46 +00003645 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003646
3647 QualType Result = TL.getType();
3648 if (getDerived().AlwaysRebuild() ||
3649 ElementType != T->getElementType() ||
3650 Size != T->getSizeExpr()) {
3651 Result = getDerived().RebuildVariableArrayType(ElementType,
3652 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003653 Size,
John McCalla2becad2009-10-21 00:40:46 +00003654 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003655 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003656 if (Result.isNull())
3657 return QualType();
3658 }
Sean Huntc3021132010-05-05 15:23:54 +00003659
John McCalla2becad2009-10-21 00:40:46 +00003660 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3661 NewTL.setLBracketLoc(TL.getLBracketLoc());
3662 NewTL.setRBracketLoc(TL.getRBracketLoc());
3663 NewTL.setSizeExpr(Size);
3664
3665 return Result;
3666}
3667
3668template<typename Derived>
3669QualType
3670TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003671 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003672 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003673 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3674 if (ElementType.isNull())
3675 return QualType();
3676
3677 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003678 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003679
John McCall3b657512011-01-19 10:06:00 +00003680 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3681 Expr *origSize = TL.getSizeExpr();
3682 if (!origSize) origSize = T->getSizeExpr();
3683
3684 ExprResult sizeResult
3685 = getDerived().TransformExpr(origSize);
3686 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003687 return QualType();
3688
John McCall3b657512011-01-19 10:06:00 +00003689 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003690
3691 QualType Result = TL.getType();
3692 if (getDerived().AlwaysRebuild() ||
3693 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003694 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003695 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3696 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003697 size,
John McCalla2becad2009-10-21 00:40:46 +00003698 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003699 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003700 if (Result.isNull())
3701 return QualType();
3702 }
John McCalla2becad2009-10-21 00:40:46 +00003703
3704 // We might have any sort of array type now, but fortunately they
3705 // all have the same location layout.
3706 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3707 NewTL.setLBracketLoc(TL.getLBracketLoc());
3708 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003709 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003710
3711 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003712}
Mike Stump1eb44332009-09-09 15:08:12 +00003713
3714template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003715QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003716 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003717 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003718 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003719
3720 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003721 QualType ElementType = getDerived().TransformType(T->getElementType());
3722 if (ElementType.isNull())
3723 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003724
Douglas Gregor670444e2009-08-04 22:27:00 +00003725 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003726 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003727
John McCall60d7b3a2010-08-24 06:29:42 +00003728 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003729 if (Size.isInvalid())
3730 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003731
John McCalla2becad2009-10-21 00:40:46 +00003732 QualType Result = TL.getType();
3733 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003734 ElementType != T->getElementType() ||
3735 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003736 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003737 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003738 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003739 if (Result.isNull())
3740 return QualType();
3741 }
John McCalla2becad2009-10-21 00:40:46 +00003742
3743 // Result might be dependent or not.
3744 if (isa<DependentSizedExtVectorType>(Result)) {
3745 DependentSizedExtVectorTypeLoc NewTL
3746 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3747 NewTL.setNameLoc(TL.getNameLoc());
3748 } else {
3749 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3750 NewTL.setNameLoc(TL.getNameLoc());
3751 }
3752
3753 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003754}
Mike Stump1eb44332009-09-09 15:08:12 +00003755
3756template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003757QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003758 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003759 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003760 QualType ElementType = getDerived().TransformType(T->getElementType());
3761 if (ElementType.isNull())
3762 return QualType();
3763
John McCalla2becad2009-10-21 00:40:46 +00003764 QualType Result = TL.getType();
3765 if (getDerived().AlwaysRebuild() ||
3766 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003767 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003768 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003769 if (Result.isNull())
3770 return QualType();
3771 }
Sean Huntc3021132010-05-05 15:23:54 +00003772
John McCalla2becad2009-10-21 00:40:46 +00003773 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3774 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003775
John McCalla2becad2009-10-21 00:40:46 +00003776 return Result;
3777}
3778
3779template<typename Derived>
3780QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003781 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003782 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003783 QualType ElementType = getDerived().TransformType(T->getElementType());
3784 if (ElementType.isNull())
3785 return QualType();
3786
3787 QualType Result = TL.getType();
3788 if (getDerived().AlwaysRebuild() ||
3789 ElementType != T->getElementType()) {
3790 Result = getDerived().RebuildExtVectorType(ElementType,
3791 T->getNumElements(),
3792 /*FIXME*/ SourceLocation());
3793 if (Result.isNull())
3794 return QualType();
3795 }
Sean Huntc3021132010-05-05 15:23:54 +00003796
John McCalla2becad2009-10-21 00:40:46 +00003797 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3798 NewTL.setNameLoc(TL.getNameLoc());
3799
3800 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003801}
Mike Stump1eb44332009-09-09 15:08:12 +00003802
3803template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003804ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003805TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003806 int indexAdjustment,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003807 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003808 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003809 TypeSourceInfo *NewDI = 0;
3810
3811 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3812 // If we're substituting into a pack expansion type and we know the
3813 TypeLoc OldTL = OldDI->getTypeLoc();
3814 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3815
3816 TypeLocBuilder TLB;
3817 TypeLoc NewTL = OldDI->getTypeLoc();
3818 TLB.reserve(NewTL.getFullDataSize());
3819
3820 QualType Result = getDerived().TransformType(TLB,
3821 OldExpansionTL.getPatternLoc());
3822 if (Result.isNull())
3823 return 0;
3824
3825 Result = RebuildPackExpansionType(Result,
3826 OldExpansionTL.getPatternLoc().getSourceRange(),
3827 OldExpansionTL.getEllipsisLoc(),
3828 NumExpansions);
3829 if (Result.isNull())
3830 return 0;
3831
3832 PackExpansionTypeLoc NewExpansionTL
3833 = TLB.push<PackExpansionTypeLoc>(Result);
3834 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3835 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3836 } else
3837 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003838 if (!NewDI)
3839 return 0;
3840
John McCallfb44de92011-05-01 22:35:37 +00003841 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003842 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003843
3844 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3845 OldParm->getDeclContext(),
3846 OldParm->getInnerLocStart(),
3847 OldParm->getLocation(),
3848 OldParm->getIdentifier(),
3849 NewDI->getType(),
3850 NewDI,
3851 OldParm->getStorageClass(),
3852 OldParm->getStorageClassAsWritten(),
3853 /* DefArg */ NULL);
3854 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3855 OldParm->getFunctionScopeIndex() + indexAdjustment);
3856 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003857}
3858
3859template<typename Derived>
3860bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003861 TransformFunctionTypeParams(SourceLocation Loc,
3862 ParmVarDecl **Params, unsigned NumParams,
3863 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003864 SmallVectorImpl<QualType> &OutParamTypes,
3865 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003866 int indexAdjustment = 0;
3867
Douglas Gregora009b592011-01-07 00:20:55 +00003868 for (unsigned i = 0; i != NumParams; ++i) {
3869 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003870 assert(OldParm->getFunctionScopeIndex() == i);
3871
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003872 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003873 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003874 if (OldParm->isParameterPack()) {
3875 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003876 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003877
Douglas Gregor603cfb42011-01-05 23:12:31 +00003878 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003879 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3880 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3881 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3882 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003883 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3884
Douglas Gregor603cfb42011-01-05 23:12:31 +00003885 // Determine whether we should expand the parameter packs.
3886 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003887 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003888 llvm::Optional<unsigned> OrigNumExpansions
3889 = ExpansionTL.getTypePtr()->getNumExpansions();
3890 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003891 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3892 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003893 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003894 ShouldExpand,
3895 RetainExpansion,
3896 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003897 return true;
3898 }
3899
3900 if (ShouldExpand) {
3901 // Expand the function parameter pack into multiple, separate
3902 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003903 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003904 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003905 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3906 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003907 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003908 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003909 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003910 if (!NewParm)
3911 return true;
3912
Douglas Gregora009b592011-01-07 00:20:55 +00003913 OutParamTypes.push_back(NewParm->getType());
3914 if (PVars)
3915 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003916 }
Douglas Gregord3731192011-01-10 07:32:04 +00003917
3918 // If we're supposed to retain a pack expansion, do so by temporarily
3919 // forgetting the partially-substituted parameter pack.
3920 if (RetainExpansion) {
3921 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3922 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003923 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003924 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003925 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003926 if (!NewParm)
3927 return true;
3928
3929 OutParamTypes.push_back(NewParm->getType());
3930 if (PVars)
3931 PVars->push_back(NewParm);
3932 }
3933
John McCallfb44de92011-05-01 22:35:37 +00003934 // The next parameter should have the same adjustment as the
3935 // last thing we pushed, but we post-incremented indexAdjustment
3936 // on every push. Also, if we push nothing, the adjustment should
3937 // go down by one.
3938 indexAdjustment--;
3939
Douglas Gregor603cfb42011-01-05 23:12:31 +00003940 // We're done with the pack expansion.
3941 continue;
3942 }
3943
3944 // We'll substitute the parameter now without expanding the pack
3945 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003946 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3947 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003948 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003949 NumExpansions);
3950 } else {
3951 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003952 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003953 llvm::Optional<unsigned>());
Douglas Gregor603cfb42011-01-05 23:12:31 +00003954 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003955
John McCall21ef0fa2010-03-11 09:03:00 +00003956 if (!NewParm)
3957 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003958
Douglas Gregora009b592011-01-07 00:20:55 +00003959 OutParamTypes.push_back(NewParm->getType());
3960 if (PVars)
3961 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003962 continue;
3963 }
John McCall21ef0fa2010-03-11 09:03:00 +00003964
3965 // Deal with the possibility that we don't have a parameter
3966 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003967 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003968 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003969 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003970 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003971 if (const PackExpansionType *Expansion
3972 = dyn_cast<PackExpansionType>(OldType)) {
3973 // We have a function parameter pack that may need to be expanded.
3974 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00003975 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003976 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3977
3978 // Determine whether we should expand the parameter packs.
3979 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003980 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003981 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003982 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003983 ShouldExpand,
3984 RetainExpansion,
3985 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003986 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003987 }
3988
3989 if (ShouldExpand) {
3990 // Expand the function parameter pack into multiple, separate
3991 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003992 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003993 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3994 QualType NewType = getDerived().TransformType(Pattern);
3995 if (NewType.isNull())
3996 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003997
Douglas Gregora009b592011-01-07 00:20:55 +00003998 OutParamTypes.push_back(NewType);
3999 if (PVars)
4000 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004001 }
4002
4003 // We're done with the pack expansion.
4004 continue;
4005 }
4006
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004007 // If we're supposed to retain a pack expansion, do so by temporarily
4008 // forgetting the partially-substituted parameter pack.
4009 if (RetainExpansion) {
4010 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4011 QualType NewType = getDerived().TransformType(Pattern);
4012 if (NewType.isNull())
4013 return true;
4014
4015 OutParamTypes.push_back(NewType);
4016 if (PVars)
4017 PVars->push_back(0);
4018 }
Douglas Gregord3731192011-01-10 07:32:04 +00004019
Douglas Gregor603cfb42011-01-05 23:12:31 +00004020 // We'll substitute the parameter now without expanding the pack
4021 // expansion.
4022 OldType = Expansion->getPattern();
4023 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004024 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4025 NewType = getDerived().TransformType(OldType);
4026 } else {
4027 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004028 }
4029
Douglas Gregor603cfb42011-01-05 23:12:31 +00004030 if (NewType.isNull())
4031 return true;
4032
4033 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004034 NewType = getSema().Context.getPackExpansionType(NewType,
4035 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004036
Douglas Gregora009b592011-01-07 00:20:55 +00004037 OutParamTypes.push_back(NewType);
4038 if (PVars)
4039 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004040 }
4041
John McCallfb44de92011-05-01 22:35:37 +00004042#ifndef NDEBUG
4043 if (PVars) {
4044 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4045 if (ParmVarDecl *parm = (*PVars)[i])
4046 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004047 }
John McCallfb44de92011-05-01 22:35:37 +00004048#endif
4049
4050 return false;
4051}
John McCall21ef0fa2010-03-11 09:03:00 +00004052
4053template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004054QualType
John McCalla2becad2009-10-21 00:40:46 +00004055TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004056 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004057 // Transform the parameters and return type.
4058 //
4059 // We instantiate in source order, with the return type first followed by
4060 // the parameters, because users tend to expect this (even if they shouldn't
4061 // rely on it!).
4062 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004063 // When the function has a trailing return type, we instantiate the
4064 // parameters before the return type, since the return type can then refer
4065 // to the parameters themselves (via decltype, sizeof, etc.).
4066 //
Chris Lattner686775d2011-07-20 06:58:45 +00004067 SmallVector<QualType, 4> ParamTypes;
4068 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004069 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004070
Douglas Gregordab60ad2010-10-01 18:44:50 +00004071 QualType ResultType;
4072
4073 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004074 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4075 TL.getParmArray(),
4076 TL.getNumArgs(),
4077 TL.getTypePtr()->arg_type_begin(),
4078 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004079 return QualType();
4080
4081 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4082 if (ResultType.isNull())
4083 return QualType();
4084 }
4085 else {
4086 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4087 if (ResultType.isNull())
4088 return QualType();
4089
Douglas Gregora009b592011-01-07 00:20:55 +00004090 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4091 TL.getParmArray(),
4092 TL.getNumArgs(),
4093 TL.getTypePtr()->arg_type_begin(),
4094 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004095 return QualType();
4096 }
4097
John McCalla2becad2009-10-21 00:40:46 +00004098 QualType Result = TL.getType();
4099 if (getDerived().AlwaysRebuild() ||
4100 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004101 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004102 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4103 Result = getDerived().RebuildFunctionProtoType(ResultType,
4104 ParamTypes.data(),
4105 ParamTypes.size(),
4106 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004107 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004108 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004109 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004110 if (Result.isNull())
4111 return QualType();
4112 }
Mike Stump1eb44332009-09-09 15:08:12 +00004113
John McCalla2becad2009-10-21 00:40:46 +00004114 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004115 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4116 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004117 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004118 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4119 NewTL.setArg(i, ParamDecls[i]);
4120
4121 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004122}
Mike Stump1eb44332009-09-09 15:08:12 +00004123
Douglas Gregor577f75a2009-08-04 16:50:30 +00004124template<typename Derived>
4125QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004126 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004127 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004128 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004129 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4130 if (ResultType.isNull())
4131 return QualType();
4132
4133 QualType Result = TL.getType();
4134 if (getDerived().AlwaysRebuild() ||
4135 ResultType != T->getResultType())
4136 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4137
4138 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004139 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4140 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004141 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004142
4143 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004144}
Mike Stump1eb44332009-09-09 15:08:12 +00004145
John McCalled976492009-12-04 22:46:56 +00004146template<typename Derived> QualType
4147TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004148 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004149 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004150 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004151 if (!D)
4152 return QualType();
4153
4154 QualType Result = TL.getType();
4155 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4156 Result = getDerived().RebuildUnresolvedUsingType(D);
4157 if (Result.isNull())
4158 return QualType();
4159 }
4160
4161 // We might get an arbitrary type spec type back. We should at
4162 // least always get a type spec type, though.
4163 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4164 NewTL.setNameLoc(TL.getNameLoc());
4165
4166 return Result;
4167}
4168
Douglas Gregor577f75a2009-08-04 16:50:30 +00004169template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004170QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004171 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004172 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004173 TypedefNameDecl *Typedef
4174 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4175 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004176 if (!Typedef)
4177 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004178
John McCalla2becad2009-10-21 00:40:46 +00004179 QualType Result = TL.getType();
4180 if (getDerived().AlwaysRebuild() ||
4181 Typedef != T->getDecl()) {
4182 Result = getDerived().RebuildTypedefType(Typedef);
4183 if (Result.isNull())
4184 return QualType();
4185 }
Mike Stump1eb44332009-09-09 15:08:12 +00004186
John McCalla2becad2009-10-21 00:40:46 +00004187 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4188 NewTL.setNameLoc(TL.getNameLoc());
4189
4190 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004191}
Mike Stump1eb44332009-09-09 15:08:12 +00004192
Douglas Gregor577f75a2009-08-04 16:50:30 +00004193template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004194QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004195 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004196 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004197 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004198
John McCall60d7b3a2010-08-24 06:29:42 +00004199 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004200 if (E.isInvalid())
4201 return QualType();
4202
John McCalla2becad2009-10-21 00:40:46 +00004203 QualType Result = TL.getType();
4204 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004205 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004206 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004207 if (Result.isNull())
4208 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004209 }
John McCalla2becad2009-10-21 00:40:46 +00004210 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004211
John McCalla2becad2009-10-21 00:40:46 +00004212 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004213 NewTL.setTypeofLoc(TL.getTypeofLoc());
4214 NewTL.setLParenLoc(TL.getLParenLoc());
4215 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004216
4217 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004218}
Mike Stump1eb44332009-09-09 15:08:12 +00004219
4220template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004221QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004222 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004223 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4224 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4225 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004226 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004227
John McCalla2becad2009-10-21 00:40:46 +00004228 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004229 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4230 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004231 if (Result.isNull())
4232 return QualType();
4233 }
Mike Stump1eb44332009-09-09 15:08:12 +00004234
John McCalla2becad2009-10-21 00:40:46 +00004235 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004236 NewTL.setTypeofLoc(TL.getTypeofLoc());
4237 NewTL.setLParenLoc(TL.getLParenLoc());
4238 NewTL.setRParenLoc(TL.getRParenLoc());
4239 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004240
4241 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004242}
Mike Stump1eb44332009-09-09 15:08:12 +00004243
4244template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004245QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004246 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004247 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004248
Douglas Gregor670444e2009-08-04 22:27:00 +00004249 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004250 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004251
John McCall60d7b3a2010-08-24 06:29:42 +00004252 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004253 if (E.isInvalid())
4254 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004255
John McCalla2becad2009-10-21 00:40:46 +00004256 QualType Result = TL.getType();
4257 if (getDerived().AlwaysRebuild() ||
4258 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004259 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004260 if (Result.isNull())
4261 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004262 }
John McCalla2becad2009-10-21 00:40:46 +00004263 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004264
John McCalla2becad2009-10-21 00:40:46 +00004265 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4266 NewTL.setNameLoc(TL.getNameLoc());
4267
4268 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004269}
4270
4271template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004272QualType TreeTransform<Derived>::TransformUnaryTransformType(
4273 TypeLocBuilder &TLB,
4274 UnaryTransformTypeLoc TL) {
4275 QualType Result = TL.getType();
4276 if (Result->isDependentType()) {
4277 const UnaryTransformType *T = TL.getTypePtr();
4278 QualType NewBase =
4279 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4280 Result = getDerived().RebuildUnaryTransformType(NewBase,
4281 T->getUTTKind(),
4282 TL.getKWLoc());
4283 if (Result.isNull())
4284 return QualType();
4285 }
4286
4287 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4288 NewTL.setKWLoc(TL.getKWLoc());
4289 NewTL.setParensRange(TL.getParensRange());
4290 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4291 return Result;
4292}
4293
4294template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004295QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4296 AutoTypeLoc TL) {
4297 const AutoType *T = TL.getTypePtr();
4298 QualType OldDeduced = T->getDeducedType();
4299 QualType NewDeduced;
4300 if (!OldDeduced.isNull()) {
4301 NewDeduced = getDerived().TransformType(OldDeduced);
4302 if (NewDeduced.isNull())
4303 return QualType();
4304 }
4305
4306 QualType Result = TL.getType();
4307 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4308 Result = getDerived().RebuildAutoType(NewDeduced);
4309 if (Result.isNull())
4310 return QualType();
4311 }
4312
4313 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4314 NewTL.setNameLoc(TL.getNameLoc());
4315
4316 return Result;
4317}
4318
4319template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004320QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004321 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004322 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004323 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004324 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4325 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004326 if (!Record)
4327 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004328
John McCalla2becad2009-10-21 00:40:46 +00004329 QualType Result = TL.getType();
4330 if (getDerived().AlwaysRebuild() ||
4331 Record != T->getDecl()) {
4332 Result = getDerived().RebuildRecordType(Record);
4333 if (Result.isNull())
4334 return QualType();
4335 }
Mike Stump1eb44332009-09-09 15:08:12 +00004336
John McCalla2becad2009-10-21 00:40:46 +00004337 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4338 NewTL.setNameLoc(TL.getNameLoc());
4339
4340 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004341}
Mike Stump1eb44332009-09-09 15:08:12 +00004342
4343template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004344QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004345 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004346 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004347 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004348 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4349 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004350 if (!Enum)
4351 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004352
John McCalla2becad2009-10-21 00:40:46 +00004353 QualType Result = TL.getType();
4354 if (getDerived().AlwaysRebuild() ||
4355 Enum != T->getDecl()) {
4356 Result = getDerived().RebuildEnumType(Enum);
4357 if (Result.isNull())
4358 return QualType();
4359 }
Mike Stump1eb44332009-09-09 15:08:12 +00004360
John McCalla2becad2009-10-21 00:40:46 +00004361 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4362 NewTL.setNameLoc(TL.getNameLoc());
4363
4364 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004365}
John McCall7da24312009-09-05 00:15:47 +00004366
John McCall3cb0ebd2010-03-10 03:28:59 +00004367template<typename Derived>
4368QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4369 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004370 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004371 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4372 TL.getTypePtr()->getDecl());
4373 if (!D) return QualType();
4374
4375 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4376 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4377 return T;
4378}
4379
Douglas Gregor577f75a2009-08-04 16:50:30 +00004380template<typename Derived>
4381QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004382 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004383 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004384 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004385}
4386
Mike Stump1eb44332009-09-09 15:08:12 +00004387template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004388QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004389 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004390 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004391 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4392
4393 // Substitute into the replacement type, which itself might involve something
4394 // that needs to be transformed. This only tends to occur with default
4395 // template arguments of template template parameters.
4396 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4397 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4398 if (Replacement.isNull())
4399 return QualType();
4400
4401 // Always canonicalize the replacement type.
4402 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4403 QualType Result
4404 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4405 Replacement);
4406
4407 // Propagate type-source information.
4408 SubstTemplateTypeParmTypeLoc NewTL
4409 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4410 NewTL.setNameLoc(TL.getNameLoc());
4411 return Result;
4412
John McCall49a832b2009-10-18 09:09:24 +00004413}
4414
4415template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004416QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4417 TypeLocBuilder &TLB,
4418 SubstTemplateTypeParmPackTypeLoc TL) {
4419 return TransformTypeSpecType(TLB, TL);
4420}
4421
4422template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004423QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004424 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004425 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004426 const TemplateSpecializationType *T = TL.getTypePtr();
4427
Douglas Gregor1d752d72011-03-02 18:46:51 +00004428 // The nested-name-specifier never matters in a TemplateSpecializationType,
4429 // because we can't have a dependent nested-name-specifier anyway.
4430 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004431 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004432 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4433 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004434 if (Template.isNull())
4435 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004436
John McCall43fed0d2010-11-12 08:19:04 +00004437 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4438}
4439
Eli Friedmanb001de72011-10-06 23:00:33 +00004440template<typename Derived>
4441QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4442 AtomicTypeLoc TL) {
4443 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4444 if (ValueType.isNull())
4445 return QualType();
4446
4447 QualType Result = TL.getType();
4448 if (getDerived().AlwaysRebuild() ||
4449 ValueType != TL.getValueLoc().getType()) {
4450 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4451 if (Result.isNull())
4452 return QualType();
4453 }
4454
4455 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4456 NewTL.setKWLoc(TL.getKWLoc());
4457 NewTL.setLParenLoc(TL.getLParenLoc());
4458 NewTL.setRParenLoc(TL.getRParenLoc());
4459
4460 return Result;
4461}
4462
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004463namespace {
4464 /// \brief Simple iterator that traverses the template arguments in a
4465 /// container that provides a \c getArgLoc() member function.
4466 ///
4467 /// This iterator is intended to be used with the iterator form of
4468 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4469 template<typename ArgLocContainer>
4470 class TemplateArgumentLocContainerIterator {
4471 ArgLocContainer *Container;
4472 unsigned Index;
4473
4474 public:
4475 typedef TemplateArgumentLoc value_type;
4476 typedef TemplateArgumentLoc reference;
4477 typedef int difference_type;
4478 typedef std::input_iterator_tag iterator_category;
4479
4480 class pointer {
4481 TemplateArgumentLoc Arg;
4482
4483 public:
4484 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4485
4486 const TemplateArgumentLoc *operator->() const {
4487 return &Arg;
4488 }
4489 };
4490
4491
4492 TemplateArgumentLocContainerIterator() {}
4493
4494 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4495 unsigned Index)
4496 : Container(&Container), Index(Index) { }
4497
4498 TemplateArgumentLocContainerIterator &operator++() {
4499 ++Index;
4500 return *this;
4501 }
4502
4503 TemplateArgumentLocContainerIterator operator++(int) {
4504 TemplateArgumentLocContainerIterator Old(*this);
4505 ++(*this);
4506 return Old;
4507 }
4508
4509 TemplateArgumentLoc operator*() const {
4510 return Container->getArgLoc(Index);
4511 }
4512
4513 pointer operator->() const {
4514 return pointer(Container->getArgLoc(Index));
4515 }
4516
4517 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004518 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004519 return X.Container == Y.Container && X.Index == Y.Index;
4520 }
4521
4522 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004523 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004524 return !(X == Y);
4525 }
4526 };
4527}
4528
4529
John McCall43fed0d2010-11-12 08:19:04 +00004530template <typename Derived>
4531QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4532 TypeLocBuilder &TLB,
4533 TemplateSpecializationTypeLoc TL,
4534 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004535 TemplateArgumentListInfo NewTemplateArgs;
4536 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4537 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004538 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4539 ArgIterator;
4540 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4541 ArgIterator(TL, TL.getNumArgs()),
4542 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004543 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004544
John McCall833ca992009-10-29 08:12:44 +00004545 // FIXME: maybe don't rebuild if all the template arguments are the same.
4546
4547 QualType Result =
4548 getDerived().RebuildTemplateSpecializationType(Template,
4549 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004550 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004551
4552 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004553 // Specializations of template template parameters are represented as
4554 // TemplateSpecializationTypes, and substitution of type alias templates
4555 // within a dependent context can transform them into
4556 // DependentTemplateSpecializationTypes.
4557 if (isa<DependentTemplateSpecializationType>(Result)) {
4558 DependentTemplateSpecializationTypeLoc NewTL
4559 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4560 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4561 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4562 NewTL.setNameLoc(TL.getTemplateNameLoc());
4563 NewTL.setLAngleLoc(TL.getLAngleLoc());
4564 NewTL.setRAngleLoc(TL.getRAngleLoc());
4565 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4566 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4567 return Result;
4568 }
4569
John McCall833ca992009-10-29 08:12:44 +00004570 TemplateSpecializationTypeLoc NewTL
4571 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4572 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4573 NewTL.setLAngleLoc(TL.getLAngleLoc());
4574 NewTL.setRAngleLoc(TL.getRAngleLoc());
4575 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4576 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004577 }
Mike Stump1eb44332009-09-09 15:08:12 +00004578
John McCall833ca992009-10-29 08:12:44 +00004579 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004580}
Mike Stump1eb44332009-09-09 15:08:12 +00004581
Douglas Gregora88f09f2011-02-28 17:23:35 +00004582template <typename Derived>
4583QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4584 TypeLocBuilder &TLB,
4585 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004586 TemplateName Template,
4587 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004588 TemplateArgumentListInfo NewTemplateArgs;
4589 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4590 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4591 typedef TemplateArgumentLocContainerIterator<
4592 DependentTemplateSpecializationTypeLoc> ArgIterator;
4593 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4594 ArgIterator(TL, TL.getNumArgs()),
4595 NewTemplateArgs))
4596 return QualType();
4597
4598 // FIXME: maybe don't rebuild if all the template arguments are the same.
4599
4600 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4601 QualType Result
4602 = getSema().Context.getDependentTemplateSpecializationType(
4603 TL.getTypePtr()->getKeyword(),
4604 DTN->getQualifier(),
4605 DTN->getIdentifier(),
4606 NewTemplateArgs);
4607
4608 DependentTemplateSpecializationTypeLoc NewTL
4609 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4610 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004611
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004612 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregora88f09f2011-02-28 17:23:35 +00004613 NewTL.setNameLoc(TL.getNameLoc());
4614 NewTL.setLAngleLoc(TL.getLAngleLoc());
4615 NewTL.setRAngleLoc(TL.getRAngleLoc());
4616 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4617 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4618 return Result;
4619 }
4620
4621 QualType Result
4622 = getDerived().RebuildTemplateSpecializationType(Template,
4623 TL.getNameLoc(),
4624 NewTemplateArgs);
4625
4626 if (!Result.isNull()) {
4627 /// FIXME: Wrap this in an elaborated-type-specifier?
4628 TemplateSpecializationTypeLoc NewTL
4629 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4630 NewTL.setTemplateNameLoc(TL.getNameLoc());
4631 NewTL.setLAngleLoc(TL.getLAngleLoc());
4632 NewTL.setRAngleLoc(TL.getRAngleLoc());
4633 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4634 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4635 }
4636
4637 return Result;
4638}
4639
Mike Stump1eb44332009-09-09 15:08:12 +00004640template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004641QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004642TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004643 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004644 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004645
Douglas Gregor9e876872011-03-01 18:12:44 +00004646 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004647 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004648 if (TL.getQualifierLoc()) {
4649 QualifierLoc
4650 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4651 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004652 return QualType();
4653 }
Mike Stump1eb44332009-09-09 15:08:12 +00004654
John McCall43fed0d2010-11-12 08:19:04 +00004655 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4656 if (NamedT.isNull())
4657 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004658
Richard Smith3e4c6c42011-05-05 21:57:07 +00004659 // C++0x [dcl.type.elab]p2:
4660 // If the identifier resolves to a typedef-name or the simple-template-id
4661 // resolves to an alias template specialization, the
4662 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004663 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4664 if (const TemplateSpecializationType *TST =
4665 NamedT->getAs<TemplateSpecializationType>()) {
4666 TemplateName Template = TST->getTemplateName();
4667 if (TypeAliasTemplateDecl *TAT =
4668 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4669 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4670 diag::err_tag_reference_non_tag) << 4;
4671 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4672 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004673 }
4674 }
4675
John McCalla2becad2009-10-21 00:40:46 +00004676 QualType Result = TL.getType();
4677 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004678 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004679 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004680 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004681 T->getKeyword(),
4682 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004683 if (Result.isNull())
4684 return QualType();
4685 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004686
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004687 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004688 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004689 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004690 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004691}
Mike Stump1eb44332009-09-09 15:08:12 +00004692
4693template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004694QualType TreeTransform<Derived>::TransformAttributedType(
4695 TypeLocBuilder &TLB,
4696 AttributedTypeLoc TL) {
4697 const AttributedType *oldType = TL.getTypePtr();
4698 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4699 if (modifiedType.isNull())
4700 return QualType();
4701
4702 QualType result = TL.getType();
4703
4704 // FIXME: dependent operand expressions?
4705 if (getDerived().AlwaysRebuild() ||
4706 modifiedType != oldType->getModifiedType()) {
4707 // TODO: this is really lame; we should really be rebuilding the
4708 // equivalent type from first principles.
4709 QualType equivalentType
4710 = getDerived().TransformType(oldType->getEquivalentType());
4711 if (equivalentType.isNull())
4712 return QualType();
4713 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4714 modifiedType,
4715 equivalentType);
4716 }
4717
4718 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4719 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4720 if (TL.hasAttrOperand())
4721 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4722 if (TL.hasAttrExprOperand())
4723 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4724 else if (TL.hasAttrEnumOperand())
4725 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4726
4727 return result;
4728}
4729
4730template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004731QualType
4732TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4733 ParenTypeLoc TL) {
4734 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4735 if (Inner.isNull())
4736 return QualType();
4737
4738 QualType Result = TL.getType();
4739 if (getDerived().AlwaysRebuild() ||
4740 Inner != TL.getInnerLoc().getType()) {
4741 Result = getDerived().RebuildParenType(Inner);
4742 if (Result.isNull())
4743 return QualType();
4744 }
4745
4746 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4747 NewTL.setLParenLoc(TL.getLParenLoc());
4748 NewTL.setRParenLoc(TL.getRParenLoc());
4749 return Result;
4750}
4751
4752template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004753QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004754 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004755 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004756
Douglas Gregor2494dd02011-03-01 01:34:45 +00004757 NestedNameSpecifierLoc QualifierLoc
4758 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4759 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004760 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004761
John McCall33500952010-06-11 00:33:02 +00004762 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004763 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCall33500952010-06-11 00:33:02 +00004764 TL.getKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004765 QualifierLoc,
4766 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004767 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004768 if (Result.isNull())
4769 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004770
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004771 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4772 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004773 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4774
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004775 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4776 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004777 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004778 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004779 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4780 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004781 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004782 NewTL.setNameLoc(TL.getNameLoc());
4783 }
John McCalla2becad2009-10-21 00:40:46 +00004784 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004785}
Mike Stump1eb44332009-09-09 15:08:12 +00004786
Douglas Gregor577f75a2009-08-04 16:50:30 +00004787template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004788QualType TreeTransform<Derived>::
4789 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004790 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004791 NestedNameSpecifierLoc QualifierLoc;
4792 if (TL.getQualifierLoc()) {
4793 QualifierLoc
4794 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4795 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004796 return QualType();
4797 }
4798
John McCall43fed0d2010-11-12 08:19:04 +00004799 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004800 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004801}
4802
4803template<typename Derived>
4804QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004805TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4806 DependentTemplateSpecializationTypeLoc TL,
4807 NestedNameSpecifierLoc QualifierLoc) {
4808 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4809
4810 TemplateArgumentListInfo NewTemplateArgs;
4811 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4812 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4813
4814 typedef TemplateArgumentLocContainerIterator<
4815 DependentTemplateSpecializationTypeLoc> ArgIterator;
4816 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4817 ArgIterator(TL, TL.getNumArgs()),
4818 NewTemplateArgs))
4819 return QualType();
4820
4821 QualType Result
4822 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4823 QualifierLoc,
4824 T->getIdentifier(),
4825 TL.getNameLoc(),
4826 NewTemplateArgs);
4827 if (Result.isNull())
4828 return QualType();
4829
4830 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4831 QualType NamedT = ElabT->getNamedType();
4832
4833 // Copy information relevant to the template specialization.
4834 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004835 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004836 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004837 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4838 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004839 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004840 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004841
4842 // Copy information relevant to the elaborated type.
4843 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4844 NewTL.setKeywordLoc(TL.getKeywordLoc());
4845 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004846 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4847 DependentTemplateSpecializationTypeLoc SpecTL
4848 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor944cdae2011-03-07 15:13:34 +00004849 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004850 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004851 SpecTL.setNameLoc(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 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004857 TemplateSpecializationTypeLoc SpecTL
4858 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004859 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004860 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4861 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004862 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004863 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004864 }
4865 return Result;
4866}
4867
4868template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004869QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4870 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004871 QualType Pattern
4872 = getDerived().TransformType(TLB, TL.getPatternLoc());
4873 if (Pattern.isNull())
4874 return QualType();
4875
4876 QualType Result = TL.getType();
4877 if (getDerived().AlwaysRebuild() ||
4878 Pattern != TL.getPatternLoc().getType()) {
4879 Result = getDerived().RebuildPackExpansionType(Pattern,
4880 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004881 TL.getEllipsisLoc(),
4882 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004883 if (Result.isNull())
4884 return QualType();
4885 }
4886
4887 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4888 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4889 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004890}
4891
4892template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004893QualType
4894TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004895 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004896 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004897 TLB.pushFullCopy(TL);
4898 return TL.getType();
4899}
4900
4901template<typename Derived>
4902QualType
4903TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004904 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004905 // ObjCObjectType is never dependent.
4906 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004907 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004908}
Mike Stump1eb44332009-09-09 15:08:12 +00004909
4910template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004911QualType
4912TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004913 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004914 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004915 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004916 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004917}
4918
Douglas Gregor577f75a2009-08-04 16:50:30 +00004919//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004920// Statement transformation
4921//===----------------------------------------------------------------------===//
4922template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004923StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004924TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004925 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004926}
4927
4928template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004929StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004930TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4931 return getDerived().TransformCompoundStmt(S, false);
4932}
4933
4934template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004935StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004936TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004937 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004938 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004939 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004940 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004941 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4942 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004943 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004944 if (Result.isInvalid()) {
4945 // Immediately fail if this was a DeclStmt, since it's very
4946 // likely that this will cause problems for future statements.
4947 if (isa<DeclStmt>(*B))
4948 return StmtError();
4949
4950 // Otherwise, just keep processing substatements and fail later.
4951 SubStmtInvalid = true;
4952 continue;
4953 }
Mike Stump1eb44332009-09-09 15:08:12 +00004954
Douglas Gregor43959a92009-08-20 07:17:43 +00004955 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4956 Statements.push_back(Result.takeAs<Stmt>());
4957 }
Mike Stump1eb44332009-09-09 15:08:12 +00004958
John McCall7114cba2010-08-27 19:56:05 +00004959 if (SubStmtInvalid)
4960 return StmtError();
4961
Douglas Gregor43959a92009-08-20 07:17:43 +00004962 if (!getDerived().AlwaysRebuild() &&
4963 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004964 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004965
4966 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4967 move_arg(Statements),
4968 S->getRBracLoc(),
4969 IsStmtExpr);
4970}
Mike Stump1eb44332009-09-09 15:08:12 +00004971
Douglas Gregor43959a92009-08-20 07:17:43 +00004972template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004973StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004974TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004975 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004976 {
4977 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004978 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004979
Eli Friedman264c1f82009-11-19 03:14:00 +00004980 // Transform the left-hand case value.
4981 LHS = getDerived().TransformExpr(S->getLHS());
4982 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004983 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004984
Eli Friedman264c1f82009-11-19 03:14:00 +00004985 // Transform the right-hand case value (for the GNU case-range extension).
4986 RHS = getDerived().TransformExpr(S->getRHS());
4987 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004988 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004989 }
Mike Stump1eb44332009-09-09 15:08:12 +00004990
Douglas Gregor43959a92009-08-20 07:17:43 +00004991 // Build the case statement.
4992 // Case statements are always rebuilt so that they will attached to their
4993 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004994 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004995 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004996 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004997 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004998 S->getColonLoc());
4999 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005000 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005001
Douglas Gregor43959a92009-08-20 07:17:43 +00005002 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005003 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005004 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005005 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005006
Douglas Gregor43959a92009-08-20 07:17:43 +00005007 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005008 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005009}
5010
5011template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005012StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005013TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005014 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005015 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005016 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005017 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005018
Douglas Gregor43959a92009-08-20 07:17:43 +00005019 // Default statements are always rebuilt
5020 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005021 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005022}
Mike Stump1eb44332009-09-09 15:08:12 +00005023
Douglas Gregor43959a92009-08-20 07:17:43 +00005024template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005025StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005026TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005027 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005028 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005029 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005030
Chris Lattner57ad3782011-02-17 20:34:02 +00005031 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5032 S->getDecl());
5033 if (!LD)
5034 return StmtError();
5035
5036
Douglas Gregor43959a92009-08-20 07:17:43 +00005037 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005038 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005039 cast<LabelDecl>(LD), SourceLocation(),
5040 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005041}
Mike Stump1eb44332009-09-09 15:08:12 +00005042
Douglas Gregor43959a92009-08-20 07:17:43 +00005043template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005044StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005045TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005046 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005047 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005048 VarDecl *ConditionVar = 0;
5049 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005050 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005051 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005052 getDerived().TransformDefinition(
5053 S->getConditionVariable()->getLocation(),
5054 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005055 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005056 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005057 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005058 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005059
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005060 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005061 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005062
5063 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005064 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005065 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5066 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005067 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005068 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005069
John McCall9ae2f072010-08-23 23:25:46 +00005070 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005071 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005072 }
Sean Huntc3021132010-05-05 15:23:54 +00005073
John McCall9ae2f072010-08-23 23:25:46 +00005074 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5075 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005076 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005077
Douglas Gregor43959a92009-08-20 07:17:43 +00005078 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005079 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005080 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005081 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005082
Douglas Gregor43959a92009-08-20 07:17:43 +00005083 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005084 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005085 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005086 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005087
Douglas Gregor43959a92009-08-20 07:17:43 +00005088 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005089 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005090 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005091 Then.get() == S->getThen() &&
5092 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005093 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005094
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005095 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005096 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005097 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005098}
5099
5100template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005101StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005102TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005103 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005104 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005105 VarDecl *ConditionVar = 0;
5106 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005107 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005108 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005109 getDerived().TransformDefinition(
5110 S->getConditionVariable()->getLocation(),
5111 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005112 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005113 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005114 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005115 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005116
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005117 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005118 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005119 }
Mike Stump1eb44332009-09-09 15:08:12 +00005120
Douglas Gregor43959a92009-08-20 07:17:43 +00005121 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005122 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005123 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005124 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005125 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005126 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005127
Douglas Gregor43959a92009-08-20 07:17:43 +00005128 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005129 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005130 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005131 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005132
Douglas Gregor43959a92009-08-20 07:17:43 +00005133 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005134 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5135 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005136}
Mike Stump1eb44332009-09-09 15:08:12 +00005137
Douglas Gregor43959a92009-08-20 07:17:43 +00005138template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005139StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005140TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005141 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005142 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005143 VarDecl *ConditionVar = 0;
5144 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005145 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005146 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005147 getDerived().TransformDefinition(
5148 S->getConditionVariable()->getLocation(),
5149 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005150 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005151 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005152 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005153 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005154
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005155 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005156 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005157
5158 if (S->getCond()) {
5159 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005160 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5161 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005162 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005163 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005164 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005165 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005166 }
Mike Stump1eb44332009-09-09 15:08:12 +00005167
John McCall9ae2f072010-08-23 23:25:46 +00005168 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5169 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005170 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005171
Douglas Gregor43959a92009-08-20 07:17:43 +00005172 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005173 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005174 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005175 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005176
Douglas Gregor43959a92009-08-20 07:17:43 +00005177 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005178 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005179 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005180 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005181 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005182
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005183 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005184 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005185}
Mike Stump1eb44332009-09-09 15:08:12 +00005186
Douglas Gregor43959a92009-08-20 07:17:43 +00005187template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005188StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005189TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005190 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005191 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005192 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005193 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005194
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005195 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005196 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005197 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005198 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005199
Douglas Gregor43959a92009-08-20 07:17:43 +00005200 if (!getDerived().AlwaysRebuild() &&
5201 Cond.get() == S->getCond() &&
5202 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005203 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005204
John McCall9ae2f072010-08-23 23:25:46 +00005205 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5206 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005207 S->getRParenLoc());
5208}
Mike Stump1eb44332009-09-09 15:08:12 +00005209
Douglas Gregor43959a92009-08-20 07:17:43 +00005210template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005211StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005212TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005213 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005214 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005215 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005216 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005217
Douglas Gregor43959a92009-08-20 07:17:43 +00005218 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005219 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005220 VarDecl *ConditionVar = 0;
5221 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005222 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005223 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005224 getDerived().TransformDefinition(
5225 S->getConditionVariable()->getLocation(),
5226 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005227 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005228 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005229 } else {
5230 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005231
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005232 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005233 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005234
5235 if (S->getCond()) {
5236 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005237 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5238 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005239 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005240 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005241
John McCall9ae2f072010-08-23 23:25:46 +00005242 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005243 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005244 }
Mike Stump1eb44332009-09-09 15:08:12 +00005245
John McCall9ae2f072010-08-23 23:25:46 +00005246 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5247 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005248 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005249
Douglas Gregor43959a92009-08-20 07:17:43 +00005250 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005251 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005252 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005253 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005254
John McCall9ae2f072010-08-23 23:25:46 +00005255 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5256 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005257 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005258
Douglas Gregor43959a92009-08-20 07:17:43 +00005259 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005260 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005261 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005262 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005263
Douglas Gregor43959a92009-08-20 07:17:43 +00005264 if (!getDerived().AlwaysRebuild() &&
5265 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005266 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005267 Inc.get() == S->getInc() &&
5268 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005269 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005270
Douglas Gregor43959a92009-08-20 07:17:43 +00005271 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005272 Init.get(), FullCond, ConditionVar,
5273 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005274}
5275
5276template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005277StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005278TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005279 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5280 S->getLabel());
5281 if (!LD)
5282 return StmtError();
5283
Douglas Gregor43959a92009-08-20 07:17:43 +00005284 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005285 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005286 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005287}
5288
5289template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005290StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005291TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005292 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005293 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005294 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005295
Douglas Gregor43959a92009-08-20 07:17:43 +00005296 if (!getDerived().AlwaysRebuild() &&
5297 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005298 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005299
5300 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005301 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005302}
5303
5304template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005305StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005306TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005307 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005308}
Mike Stump1eb44332009-09-09 15:08:12 +00005309
Douglas Gregor43959a92009-08-20 07:17:43 +00005310template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005311StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005312TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005313 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005314}
Mike Stump1eb44332009-09-09 15:08:12 +00005315
Douglas Gregor43959a92009-08-20 07:17:43 +00005316template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005317StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005318TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005319 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005320 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005321 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005322
Mike Stump1eb44332009-09-09 15:08:12 +00005323 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005324 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005325 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005326}
Mike Stump1eb44332009-09-09 15:08:12 +00005327
Douglas Gregor43959a92009-08-20 07:17:43 +00005328template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005329StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005330TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005331 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005332 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005333 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5334 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005335 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5336 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005337 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005338 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005339
Douglas Gregor43959a92009-08-20 07:17:43 +00005340 if (Transformed != *D)
5341 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005342
Douglas Gregor43959a92009-08-20 07:17:43 +00005343 Decls.push_back(Transformed);
5344 }
Mike Stump1eb44332009-09-09 15:08:12 +00005345
Douglas Gregor43959a92009-08-20 07:17:43 +00005346 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005347 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005348
5349 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005350 S->getStartLoc(), S->getEndLoc());
5351}
Mike Stump1eb44332009-09-09 15:08:12 +00005352
Douglas Gregor43959a92009-08-20 07:17:43 +00005353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005354StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005355TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005356
John McCallca0408f2010-08-23 06:44:23 +00005357 ASTOwningVector<Expr*> Constraints(getSema());
5358 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005359 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005360
John McCall60d7b3a2010-08-24 06:29:42 +00005361 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005362 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005363
5364 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005365
Anders Carlsson703e3942010-01-24 05:50:09 +00005366 // Go through the outputs.
5367 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005368 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005369
Anders Carlsson703e3942010-01-24 05:50:09 +00005370 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005371 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005372
Anders Carlsson703e3942010-01-24 05:50:09 +00005373 // Transform the output expr.
5374 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005375 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005376 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005377 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005378
Anders Carlsson703e3942010-01-24 05:50:09 +00005379 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005380
John McCall9ae2f072010-08-23 23:25:46 +00005381 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005382 }
Sean Huntc3021132010-05-05 15:23:54 +00005383
Anders Carlsson703e3942010-01-24 05:50:09 +00005384 // Go through the inputs.
5385 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005386 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005387
Anders Carlsson703e3942010-01-24 05:50:09 +00005388 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005389 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005390
Anders Carlsson703e3942010-01-24 05:50:09 +00005391 // Transform the input expr.
5392 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005393 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005394 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005395 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005396
Anders Carlsson703e3942010-01-24 05:50:09 +00005397 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005398
John McCall9ae2f072010-08-23 23:25:46 +00005399 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005400 }
Sean Huntc3021132010-05-05 15:23:54 +00005401
Anders Carlsson703e3942010-01-24 05:50:09 +00005402 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005403 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005404
5405 // Go through the clobbers.
5406 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005407 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005408
5409 // No need to transform the asm string literal.
5410 AsmString = SemaRef.Owned(S->getAsmString());
5411
5412 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5413 S->isSimple(),
5414 S->isVolatile(),
5415 S->getNumOutputs(),
5416 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005417 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005418 move_arg(Constraints),
5419 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005420 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005421 move_arg(Clobbers),
5422 S->getRParenLoc(),
5423 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005424}
5425
5426
5427template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005428StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005429TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005430 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005431 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005432 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005433 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005434
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005435 // Transform the @catch statements (if present).
5436 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005437 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005438 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005439 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005440 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005441 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005442 if (Catch.get() != S->getCatchStmt(I))
5443 AnyCatchChanged = true;
5444 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005445 }
Sean Huntc3021132010-05-05 15:23:54 +00005446
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005447 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005448 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005449 if (S->getFinallyStmt()) {
5450 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5451 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005452 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005453 }
5454
5455 // If nothing changed, just retain this statement.
5456 if (!getDerived().AlwaysRebuild() &&
5457 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005458 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005459 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005460 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005461
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005462 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005463 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5464 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005465}
Mike Stump1eb44332009-09-09 15:08:12 +00005466
Douglas Gregor43959a92009-08-20 07:17:43 +00005467template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005468StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005469TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005470 // Transform the @catch parameter, if there is one.
5471 VarDecl *Var = 0;
5472 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5473 TypeSourceInfo *TSInfo = 0;
5474 if (FromVar->getTypeSourceInfo()) {
5475 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5476 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005477 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005478 }
Sean Huntc3021132010-05-05 15:23:54 +00005479
Douglas Gregorbe270a02010-04-26 17:57:08 +00005480 QualType T;
5481 if (TSInfo)
5482 T = TSInfo->getType();
5483 else {
5484 T = getDerived().TransformType(FromVar->getType());
5485 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005486 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005487 }
Sean Huntc3021132010-05-05 15:23:54 +00005488
Douglas Gregorbe270a02010-04-26 17:57:08 +00005489 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5490 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005491 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005492 }
Sean Huntc3021132010-05-05 15:23:54 +00005493
John McCall60d7b3a2010-08-24 06:29:42 +00005494 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005495 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005496 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005497
5498 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005499 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005500 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005501}
Mike Stump1eb44332009-09-09 15:08:12 +00005502
Douglas Gregor43959a92009-08-20 07:17:43 +00005503template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005504StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005505TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005506 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005507 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005508 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005509 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005510
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005511 // If nothing changed, just retain this statement.
5512 if (!getDerived().AlwaysRebuild() &&
5513 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005514 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005515
5516 // Build a new statement.
5517 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005518 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005519}
Mike Stump1eb44332009-09-09 15:08:12 +00005520
Douglas Gregor43959a92009-08-20 07:17:43 +00005521template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005522StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005523TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005524 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005525 if (S->getThrowExpr()) {
5526 Operand = getDerived().TransformExpr(S->getThrowExpr());
5527 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005528 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005529 }
Sean Huntc3021132010-05-05 15:23:54 +00005530
Douglas Gregord1377b22010-04-22 21:44:01 +00005531 if (!getDerived().AlwaysRebuild() &&
5532 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005533 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005534
John McCall9ae2f072010-08-23 23:25:46 +00005535 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005536}
Mike Stump1eb44332009-09-09 15:08:12 +00005537
Douglas Gregor43959a92009-08-20 07:17:43 +00005538template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005539StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005540TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005541 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005542 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005543 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005544 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005545 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005546 Object =
5547 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5548 Object.get());
5549 if (Object.isInvalid())
5550 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005551
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005552 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005553 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005554 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005555 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005556
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005557 // If nothing change, just retain the current statement.
5558 if (!getDerived().AlwaysRebuild() &&
5559 Object.get() == S->getSynchExpr() &&
5560 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005561 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005562
5563 // Build a new statement.
5564 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005565 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005566}
5567
5568template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005569StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005570TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5571 ObjCAutoreleasePoolStmt *S) {
5572 // Transform the body.
5573 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5574 if (Body.isInvalid())
5575 return StmtError();
5576
5577 // If nothing changed, just retain this statement.
5578 if (!getDerived().AlwaysRebuild() &&
5579 Body.get() == S->getSubStmt())
5580 return SemaRef.Owned(S);
5581
5582 // Build a new statement.
5583 return getDerived().RebuildObjCAutoreleasePoolStmt(
5584 S->getAtLoc(), Body.get());
5585}
5586
5587template<typename Derived>
5588StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005589TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005590 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005591 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005592 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005593 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005594 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005595
Douglas Gregorc3203e72010-04-22 23:10:45 +00005596 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005597 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005598 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005599 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005600 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5601 Collection.take());
5602 if (Collection.isInvalid())
5603 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005604
Douglas Gregorc3203e72010-04-22 23:10:45 +00005605 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005606 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005607 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005608 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005609
Douglas Gregorc3203e72010-04-22 23:10:45 +00005610 // If nothing changed, just retain this statement.
5611 if (!getDerived().AlwaysRebuild() &&
5612 Element.get() == S->getElement() &&
5613 Collection.get() == S->getCollection() &&
5614 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005615 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005616
Douglas Gregorc3203e72010-04-22 23:10:45 +00005617 // Build a new statement.
5618 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5619 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005620 Element.get(),
5621 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005622 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005623 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005624}
5625
5626
5627template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005628StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005629TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5630 // Transform the exception declaration, if any.
5631 VarDecl *Var = 0;
5632 if (S->getExceptionDecl()) {
5633 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005634 TypeSourceInfo *T = getDerived().TransformType(
5635 ExceptionDecl->getTypeSourceInfo());
5636 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005637 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005638
Douglas Gregor83cb9422010-09-09 17:09:21 +00005639 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005640 ExceptionDecl->getInnerLocStart(),
5641 ExceptionDecl->getLocation(),
5642 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005643 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005644 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005645 }
Mike Stump1eb44332009-09-09 15:08:12 +00005646
Douglas Gregor43959a92009-08-20 07:17:43 +00005647 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005648 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005649 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005650 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005651
Douglas Gregor43959a92009-08-20 07:17:43 +00005652 if (!getDerived().AlwaysRebuild() &&
5653 !Var &&
5654 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005655 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005656
5657 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5658 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005659 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005660}
Mike Stump1eb44332009-09-09 15:08:12 +00005661
Douglas Gregor43959a92009-08-20 07:17:43 +00005662template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005663StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005664TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5665 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005666 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005667 = getDerived().TransformCompoundStmt(S->getTryBlock());
5668 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005669 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005670
Douglas Gregor43959a92009-08-20 07:17:43 +00005671 // Transform the handlers.
5672 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005673 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005674 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005675 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005676 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5677 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005678 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005679
Douglas Gregor43959a92009-08-20 07:17:43 +00005680 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5681 Handlers.push_back(Handler.takeAs<Stmt>());
5682 }
Mike Stump1eb44332009-09-09 15:08:12 +00005683
Douglas Gregor43959a92009-08-20 07:17:43 +00005684 if (!getDerived().AlwaysRebuild() &&
5685 TryBlock.get() == S->getTryBlock() &&
5686 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005687 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005688
John McCall9ae2f072010-08-23 23:25:46 +00005689 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005690 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005691}
Mike Stump1eb44332009-09-09 15:08:12 +00005692
Richard Smithad762fc2011-04-14 22:09:26 +00005693template<typename Derived>
5694StmtResult
5695TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5696 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5697 if (Range.isInvalid())
5698 return StmtError();
5699
5700 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5701 if (BeginEnd.isInvalid())
5702 return StmtError();
5703
5704 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5705 if (Cond.isInvalid())
5706 return StmtError();
5707
5708 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5709 if (Inc.isInvalid())
5710 return StmtError();
5711
5712 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5713 if (LoopVar.isInvalid())
5714 return StmtError();
5715
5716 StmtResult NewStmt = S;
5717 if (getDerived().AlwaysRebuild() ||
5718 Range.get() != S->getRangeStmt() ||
5719 BeginEnd.get() != S->getBeginEndStmt() ||
5720 Cond.get() != S->getCond() ||
5721 Inc.get() != S->getInc() ||
5722 LoopVar.get() != S->getLoopVarStmt())
5723 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5724 S->getColonLoc(), Range.get(),
5725 BeginEnd.get(), Cond.get(),
5726 Inc.get(), LoopVar.get(),
5727 S->getRParenLoc());
5728
5729 StmtResult Body = getDerived().TransformStmt(S->getBody());
5730 if (Body.isInvalid())
5731 return StmtError();
5732
5733 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5734 // it now so we have a new statement to attach the body to.
5735 if (Body.get() != S->getBody() && NewStmt.get() == S)
5736 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5737 S->getColonLoc(), Range.get(),
5738 BeginEnd.get(), Cond.get(),
5739 Inc.get(), LoopVar.get(),
5740 S->getRParenLoc());
5741
5742 if (NewStmt.get() == S)
5743 return SemaRef.Owned(S);
5744
5745 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5746}
5747
John Wiegley28bbe4b2011-04-28 01:08:34 +00005748template<typename Derived>
5749StmtResult
5750TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5751 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5752 if(TryBlock.isInvalid()) return StmtError();
5753
5754 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5755 if(!getDerived().AlwaysRebuild() &&
5756 TryBlock.get() == S->getTryBlock() &&
5757 Handler.get() == S->getHandler())
5758 return SemaRef.Owned(S);
5759
5760 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5761 S->getTryLoc(),
5762 TryBlock.take(),
5763 Handler.take());
5764}
5765
5766template<typename Derived>
5767StmtResult
5768TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5769 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5770 if(Block.isInvalid()) return StmtError();
5771
5772 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5773 Block.take());
5774}
5775
5776template<typename Derived>
5777StmtResult
5778TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5779 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5780 if(FilterExpr.isInvalid()) return StmtError();
5781
5782 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5783 if(Block.isInvalid()) return StmtError();
5784
5785 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5786 FilterExpr.take(),
5787 Block.take());
5788}
5789
5790template<typename Derived>
5791StmtResult
5792TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5793 if(isa<SEHFinallyStmt>(Handler))
5794 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5795 else
5796 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5797}
5798
Douglas Gregor43959a92009-08-20 07:17:43 +00005799//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005800// Expression transformation
5801//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005802template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005803ExprResult
John McCall454feb92009-12-08 09:21:05 +00005804TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005805 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005806}
Mike Stump1eb44332009-09-09 15:08:12 +00005807
5808template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005809ExprResult
John McCall454feb92009-12-08 09:21:05 +00005810TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005811 NestedNameSpecifierLoc QualifierLoc;
5812 if (E->getQualifierLoc()) {
5813 QualifierLoc
5814 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5815 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005816 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005817 }
John McCalldbd872f2009-12-08 09:08:17 +00005818
5819 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005820 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5821 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005822 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005823 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005824
John McCallec8045d2010-08-17 21:27:17 +00005825 DeclarationNameInfo NameInfo = E->getNameInfo();
5826 if (NameInfo.getName()) {
5827 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5828 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005829 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005830 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005831
5832 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005833 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005834 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005835 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005836 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005837
5838 // Mark it referenced in the new context regardless.
5839 // FIXME: this is a bit instantiation-specific.
5840 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5841
John McCall3fa5cae2010-10-26 07:05:15 +00005842 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005843 }
John McCalldbd872f2009-12-08 09:08:17 +00005844
5845 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005846 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005847 TemplateArgs = &TransArgs;
5848 TransArgs.setLAngleLoc(E->getLAngleLoc());
5849 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005850 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5851 E->getNumTemplateArgs(),
5852 TransArgs))
5853 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005854 }
5855
Douglas Gregor40d96a62011-02-28 21:54:11 +00005856 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5857 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005858}
Mike Stump1eb44332009-09-09 15:08:12 +00005859
Douglas Gregorb98b1992009-08-11 05:31:07 +00005860template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005861ExprResult
John McCall454feb92009-12-08 09:21:05 +00005862TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005863 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005864}
Mike Stump1eb44332009-09-09 15:08:12 +00005865
Douglas Gregorb98b1992009-08-11 05:31:07 +00005866template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005867ExprResult
John McCall454feb92009-12-08 09:21:05 +00005868TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005869 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005870}
Mike Stump1eb44332009-09-09 15:08:12 +00005871
Douglas Gregorb98b1992009-08-11 05:31:07 +00005872template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005873ExprResult
John McCall454feb92009-12-08 09:21:05 +00005874TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005875 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005876}
Mike Stump1eb44332009-09-09 15:08:12 +00005877
Douglas Gregorb98b1992009-08-11 05:31:07 +00005878template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005879ExprResult
John McCall454feb92009-12-08 09:21:05 +00005880TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005881 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005882}
Mike Stump1eb44332009-09-09 15:08:12 +00005883
Douglas Gregorb98b1992009-08-11 05:31:07 +00005884template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005885ExprResult
John McCall454feb92009-12-08 09:21:05 +00005886TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005887 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005888}
5889
5890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005891ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00005892TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5893 ExprResult ControllingExpr =
5894 getDerived().TransformExpr(E->getControllingExpr());
5895 if (ControllingExpr.isInvalid())
5896 return ExprError();
5897
Chris Lattner686775d2011-07-20 06:58:45 +00005898 SmallVector<Expr *, 4> AssocExprs;
5899 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00005900 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5901 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5902 if (TS) {
5903 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5904 if (!AssocType)
5905 return ExprError();
5906 AssocTypes.push_back(AssocType);
5907 } else {
5908 AssocTypes.push_back(0);
5909 }
5910
5911 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5912 if (AssocExpr.isInvalid())
5913 return ExprError();
5914 AssocExprs.push_back(AssocExpr.release());
5915 }
5916
5917 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5918 E->getDefaultLoc(),
5919 E->getRParenLoc(),
5920 ControllingExpr.release(),
5921 AssocTypes.data(),
5922 AssocExprs.data(),
5923 E->getNumAssocs());
5924}
5925
5926template<typename Derived>
5927ExprResult
John McCall454feb92009-12-08 09:21:05 +00005928TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005929 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005930 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005931 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005932
Douglas Gregorb98b1992009-08-11 05:31:07 +00005933 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005934 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005935
John McCall9ae2f072010-08-23 23:25:46 +00005936 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005937 E->getRParen());
5938}
5939
Mike Stump1eb44332009-09-09 15:08:12 +00005940template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005941ExprResult
John McCall454feb92009-12-08 09:21:05 +00005942TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005943 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005944 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005945 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005946
Douglas Gregorb98b1992009-08-11 05:31:07 +00005947 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005948 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005949
Douglas Gregorb98b1992009-08-11 05:31:07 +00005950 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5951 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005952 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005953}
Mike Stump1eb44332009-09-09 15:08:12 +00005954
Douglas Gregorb98b1992009-08-11 05:31:07 +00005955template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005956ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005957TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5958 // Transform the type.
5959 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5960 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005961 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005962
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005963 // Transform all of the components into components similar to what the
5964 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005965 // FIXME: It would be slightly more efficient in the non-dependent case to
5966 // just map FieldDecls, rather than requiring the rebuilder to look for
5967 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005968 // template code that we don't care.
5969 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005970 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005971 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00005972 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005973 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5974 const Node &ON = E->getComponent(I);
5975 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005976 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00005977 Comp.LocStart = ON.getSourceRange().getBegin();
5978 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005979 switch (ON.getKind()) {
5980 case Node::Array: {
5981 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005982 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005983 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005984 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005985
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005986 ExprChanged = ExprChanged || Index.get() != FromIndex;
5987 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005988 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005989 break;
5990 }
Sean Huntc3021132010-05-05 15:23:54 +00005991
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005992 case Node::Field:
5993 case Node::Identifier:
5994 Comp.isBrackets = false;
5995 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005996 if (!Comp.U.IdentInfo)
5997 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005998
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005999 break;
Sean Huntc3021132010-05-05 15:23:54 +00006000
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006001 case Node::Base:
6002 // Will be recomputed during the rebuild.
6003 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006004 }
Sean Huntc3021132010-05-05 15:23:54 +00006005
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006006 Components.push_back(Comp);
6007 }
Sean Huntc3021132010-05-05 15:23:54 +00006008
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006009 // If nothing changed, retain the existing expression.
6010 if (!getDerived().AlwaysRebuild() &&
6011 Type == E->getTypeSourceInfo() &&
6012 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006013 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006014
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006015 // Build a new offsetof expression.
6016 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6017 Components.data(), Components.size(),
6018 E->getRParenLoc());
6019}
6020
6021template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006022ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006023TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6024 assert(getDerived().AlreadyTransformed(E->getType()) &&
6025 "opaque value expression requires transformation");
6026 return SemaRef.Owned(E);
6027}
6028
6029template<typename Derived>
6030ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006031TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6032 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006033 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006034 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006035
John McCalla93c9342009-12-07 02:54:59 +00006036 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006037 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006038 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006039
John McCall5ab75172009-11-04 07:28:41 +00006040 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006041 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006042
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006043 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6044 E->getKind(),
6045 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006046 }
Mike Stump1eb44332009-09-09 15:08:12 +00006047
John McCall60d7b3a2010-08-24 06:29:42 +00006048 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00006049 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006050 // C++0x [expr.sizeof]p1:
6051 // The operand is either an expression, which is an unevaluated operand
6052 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00006053 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006054
Douglas Gregorb98b1992009-08-11 05:31:07 +00006055 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6056 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006057 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006058
Douglas Gregorb98b1992009-08-11 05:31:07 +00006059 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006060 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006061 }
Mike Stump1eb44332009-09-09 15:08:12 +00006062
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006063 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6064 E->getOperatorLoc(),
6065 E->getKind(),
6066 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006067}
Mike Stump1eb44332009-09-09 15:08:12 +00006068
Douglas Gregorb98b1992009-08-11 05:31:07 +00006069template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006070ExprResult
John McCall454feb92009-12-08 09:21:05 +00006071TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006072 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006073 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006074 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006075
John McCall60d7b3a2010-08-24 06:29:42 +00006076 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006077 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006078 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006079
6080
Douglas Gregorb98b1992009-08-11 05:31:07 +00006081 if (!getDerived().AlwaysRebuild() &&
6082 LHS.get() == E->getLHS() &&
6083 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006084 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006085
John McCall9ae2f072010-08-23 23:25:46 +00006086 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006087 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006088 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006089 E->getRBracketLoc());
6090}
Mike Stump1eb44332009-09-09 15:08:12 +00006091
6092template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006093ExprResult
John McCall454feb92009-12-08 09:21:05 +00006094TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006095 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006096 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006097 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006098 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006099
6100 // Transform arguments.
6101 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006102 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006103 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6104 &ArgChanged))
6105 return ExprError();
6106
Douglas Gregorb98b1992009-08-11 05:31:07 +00006107 if (!getDerived().AlwaysRebuild() &&
6108 Callee.get() == E->getCallee() &&
6109 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006110 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006111
Douglas Gregorb98b1992009-08-11 05:31:07 +00006112 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006113 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006114 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006115 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006116 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006117 E->getRParenLoc());
6118}
Mike Stump1eb44332009-09-09 15:08:12 +00006119
6120template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006121ExprResult
John McCall454feb92009-12-08 09:21:05 +00006122TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006123 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006124 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006125 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006126
Douglas Gregor40d96a62011-02-28 21:54:11 +00006127 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006128 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006129 QualifierLoc
6130 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6131
6132 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006133 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006134 }
Mike Stump1eb44332009-09-09 15:08:12 +00006135
Eli Friedmanf595cc42009-12-04 06:40:45 +00006136 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006137 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6138 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006139 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006140 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006141
John McCall6bb80172010-03-30 21:47:33 +00006142 NamedDecl *FoundDecl = E->getFoundDecl();
6143 if (FoundDecl == E->getMemberDecl()) {
6144 FoundDecl = Member;
6145 } else {
6146 FoundDecl = cast_or_null<NamedDecl>(
6147 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6148 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006149 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006150 }
6151
Douglas Gregorb98b1992009-08-11 05:31:07 +00006152 if (!getDerived().AlwaysRebuild() &&
6153 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006154 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006155 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006156 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006157 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006158
Anders Carlsson1f240322009-12-22 05:24:09 +00006159 // Mark it referenced in the new context regardless.
6160 // FIXME: this is a bit instantiation-specific.
6161 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00006162 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006163 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006164
John McCalld5532b62009-11-23 01:53:49 +00006165 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006166 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006167 TransArgs.setLAngleLoc(E->getLAngleLoc());
6168 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006169 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6170 E->getNumTemplateArgs(),
6171 TransArgs))
6172 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006173 }
Sean Huntc3021132010-05-05 15:23:54 +00006174
Douglas Gregorb98b1992009-08-11 05:31:07 +00006175 // FIXME: Bogus source location for the operator
6176 SourceLocation FakeOperatorLoc
6177 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6178
John McCallc2233c52010-01-15 08:34:02 +00006179 // FIXME: to do this check properly, we will need to preserve the
6180 // first-qualifier-in-scope here, just in case we had a dependent
6181 // base (and therefore couldn't do the check) and a
6182 // nested-name-qualifier (and therefore could do the lookup).
6183 NamedDecl *FirstQualifierInScope = 0;
6184
John McCall9ae2f072010-08-23 23:25:46 +00006185 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006186 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006187 QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006188 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006189 Member,
John McCall6bb80172010-03-30 21:47:33 +00006190 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006191 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006192 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006193 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006194}
Mike Stump1eb44332009-09-09 15:08:12 +00006195
Douglas Gregorb98b1992009-08-11 05:31:07 +00006196template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006197ExprResult
John McCall454feb92009-12-08 09:21:05 +00006198TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006199 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006200 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006201 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006202
John McCall60d7b3a2010-08-24 06:29:42 +00006203 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006204 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006205 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006206
Douglas Gregorb98b1992009-08-11 05:31:07 +00006207 if (!getDerived().AlwaysRebuild() &&
6208 LHS.get() == E->getLHS() &&
6209 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006210 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006211
Douglas Gregorb98b1992009-08-11 05:31:07 +00006212 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006213 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006214}
6215
Mike Stump1eb44332009-09-09 15:08:12 +00006216template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006217ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006218TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006219 CompoundAssignOperator *E) {
6220 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006221}
Mike Stump1eb44332009-09-09 15:08:12 +00006222
Douglas Gregorb98b1992009-08-11 05:31:07 +00006223template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006224ExprResult TreeTransform<Derived>::
6225TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6226 // Just rebuild the common and RHS expressions and see whether we
6227 // get any changes.
6228
6229 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6230 if (commonExpr.isInvalid())
6231 return ExprError();
6232
6233 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6234 if (rhs.isInvalid())
6235 return ExprError();
6236
6237 if (!getDerived().AlwaysRebuild() &&
6238 commonExpr.get() == e->getCommon() &&
6239 rhs.get() == e->getFalseExpr())
6240 return SemaRef.Owned(e);
6241
6242 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6243 e->getQuestionLoc(),
6244 0,
6245 e->getColonLoc(),
6246 rhs.get());
6247}
6248
6249template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006250ExprResult
John McCall454feb92009-12-08 09:21:05 +00006251TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006252 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006253 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006254 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006255
John McCall60d7b3a2010-08-24 06:29:42 +00006256 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006257 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006258 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006259
John McCall60d7b3a2010-08-24 06:29:42 +00006260 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006261 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006262 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006263
Douglas Gregorb98b1992009-08-11 05:31:07 +00006264 if (!getDerived().AlwaysRebuild() &&
6265 Cond.get() == E->getCond() &&
6266 LHS.get() == E->getLHS() &&
6267 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006268 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006269
John McCall9ae2f072010-08-23 23:25:46 +00006270 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006271 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006272 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006273 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006274 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006275}
Mike Stump1eb44332009-09-09 15:08:12 +00006276
6277template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006278ExprResult
John McCall454feb92009-12-08 09:21:05 +00006279TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006280 // Implicit casts are eliminated during transformation, since they
6281 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006282 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006283}
Mike Stump1eb44332009-09-09 15:08:12 +00006284
Douglas Gregorb98b1992009-08-11 05:31:07 +00006285template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006286ExprResult
John McCall454feb92009-12-08 09:21:05 +00006287TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006288 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6289 if (!Type)
6290 return ExprError();
6291
John McCall60d7b3a2010-08-24 06:29:42 +00006292 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006293 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006294 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006295 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006296
Douglas Gregorb98b1992009-08-11 05:31:07 +00006297 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006298 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006299 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006300 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006301
John McCall9d125032010-01-15 18:39:57 +00006302 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006303 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006304 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006305 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006306}
Mike Stump1eb44332009-09-09 15:08:12 +00006307
Douglas Gregorb98b1992009-08-11 05:31:07 +00006308template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006309ExprResult
John McCall454feb92009-12-08 09:21:05 +00006310TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006311 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6312 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6313 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006314 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006315
John McCall60d7b3a2010-08-24 06:29:42 +00006316 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006317 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006318 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006319
Douglas Gregorb98b1992009-08-11 05:31:07 +00006320 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006321 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006322 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00006323 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006324
John McCall1d7d8d62010-01-19 22:33:45 +00006325 // Note: the expression type doesn't necessarily match the
6326 // type-as-written, but that's okay, because it should always be
6327 // derivable from the initializer.
6328
John McCall42f56b52010-01-18 19:35:47 +00006329 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006330 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006331 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006332}
Mike Stump1eb44332009-09-09 15:08:12 +00006333
Douglas Gregorb98b1992009-08-11 05:31:07 +00006334template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006335ExprResult
John McCall454feb92009-12-08 09:21:05 +00006336TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006337 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006338 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006339 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006340
Douglas Gregorb98b1992009-08-11 05:31:07 +00006341 if (!getDerived().AlwaysRebuild() &&
6342 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006343 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006344
Douglas Gregorb98b1992009-08-11 05:31:07 +00006345 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006346 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006347 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006348 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006349 E->getAccessorLoc(),
6350 E->getAccessor());
6351}
Mike Stump1eb44332009-09-09 15:08:12 +00006352
Douglas Gregorb98b1992009-08-11 05:31:07 +00006353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006354ExprResult
John McCall454feb92009-12-08 09:21:05 +00006355TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006356 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006357
John McCallca0408f2010-08-23 06:44:23 +00006358 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006359 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6360 Inits, &InitChanged))
6361 return ExprError();
6362
Douglas Gregorb98b1992009-08-11 05:31:07 +00006363 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006364 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006365
Douglas Gregorb98b1992009-08-11 05:31:07 +00006366 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006367 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006368}
Mike Stump1eb44332009-09-09 15:08:12 +00006369
Douglas Gregorb98b1992009-08-11 05:31:07 +00006370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006371ExprResult
John McCall454feb92009-12-08 09:21:05 +00006372TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006373 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006374
Douglas Gregor43959a92009-08-20 07:17:43 +00006375 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006376 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006377 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006378 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006379
Douglas Gregor43959a92009-08-20 07:17:43 +00006380 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006381 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006382 bool ExprChanged = false;
6383 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6384 DEnd = E->designators_end();
6385 D != DEnd; ++D) {
6386 if (D->isFieldDesignator()) {
6387 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6388 D->getDotLoc(),
6389 D->getFieldLoc()));
6390 continue;
6391 }
Mike Stump1eb44332009-09-09 15:08:12 +00006392
Douglas Gregorb98b1992009-08-11 05:31:07 +00006393 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006394 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006395 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006396 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006397
6398 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006399 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006400
Douglas Gregorb98b1992009-08-11 05:31:07 +00006401 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6402 ArrayExprs.push_back(Index.release());
6403 continue;
6404 }
Mike Stump1eb44332009-09-09 15:08:12 +00006405
Douglas Gregorb98b1992009-08-11 05:31:07 +00006406 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006407 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006408 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6409 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006410 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006411
John McCall60d7b3a2010-08-24 06:29:42 +00006412 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006413 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006414 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006415
6416 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006417 End.get(),
6418 D->getLBracketLoc(),
6419 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006420
Douglas Gregorb98b1992009-08-11 05:31:07 +00006421 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6422 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006423
Douglas Gregorb98b1992009-08-11 05:31:07 +00006424 ArrayExprs.push_back(Start.release());
6425 ArrayExprs.push_back(End.release());
6426 }
Mike Stump1eb44332009-09-09 15:08:12 +00006427
Douglas Gregorb98b1992009-08-11 05:31:07 +00006428 if (!getDerived().AlwaysRebuild() &&
6429 Init.get() == E->getInit() &&
6430 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006431 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006432
Douglas Gregorb98b1992009-08-11 05:31:07 +00006433 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6434 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006435 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006436}
Mike Stump1eb44332009-09-09 15:08:12 +00006437
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006439ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006440TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006441 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006442 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006443
Douglas Gregor5557b252009-10-28 00:29:27 +00006444 // FIXME: Will we ever have proper type location here? Will we actually
6445 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006446 QualType T = getDerived().TransformType(E->getType());
6447 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006448 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006449
Douglas Gregorb98b1992009-08-11 05:31:07 +00006450 if (!getDerived().AlwaysRebuild() &&
6451 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006452 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006453
Douglas Gregorb98b1992009-08-11 05:31:07 +00006454 return getDerived().RebuildImplicitValueInitExpr(T);
6455}
Mike Stump1eb44332009-09-09 15:08:12 +00006456
Douglas Gregorb98b1992009-08-11 05:31:07 +00006457template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006458ExprResult
John McCall454feb92009-12-08 09:21:05 +00006459TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006460 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6461 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006462 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006463
John McCall60d7b3a2010-08-24 06:29:42 +00006464 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006465 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006466 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006467
Douglas Gregorb98b1992009-08-11 05:31:07 +00006468 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006469 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006470 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006471 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006472
John McCall9ae2f072010-08-23 23:25:46 +00006473 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006474 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006475}
6476
6477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006478ExprResult
John McCall454feb92009-12-08 09:21:05 +00006479TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006480 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006481 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006482 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6483 &ArgumentChanged))
6484 return ExprError();
6485
Douglas Gregorb98b1992009-08-11 05:31:07 +00006486 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6487 move_arg(Inits),
6488 E->getRParenLoc());
6489}
Mike Stump1eb44332009-09-09 15:08:12 +00006490
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491/// \brief Transform an address-of-label expression.
6492///
6493/// By default, the transformation of an address-of-label expression always
6494/// rebuilds the expression, so that the label identifier can be resolved to
6495/// the corresponding label statement by semantic analysis.
6496template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006497ExprResult
John McCall454feb92009-12-08 09:21:05 +00006498TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006499 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6500 E->getLabel());
6501 if (!LD)
6502 return ExprError();
6503
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006505 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506}
Mike Stump1eb44332009-09-09 15:08:12 +00006507
6508template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006509ExprResult
John McCall454feb92009-12-08 09:21:05 +00006510TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006511 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006512 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6513 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006514 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006515
Douglas Gregorb98b1992009-08-11 05:31:07 +00006516 if (!getDerived().AlwaysRebuild() &&
6517 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00006518 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006519
6520 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006521 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006522 E->getRParenLoc());
6523}
Mike Stump1eb44332009-09-09 15:08:12 +00006524
Douglas Gregorb98b1992009-08-11 05:31:07 +00006525template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006526ExprResult
John McCall454feb92009-12-08 09:21:05 +00006527TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006528 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006529 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006530 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006531
John McCall60d7b3a2010-08-24 06:29:42 +00006532 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006533 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006534 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006535
John McCall60d7b3a2010-08-24 06:29:42 +00006536 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006537 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006538 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006539
Douglas Gregorb98b1992009-08-11 05:31:07 +00006540 if (!getDerived().AlwaysRebuild() &&
6541 Cond.get() == E->getCond() &&
6542 LHS.get() == E->getLHS() &&
6543 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006544 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006545
Douglas Gregorb98b1992009-08-11 05:31:07 +00006546 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006547 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548 E->getRParenLoc());
6549}
Mike Stump1eb44332009-09-09 15:08:12 +00006550
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006552ExprResult
John McCall454feb92009-12-08 09:21:05 +00006553TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006554 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006555}
6556
6557template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006558ExprResult
John McCall454feb92009-12-08 09:21:05 +00006559TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006560 switch (E->getOperator()) {
6561 case OO_New:
6562 case OO_Delete:
6563 case OO_Array_New:
6564 case OO_Array_Delete:
6565 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006566 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006567
Douglas Gregor668d6d92009-12-13 20:44:55 +00006568 case OO_Call: {
6569 // This is a call to an object's operator().
6570 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6571
6572 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006573 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006574 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006575 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006576
6577 // FIXME: Poor location information
6578 SourceLocation FakeLParenLoc
6579 = SemaRef.PP.getLocForEndOfToken(
6580 static_cast<Expr *>(Object.get())->getLocEnd());
6581
6582 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006583 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006584 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6585 Args))
6586 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006587
John McCall9ae2f072010-08-23 23:25:46 +00006588 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006589 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006590 E->getLocEnd());
6591 }
6592
6593#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6594 case OO_##Name:
6595#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6596#include "clang/Basic/OperatorKinds.def"
6597 case OO_Subscript:
6598 // Handled below.
6599 break;
6600
6601 case OO_Conditional:
6602 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006603 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006604
6605 case OO_None:
6606 case NUM_OVERLOADED_OPERATORS:
6607 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006608 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006609 }
6610
John McCall60d7b3a2010-08-24 06:29:42 +00006611 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006612 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006613 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006614
John McCall60d7b3a2010-08-24 06:29:42 +00006615 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006616 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006617 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618
John McCall60d7b3a2010-08-24 06:29:42 +00006619 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006620 if (E->getNumArgs() == 2) {
6621 Second = getDerived().TransformExpr(E->getArg(1));
6622 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006623 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624 }
Mike Stump1eb44332009-09-09 15:08:12 +00006625
Douglas Gregorb98b1992009-08-11 05:31:07 +00006626 if (!getDerived().AlwaysRebuild() &&
6627 Callee.get() == E->getCallee() &&
6628 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006629 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00006630 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006631
Douglas Gregorb98b1992009-08-11 05:31:07 +00006632 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6633 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006634 Callee.get(),
6635 First.get(),
6636 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006637}
Mike Stump1eb44332009-09-09 15:08:12 +00006638
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006640ExprResult
John McCall454feb92009-12-08 09:21:05 +00006641TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6642 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643}
Mike Stump1eb44332009-09-09 15:08:12 +00006644
Douglas Gregorb98b1992009-08-11 05:31:07 +00006645template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006646ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006647TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6648 // Transform the callee.
6649 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6650 if (Callee.isInvalid())
6651 return ExprError();
6652
6653 // Transform exec config.
6654 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6655 if (EC.isInvalid())
6656 return ExprError();
6657
6658 // Transform arguments.
6659 bool ArgChanged = false;
6660 ASTOwningVector<Expr*> Args(SemaRef);
6661 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6662 &ArgChanged))
6663 return ExprError();
6664
6665 if (!getDerived().AlwaysRebuild() &&
6666 Callee.get() == E->getCallee() &&
6667 !ArgChanged)
6668 return SemaRef.Owned(E);
6669
6670 // FIXME: Wrong source location information for the '('.
6671 SourceLocation FakeLParenLoc
6672 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6673 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6674 move_arg(Args),
6675 E->getRParenLoc(), EC.get());
6676}
6677
6678template<typename Derived>
6679ExprResult
John McCall454feb92009-12-08 09:21:05 +00006680TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006681 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6682 if (!Type)
6683 return ExprError();
6684
John McCall60d7b3a2010-08-24 06:29:42 +00006685 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006686 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006687 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006688 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006689
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006691 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006693 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006694
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006696 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006697 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6698 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6699 SourceLocation FakeRParenLoc
6700 = SemaRef.PP.getLocForEndOfToken(
6701 E->getSubExpr()->getSourceRange().getEnd());
6702 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006703 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006704 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006705 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006706 FakeRAngleLoc,
6707 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006708 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006709 FakeRParenLoc);
6710}
Mike Stump1eb44332009-09-09 15:08:12 +00006711
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006713ExprResult
John McCall454feb92009-12-08 09:21:05 +00006714TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6715 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006716}
Mike Stump1eb44332009-09-09 15:08:12 +00006717
6718template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006719ExprResult
John McCall454feb92009-12-08 09:21:05 +00006720TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6721 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006722}
6723
Douglas Gregorb98b1992009-08-11 05:31:07 +00006724template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006725ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006726TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006727 CXXReinterpretCastExpr *E) {
6728 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006729}
Mike Stump1eb44332009-09-09 15:08:12 +00006730
Douglas Gregorb98b1992009-08-11 05:31:07 +00006731template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006732ExprResult
John McCall454feb92009-12-08 09:21:05 +00006733TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6734 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006735}
Mike Stump1eb44332009-09-09 15:08:12 +00006736
Douglas Gregorb98b1992009-08-11 05:31:07 +00006737template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006738ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006739TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006740 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006741 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6742 if (!Type)
6743 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006744
John McCall60d7b3a2010-08-24 06:29:42 +00006745 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006746 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006747 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006748 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006749
Douglas Gregorb98b1992009-08-11 05:31:07 +00006750 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006751 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006752 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006753 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006754
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006755 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006757 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006758 E->getRParenLoc());
6759}
Mike Stump1eb44332009-09-09 15:08:12 +00006760
Douglas Gregorb98b1992009-08-11 05:31:07 +00006761template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006762ExprResult
John McCall454feb92009-12-08 09:21:05 +00006763TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006764 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006765 TypeSourceInfo *TInfo
6766 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6767 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006768 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006769
Douglas Gregorb98b1992009-08-11 05:31:07 +00006770 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006771 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006772 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006773
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006774 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6775 E->getLocStart(),
6776 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006777 E->getLocEnd());
6778 }
Mike Stump1eb44332009-09-09 15:08:12 +00006779
Douglas Gregorb98b1992009-08-11 05:31:07 +00006780 // We don't know whether the expression is potentially evaluated until
6781 // after we perform semantic analysis, so the expression is potentially
6782 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006783 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006784 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006785
John McCall60d7b3a2010-08-24 06:29:42 +00006786 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006787 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006788 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006789
Douglas Gregorb98b1992009-08-11 05:31:07 +00006790 if (!getDerived().AlwaysRebuild() &&
6791 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006792 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006793
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006794 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6795 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006796 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006797 E->getLocEnd());
6798}
6799
6800template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006801ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006802TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6803 if (E->isTypeOperand()) {
6804 TypeSourceInfo *TInfo
6805 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6806 if (!TInfo)
6807 return ExprError();
6808
6809 if (!getDerived().AlwaysRebuild() &&
6810 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006811 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006812
Douglas Gregor3c52a212011-03-06 17:40:41 +00006813 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006814 E->getLocStart(),
6815 TInfo,
6816 E->getLocEnd());
6817 }
6818
6819 // We don't know whether the expression is potentially evaluated until
6820 // after we perform semantic analysis, so the expression is potentially
6821 // potentially evaluated.
6822 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6823
6824 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6825 if (SubExpr.isInvalid())
6826 return ExprError();
6827
6828 if (!getDerived().AlwaysRebuild() &&
6829 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006830 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006831
6832 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6833 E->getLocStart(),
6834 SubExpr.get(),
6835 E->getLocEnd());
6836}
6837
6838template<typename Derived>
6839ExprResult
John McCall454feb92009-12-08 09:21:05 +00006840TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006841 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006842}
Mike Stump1eb44332009-09-09 15:08:12 +00006843
Douglas Gregorb98b1992009-08-11 05:31:07 +00006844template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006845ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006846TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006847 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006848 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006849}
Mike Stump1eb44332009-09-09 15:08:12 +00006850
Douglas Gregorb98b1992009-08-11 05:31:07 +00006851template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006852ExprResult
John McCall454feb92009-12-08 09:21:05 +00006853TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006854 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00006855 QualType T;
6856 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6857 T = MD->getThisType(getSema().Context);
6858 else
6859 T = getSema().Context.getPointerType(
6860 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00006861
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006862 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006863 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006864
Douglas Gregor828a1972010-01-07 23:12:05 +00006865 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006866}
Mike Stump1eb44332009-09-09 15:08:12 +00006867
Douglas Gregorb98b1992009-08-11 05:31:07 +00006868template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006869ExprResult
John McCall454feb92009-12-08 09:21:05 +00006870TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006871 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006872 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006873 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006874
Douglas Gregorb98b1992009-08-11 05:31:07 +00006875 if (!getDerived().AlwaysRebuild() &&
6876 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006877 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006878
Douglas Gregorbca01b42011-07-06 22:04:06 +00006879 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6880 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006881}
Mike Stump1eb44332009-09-09 15:08:12 +00006882
Douglas Gregorb98b1992009-08-11 05:31:07 +00006883template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006884ExprResult
John McCall454feb92009-12-08 09:21:05 +00006885TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006886 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006887 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6888 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006889 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006890 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006891
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006892 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006893 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006894 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006895
Douglas Gregor036aed12009-12-23 23:03:06 +00006896 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006897}
Mike Stump1eb44332009-09-09 15:08:12 +00006898
Douglas Gregorb98b1992009-08-11 05:31:07 +00006899template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006900ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006901TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6902 CXXScalarValueInitExpr *E) {
6903 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6904 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006905 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006906
Douglas Gregorb98b1992009-08-11 05:31:07 +00006907 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006908 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006909 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006910
Douglas Gregorab6677e2010-09-08 00:15:04 +00006911 return getDerived().RebuildCXXScalarValueInitExpr(T,
6912 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006913 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006914}
Mike Stump1eb44332009-09-09 15:08:12 +00006915
Douglas Gregorb98b1992009-08-11 05:31:07 +00006916template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006917ExprResult
John McCall454feb92009-12-08 09:21:05 +00006918TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006919 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006920 TypeSourceInfo *AllocTypeInfo
6921 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6922 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006923 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006924
Douglas Gregorb98b1992009-08-11 05:31:07 +00006925 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006926 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006927 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006928 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006929
Douglas Gregorb98b1992009-08-11 05:31:07 +00006930 // Transform the placement arguments (if any).
6931 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006932 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006933 if (getDerived().TransformExprs(E->getPlacementArgs(),
6934 E->getNumPlacementArgs(), true,
6935 PlacementArgs, &ArgumentChanged))
6936 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006937
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00006938 // Transform the constructor arguments (if any).
6939 // As an annoying corner case, we may have introduced an implicit value-
6940 // initialization expression when allocating a new array, which we implicitly
6941 // drop. It will be re-created during type checking.
John McCallca0408f2010-08-23 06:44:23 +00006942 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00006943 if (!(E->isArray() && E->getNumConstructorArgs() == 1 &&
6944 isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) &&
6945 TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00006946 ConstructorArgs, &ArgumentChanged))
6947 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006948
Douglas Gregor1af74512010-02-26 00:38:10 +00006949 // Transform constructor, new operator, and delete operator.
6950 CXXConstructorDecl *Constructor = 0;
6951 if (E->getConstructor()) {
6952 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006953 getDerived().TransformDecl(E->getLocStart(),
6954 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006955 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006956 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006957 }
6958
6959 FunctionDecl *OperatorNew = 0;
6960 if (E->getOperatorNew()) {
6961 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006962 getDerived().TransformDecl(E->getLocStart(),
6963 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006964 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006965 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006966 }
6967
6968 FunctionDecl *OperatorDelete = 0;
6969 if (E->getOperatorDelete()) {
6970 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006971 getDerived().TransformDecl(E->getLocStart(),
6972 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006973 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006974 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006975 }
Sean Huntc3021132010-05-05 15:23:54 +00006976
Douglas Gregorb98b1992009-08-11 05:31:07 +00006977 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006978 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006979 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006980 Constructor == E->getConstructor() &&
6981 OperatorNew == E->getOperatorNew() &&
6982 OperatorDelete == E->getOperatorDelete() &&
6983 !ArgumentChanged) {
6984 // Mark any declarations we need as referenced.
6985 // FIXME: instantiation-specific.
6986 if (Constructor)
6987 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6988 if (OperatorNew)
6989 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6990 if (OperatorDelete)
6991 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00006992
6993 if (E->isArray() && Constructor &&
6994 !E->getAllocatedType()->isDependentType()) {
6995 QualType ElementType
6996 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
6997 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
6998 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
6999 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
7000 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
7001 }
7002 }
7003 }
7004
John McCall3fa5cae2010-10-26 07:05:15 +00007005 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007006 }
Mike Stump1eb44332009-09-09 15:08:12 +00007007
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007008 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007009 if (!ArraySize.get()) {
7010 // If no array size was specified, but the new expression was
7011 // instantiated with an array type (e.g., "new T" where T is
7012 // instantiated with "int[4]"), extract the outer bound from the
7013 // array type as our array size. We do this with constant and
7014 // dependently-sized array types.
7015 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7016 if (!ArrayT) {
7017 // Do nothing
7018 } else if (const ConstantArrayType *ConsArrayT
7019 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007020 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007021 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7022 ConsArrayT->getSize(),
7023 SemaRef.Context.getSizeType(),
7024 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007025 AllocType = ConsArrayT->getElementType();
7026 } else if (const DependentSizedArrayType *DepArrayT
7027 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7028 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007029 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007030 AllocType = DepArrayT->getElementType();
7031 }
7032 }
7033 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007034
Douglas Gregorb98b1992009-08-11 05:31:07 +00007035 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7036 E->isGlobalNew(),
7037 /*FIXME:*/E->getLocStart(),
7038 move_arg(PlacementArgs),
7039 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007040 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007041 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007042 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007043 ArraySize.get(),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007044 E->getConstructorLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007045 move_arg(ConstructorArgs),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007046 E->getConstructorRParen());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007047}
Mike Stump1eb44332009-09-09 15:08:12 +00007048
Douglas Gregorb98b1992009-08-11 05:31:07 +00007049template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007050ExprResult
John McCall454feb92009-12-08 09:21:05 +00007051TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007052 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007053 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007054 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007055
Douglas Gregor1af74512010-02-26 00:38:10 +00007056 // Transform the delete operator, if known.
7057 FunctionDecl *OperatorDelete = 0;
7058 if (E->getOperatorDelete()) {
7059 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007060 getDerived().TransformDecl(E->getLocStart(),
7061 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007062 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007063 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007064 }
Sean Huntc3021132010-05-05 15:23:54 +00007065
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007067 Operand.get() == E->getArgument() &&
7068 OperatorDelete == E->getOperatorDelete()) {
7069 // Mark any declarations we need as referenced.
7070 // FIXME: instantiation-specific.
7071 if (OperatorDelete)
7072 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007073
7074 if (!E->getArgument()->isTypeDependent()) {
7075 QualType Destroyed = SemaRef.Context.getBaseElementType(
7076 E->getDestroyedType());
7077 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7078 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7079 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
7080 SemaRef.LookupDestructor(Record));
7081 }
7082 }
7083
John McCall3fa5cae2010-10-26 07:05:15 +00007084 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007085 }
Mike Stump1eb44332009-09-09 15:08:12 +00007086
Douglas Gregorb98b1992009-08-11 05:31:07 +00007087 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7088 E->isGlobalDelete(),
7089 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007090 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007091}
Mike Stump1eb44332009-09-09 15:08:12 +00007092
Douglas Gregorb98b1992009-08-11 05:31:07 +00007093template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007094ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007095TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007096 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007097 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007098 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007099 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007100
John McCallb3d87482010-08-24 05:47:05 +00007101 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007102 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007103 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007104 E->getOperatorLoc(),
7105 E->isArrow()? tok::arrow : tok::period,
7106 ObjectTypePtr,
7107 MayBePseudoDestructor);
7108 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007109 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007110
John McCallb3d87482010-08-24 05:47:05 +00007111 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007112 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7113 if (QualifierLoc) {
7114 QualifierLoc
7115 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7116 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007117 return ExprError();
7118 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007119 CXXScopeSpec SS;
7120 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007121
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007122 PseudoDestructorTypeStorage Destroyed;
7123 if (E->getDestroyedTypeInfo()) {
7124 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007125 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007126 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007127 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007128 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007129 Destroyed = DestroyedTypeInfo;
7130 } else if (ObjectType->isDependentType()) {
7131 // We aren't likely to be able to resolve the identifier down to a type
7132 // now anyway, so just retain the identifier.
7133 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7134 E->getDestroyedTypeLoc());
7135 } else {
7136 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007137 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007138 *E->getDestroyedTypeIdentifier(),
7139 E->getDestroyedTypeLoc(),
7140 /*Scope=*/0,
7141 SS, ObjectTypePtr,
7142 false);
7143 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007144 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007145
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007146 Destroyed
7147 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7148 E->getDestroyedTypeLoc());
7149 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007150
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007151 TypeSourceInfo *ScopeTypeInfo = 0;
7152 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007153 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007154 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007155 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007156 }
Sean Huntc3021132010-05-05 15:23:54 +00007157
John McCall9ae2f072010-08-23 23:25:46 +00007158 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007159 E->getOperatorLoc(),
7160 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007161 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007162 ScopeTypeInfo,
7163 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007164 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007165 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007166}
Mike Stump1eb44332009-09-09 15:08:12 +00007167
Douglas Gregora71d8192009-09-04 17:36:40 +00007168template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007169ExprResult
John McCallba135432009-11-21 08:51:07 +00007170TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007171 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007172 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7173 Sema::LookupOrdinaryName);
7174
7175 // Transform all the decls.
7176 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7177 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007178 NamedDecl *InstD = static_cast<NamedDecl*>(
7179 getDerived().TransformDecl(Old->getNameLoc(),
7180 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007181 if (!InstD) {
7182 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7183 // This can happen because of dependent hiding.
7184 if (isa<UsingShadowDecl>(*I))
7185 continue;
7186 else
John McCallf312b1e2010-08-26 23:41:50 +00007187 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007188 }
John McCallf7a1a742009-11-24 19:00:30 +00007189
7190 // Expand using declarations.
7191 if (isa<UsingDecl>(InstD)) {
7192 UsingDecl *UD = cast<UsingDecl>(InstD);
7193 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7194 E = UD->shadow_end(); I != E; ++I)
7195 R.addDecl(*I);
7196 continue;
7197 }
7198
7199 R.addDecl(InstD);
7200 }
7201
7202 // Resolve a kind, but don't do any further analysis. If it's
7203 // ambiguous, the callee needs to deal with it.
7204 R.resolveKind();
7205
7206 // Rebuild the nested-name qualifier, if present.
7207 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007208 if (Old->getQualifierLoc()) {
7209 NestedNameSpecifierLoc QualifierLoc
7210 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7211 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007212 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007213
Douglas Gregor4c9be892011-02-28 20:01:57 +00007214 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007215 }
7216
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007217 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007218 CXXRecordDecl *NamingClass
7219 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7220 Old->getNameLoc(),
7221 Old->getNamingClass()));
7222 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007223 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007224
Douglas Gregor66c45152010-04-27 16:10:10 +00007225 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007226 }
7227
7228 // If we have no template arguments, it's a normal declaration name.
7229 if (!Old->hasExplicitTemplateArgs())
7230 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7231
7232 // If we have template arguments, rebuild them, then rebuild the
7233 // templateid expression.
7234 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007235 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7236 Old->getNumTemplateArgs(),
7237 TransArgs))
7238 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007239
7240 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7241 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007242}
Mike Stump1eb44332009-09-09 15:08:12 +00007243
Douglas Gregorb98b1992009-08-11 05:31:07 +00007244template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007245ExprResult
John McCall454feb92009-12-08 09:21:05 +00007246TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007247 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7248 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007249 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007250
Douglas Gregorb98b1992009-08-11 05:31:07 +00007251 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007252 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007253 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007254
Mike Stump1eb44332009-09-09 15:08:12 +00007255 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007256 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007257 T,
7258 E->getLocEnd());
7259}
Mike Stump1eb44332009-09-09 15:08:12 +00007260
Douglas Gregorb98b1992009-08-11 05:31:07 +00007261template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007262ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007263TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7264 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7265 if (!LhsT)
7266 return ExprError();
7267
7268 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7269 if (!RhsT)
7270 return ExprError();
7271
7272 if (!getDerived().AlwaysRebuild() &&
7273 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7274 return SemaRef.Owned(E);
7275
7276 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7277 E->getLocStart(),
7278 LhsT, RhsT,
7279 E->getLocEnd());
7280}
7281
7282template<typename Derived>
7283ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007284TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7285 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7286 if (!T)
7287 return ExprError();
7288
7289 if (!getDerived().AlwaysRebuild() &&
7290 T == E->getQueriedTypeSourceInfo())
7291 return SemaRef.Owned(E);
7292
7293 ExprResult SubExpr;
7294 {
7295 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7296 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7297 if (SubExpr.isInvalid())
7298 return ExprError();
7299
7300 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7301 return SemaRef.Owned(E);
7302 }
7303
7304 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7305 E->getLocStart(),
7306 T,
7307 SubExpr.get(),
7308 E->getLocEnd());
7309}
7310
7311template<typename Derived>
7312ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007313TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7314 ExprResult SubExpr;
7315 {
7316 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7317 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7318 if (SubExpr.isInvalid())
7319 return ExprError();
7320
7321 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7322 return SemaRef.Owned(E);
7323 }
7324
7325 return getDerived().RebuildExpressionTrait(
7326 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7327}
7328
7329template<typename Derived>
7330ExprResult
John McCall865d4472009-11-19 22:55:06 +00007331TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007332 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007333 NestedNameSpecifierLoc QualifierLoc
7334 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7335 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007336 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007337
John McCall43fed0d2010-11-12 08:19:04 +00007338 // TODO: If this is a conversion-function-id, verify that the
7339 // destination type name (if present) resolves the same way after
7340 // instantiation as it did in the local scope.
7341
Abramo Bagnara25777432010-08-11 22:01:17 +00007342 DeclarationNameInfo NameInfo
7343 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7344 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007345 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007346
John McCallf7a1a742009-11-24 19:00:30 +00007347 if (!E->hasExplicitTemplateArgs()) {
7348 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007349 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007350 // Note: it is sufficient to compare the Name component of NameInfo:
7351 // if name has not changed, DNLoc has not changed either.
7352 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007353 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007354
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007355 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007356 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007357 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007358 }
John McCalld5532b62009-11-23 01:53:49 +00007359
7360 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007361 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7362 E->getNumTemplateArgs(),
7363 TransArgs))
7364 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007365
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007366 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007367 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007368 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007369}
7370
7371template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007372ExprResult
John McCall454feb92009-12-08 09:21:05 +00007373TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007374 // CXXConstructExprs are always implicit, so when we have a
7375 // 1-argument construction we just transform that argument.
7376 if (E->getNumArgs() == 1 ||
7377 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7378 return getDerived().TransformExpr(E->getArg(0));
7379
Douglas Gregorb98b1992009-08-11 05:31:07 +00007380 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7381
7382 QualType T = getDerived().TransformType(E->getType());
7383 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007384 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007385
7386 CXXConstructorDecl *Constructor
7387 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007388 getDerived().TransformDecl(E->getLocStart(),
7389 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007390 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007391 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007392
Douglas Gregorb98b1992009-08-11 05:31:07 +00007393 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007394 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007395 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7396 &ArgumentChanged))
7397 return ExprError();
7398
Douglas Gregorb98b1992009-08-11 05:31:07 +00007399 if (!getDerived().AlwaysRebuild() &&
7400 T == E->getType() &&
7401 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007402 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007403 // Mark the constructor as referenced.
7404 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00007405 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007406 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007407 }
Mike Stump1eb44332009-09-09 15:08:12 +00007408
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007409 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7410 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007411 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007412 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007413 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007414 E->getConstructionKind(),
7415 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007416}
Mike Stump1eb44332009-09-09 15:08:12 +00007417
Douglas Gregorb98b1992009-08-11 05:31:07 +00007418/// \brief Transform a C++ temporary-binding expression.
7419///
Douglas Gregor51326552009-12-24 18:51:59 +00007420/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7421/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007422template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007423ExprResult
John McCall454feb92009-12-08 09:21:05 +00007424TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007425 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007426}
Mike Stump1eb44332009-09-09 15:08:12 +00007427
John McCall4765fa02010-12-06 08:20:24 +00007428/// \brief Transform a C++ expression that contains cleanups that should
7429/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007430///
John McCall4765fa02010-12-06 08:20:24 +00007431/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007432/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007433template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007434ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007435TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007436 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007437}
Mike Stump1eb44332009-09-09 15:08:12 +00007438
Douglas Gregorb98b1992009-08-11 05:31:07 +00007439template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007440ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007441TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007442 CXXTemporaryObjectExpr *E) {
7443 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7444 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007445 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007446
Douglas Gregorb98b1992009-08-11 05:31:07 +00007447 CXXConstructorDecl *Constructor
7448 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007449 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007450 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007451 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007452 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007453
Douglas Gregorb98b1992009-08-11 05:31:07 +00007454 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007455 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007456 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007457 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7458 &ArgumentChanged))
7459 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007460
Douglas Gregorb98b1992009-08-11 05:31:07 +00007461 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007462 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007463 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007464 !ArgumentChanged) {
7465 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00007466 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007467 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007468 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007469
7470 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7471 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007472 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007473 E->getLocEnd());
7474}
Mike Stump1eb44332009-09-09 15:08:12 +00007475
Douglas Gregorb98b1992009-08-11 05:31:07 +00007476template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007477ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007478TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007479 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007480 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7481 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007482 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007483
Douglas Gregorb98b1992009-08-11 05:31:07 +00007484 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007485 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007486 Args.reserve(E->arg_size());
7487 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7488 &ArgumentChanged))
7489 return ExprError();
7490
Douglas Gregorb98b1992009-08-11 05:31:07 +00007491 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007492 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007493 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007494 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007495
Douglas Gregorb98b1992009-08-11 05:31:07 +00007496 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007497 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007498 E->getLParenLoc(),
7499 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007500 E->getRParenLoc());
7501}
Mike Stump1eb44332009-09-09 15:08:12 +00007502
Douglas Gregorb98b1992009-08-11 05:31:07 +00007503template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007504ExprResult
John McCall865d4472009-11-19 22:55:06 +00007505TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007506 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007507 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007508 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007509 Expr *OldBase;
7510 QualType BaseType;
7511 QualType ObjectType;
7512 if (!E->isImplicitAccess()) {
7513 OldBase = E->getBase();
7514 Base = getDerived().TransformExpr(OldBase);
7515 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007516 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007517
John McCallaa81e162009-12-01 22:10:20 +00007518 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007519 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007520 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007521 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007522 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007523 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007524 ObjectTy,
7525 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007526 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007527 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007528
John McCallb3d87482010-08-24 05:47:05 +00007529 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007530 BaseType = ((Expr*) Base.get())->getType();
7531 } else {
7532 OldBase = 0;
7533 BaseType = getDerived().TransformType(E->getBaseType());
7534 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7535 }
Mike Stump1eb44332009-09-09 15:08:12 +00007536
Douglas Gregor6cd21982009-10-20 05:58:46 +00007537 // Transform the first part of the nested-name-specifier that qualifies
7538 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007539 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007540 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007541 E->getFirstQualifierFoundInScope(),
7542 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007543
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007544 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007545 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007546 QualifierLoc
7547 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7548 ObjectType,
7549 FirstQualifierInScope);
7550 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007551 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007552 }
Mike Stump1eb44332009-09-09 15:08:12 +00007553
John McCall43fed0d2010-11-12 08:19:04 +00007554 // TODO: If this is a conversion-function-id, verify that the
7555 // destination type name (if present) resolves the same way after
7556 // instantiation as it did in the local scope.
7557
Abramo Bagnara25777432010-08-11 22:01:17 +00007558 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007559 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007560 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007561 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007562
John McCallaa81e162009-12-01 22:10:20 +00007563 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007564 // This is a reference to a member without an explicitly-specified
7565 // template argument list. Optimize for this common case.
7566 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007567 Base.get() == OldBase &&
7568 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007569 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007570 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007571 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007572 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007573
John McCall9ae2f072010-08-23 23:25:46 +00007574 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007575 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007576 E->isArrow(),
7577 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007578 QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00007579 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007580 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007581 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007582 }
7583
John McCalld5532b62009-11-23 01:53:49 +00007584 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007585 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7586 E->getNumTemplateArgs(),
7587 TransArgs))
7588 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007589
John McCall9ae2f072010-08-23 23:25:46 +00007590 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007591 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007592 E->isArrow(),
7593 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007594 QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007595 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007596 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007597 &TransArgs);
7598}
7599
7600template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007601ExprResult
John McCall454feb92009-12-08 09:21:05 +00007602TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007603 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007604 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007605 QualType BaseType;
7606 if (!Old->isImplicitAccess()) {
7607 Base = getDerived().TransformExpr(Old->getBase());
7608 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007609 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007610 BaseType = ((Expr*) Base.get())->getType();
7611 } else {
7612 BaseType = getDerived().TransformType(Old->getBaseType());
7613 }
John McCall129e2df2009-11-30 22:42:35 +00007614
Douglas Gregor4c9be892011-02-28 20:01:57 +00007615 NestedNameSpecifierLoc QualifierLoc;
7616 if (Old->getQualifierLoc()) {
7617 QualifierLoc
7618 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7619 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007620 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007621 }
7622
Abramo Bagnara25777432010-08-11 22:01:17 +00007623 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007624 Sema::LookupOrdinaryName);
7625
7626 // Transform all the decls.
7627 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7628 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007629 NamedDecl *InstD = static_cast<NamedDecl*>(
7630 getDerived().TransformDecl(Old->getMemberLoc(),
7631 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007632 if (!InstD) {
7633 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7634 // This can happen because of dependent hiding.
7635 if (isa<UsingShadowDecl>(*I))
7636 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007637 else {
7638 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007639 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007640 }
John McCall9f54ad42009-12-10 09:41:52 +00007641 }
John McCall129e2df2009-11-30 22:42:35 +00007642
7643 // Expand using declarations.
7644 if (isa<UsingDecl>(InstD)) {
7645 UsingDecl *UD = cast<UsingDecl>(InstD);
7646 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7647 E = UD->shadow_end(); I != E; ++I)
7648 R.addDecl(*I);
7649 continue;
7650 }
7651
7652 R.addDecl(InstD);
7653 }
7654
7655 R.resolveKind();
7656
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007657 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007658 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007659 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007660 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007661 Old->getMemberLoc(),
7662 Old->getNamingClass()));
7663 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007664 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007665
Douglas Gregor66c45152010-04-27 16:10:10 +00007666 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007667 }
Sean Huntc3021132010-05-05 15:23:54 +00007668
John McCall129e2df2009-11-30 22:42:35 +00007669 TemplateArgumentListInfo TransArgs;
7670 if (Old->hasExplicitTemplateArgs()) {
7671 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7672 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007673 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7674 Old->getNumTemplateArgs(),
7675 TransArgs))
7676 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007677 }
John McCallc2233c52010-01-15 08:34:02 +00007678
7679 // FIXME: to do this check properly, we will need to preserve the
7680 // first-qualifier-in-scope here, just in case we had a dependent
7681 // base (and therefore couldn't do the check) and a
7682 // nested-name-qualifier (and therefore could do the lookup).
7683 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007684
John McCall9ae2f072010-08-23 23:25:46 +00007685 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007686 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007687 Old->getOperatorLoc(),
7688 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007689 QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00007690 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007691 R,
7692 (Old->hasExplicitTemplateArgs()
7693 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007694}
7695
7696template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007697ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007698TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00007699 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00007700 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7701 if (SubExpr.isInvalid())
7702 return ExprError();
7703
7704 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007705 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007706
7707 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7708}
7709
7710template<typename Derived>
7711ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007712TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007713 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7714 if (Pattern.isInvalid())
7715 return ExprError();
7716
7717 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7718 return SemaRef.Owned(E);
7719
Douglas Gregor67fd1252011-01-14 21:20:45 +00007720 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7721 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007722}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007723
7724template<typename Derived>
7725ExprResult
7726TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7727 // If E is not value-dependent, then nothing will change when we transform it.
7728 // Note: This is an instantiation-centric view.
7729 if (!E->isValueDependent())
7730 return SemaRef.Owned(E);
7731
7732 // Note: None of the implementations of TryExpandParameterPacks can ever
7733 // produce a diagnostic when given only a single unexpanded parameter pack,
7734 // so
7735 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7736 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007737 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007738 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007739 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00007740 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00007741 ShouldExpand, RetainExpansion,
7742 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007743 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007744
Douglas Gregor089e8932011-10-10 18:59:29 +00007745 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007746 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00007747
7748 NamedDecl *Pack = E->getPack();
7749 if (!ShouldExpand) {
7750 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
7751 Pack));
7752 if (!Pack)
7753 return ExprError();
7754 }
7755
Douglas Gregoree8aff02011-01-04 17:33:58 +00007756
7757 // We now know the length of the parameter pack, so build a new expression
7758 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00007759 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00007760 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00007761 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007762}
7763
Douglas Gregorbe230c32011-01-03 17:17:50 +00007764template<typename Derived>
7765ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007766TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7767 SubstNonTypeTemplateParmPackExpr *E) {
7768 // Default behavior is to do nothing with this transformation.
7769 return SemaRef.Owned(E);
7770}
7771
7772template<typename Derived>
7773ExprResult
John McCall91a57552011-07-15 05:09:51 +00007774TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7775 SubstNonTypeTemplateParmExpr *E) {
7776 // Default behavior is to do nothing with this transformation.
7777 return SemaRef.Owned(E);
7778}
7779
7780template<typename Derived>
7781ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00007782TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7783 MaterializeTemporaryExpr *E) {
7784 return getDerived().TransformExpr(E->GetTemporaryExpr());
7785}
7786
7787template<typename Derived>
7788ExprResult
John McCall454feb92009-12-08 09:21:05 +00007789TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007790 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007791}
7792
Mike Stump1eb44332009-09-09 15:08:12 +00007793template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007794ExprResult
John McCall454feb92009-12-08 09:21:05 +00007795TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007796 TypeSourceInfo *EncodedTypeInfo
7797 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7798 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007799 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007800
Douglas Gregorb98b1992009-08-11 05:31:07 +00007801 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007802 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007803 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007804
7805 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007806 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007807 E->getRParenLoc());
7808}
Mike Stump1eb44332009-09-09 15:08:12 +00007809
Douglas Gregorb98b1992009-08-11 05:31:07 +00007810template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00007811ExprResult TreeTransform<Derived>::
7812TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7813 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7814 if (result.isInvalid()) return ExprError();
7815 Expr *subExpr = result.take();
7816
7817 if (!getDerived().AlwaysRebuild() &&
7818 subExpr == E->getSubExpr())
7819 return SemaRef.Owned(E);
7820
7821 return SemaRef.Owned(new(SemaRef.Context)
7822 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7823}
7824
7825template<typename Derived>
7826ExprResult TreeTransform<Derived>::
7827TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7828 TypeSourceInfo *TSInfo
7829 = getDerived().TransformType(E->getTypeInfoAsWritten());
7830 if (!TSInfo)
7831 return ExprError();
7832
7833 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7834 if (Result.isInvalid())
7835 return ExprError();
7836
7837 if (!getDerived().AlwaysRebuild() &&
7838 TSInfo == E->getTypeInfoAsWritten() &&
7839 Result.get() == E->getSubExpr())
7840 return SemaRef.Owned(E);
7841
7842 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7843 E->getBridgeKeywordLoc(), TSInfo,
7844 Result.get());
7845}
7846
7847template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007848ExprResult
John McCall454feb92009-12-08 09:21:05 +00007849TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007850 // Transform arguments.
7851 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007852 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007853 Args.reserve(E->getNumArgs());
7854 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7855 &ArgChanged))
7856 return ExprError();
7857
Douglas Gregor92e986e2010-04-22 16:44:27 +00007858 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7859 // Class message: transform the receiver type.
7860 TypeSourceInfo *ReceiverTypeInfo
7861 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7862 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007863 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007864
Douglas Gregor92e986e2010-04-22 16:44:27 +00007865 // If nothing changed, just retain the existing message send.
7866 if (!getDerived().AlwaysRebuild() &&
7867 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007868 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007869
7870 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007871 SmallVector<SourceLocation, 16> SelLocs;
7872 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007873 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7874 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007875 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00007876 E->getMethodDecl(),
7877 E->getLeftLoc(),
7878 move_arg(Args),
7879 E->getRightLoc());
7880 }
7881
7882 // Instance message: transform the receiver
7883 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7884 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007885 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007886 = getDerived().TransformExpr(E->getInstanceReceiver());
7887 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007888 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007889
7890 // If nothing changed, just retain the existing message send.
7891 if (!getDerived().AlwaysRebuild() &&
7892 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007893 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007894
Douglas Gregor92e986e2010-04-22 16:44:27 +00007895 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007896 SmallVector<SourceLocation, 16> SelLocs;
7897 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00007898 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007899 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00007900 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00007901 E->getMethodDecl(),
7902 E->getLeftLoc(),
7903 move_arg(Args),
7904 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007905}
7906
Mike Stump1eb44332009-09-09 15:08:12 +00007907template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007908ExprResult
John McCall454feb92009-12-08 09:21:05 +00007909TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007910 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007911}
7912
Mike Stump1eb44332009-09-09 15:08:12 +00007913template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007914ExprResult
John McCall454feb92009-12-08 09:21:05 +00007915TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007916 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007917}
7918
Mike Stump1eb44332009-09-09 15:08:12 +00007919template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007920ExprResult
John McCall454feb92009-12-08 09:21:05 +00007921TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007922 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007923 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007924 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007925 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007926
7927 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007928
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007929 // If nothing changed, just retain the existing expression.
7930 if (!getDerived().AlwaysRebuild() &&
7931 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007932 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007933
John McCall9ae2f072010-08-23 23:25:46 +00007934 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007935 E->getLocation(),
7936 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007937}
7938
Mike Stump1eb44332009-09-09 15:08:12 +00007939template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007940ExprResult
John McCall454feb92009-12-08 09:21:05 +00007941TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00007942 // 'super' and types never change. Property never changes. Just
7943 // retain the existing expression.
7944 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00007945 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00007946
Douglas Gregore3303542010-04-26 20:47:02 +00007947 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007948 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00007949 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007950 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007951
Douglas Gregore3303542010-04-26 20:47:02 +00007952 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007953
Douglas Gregore3303542010-04-26 20:47:02 +00007954 // If nothing changed, just retain the existing expression.
7955 if (!getDerived().AlwaysRebuild() &&
7956 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007957 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007958
John McCall12f78a62010-12-02 01:19:52 +00007959 if (E->isExplicitProperty())
7960 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7961 E->getExplicitProperty(),
7962 E->getLocation());
7963
7964 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7965 E->getType(),
7966 E->getImplicitPropertyGetter(),
7967 E->getImplicitPropertySetter(),
7968 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007969}
7970
Mike Stump1eb44332009-09-09 15:08:12 +00007971template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007972ExprResult
John McCall454feb92009-12-08 09:21:05 +00007973TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007974 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007975 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007976 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007977 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007978
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007979 // If nothing changed, just retain the existing expression.
7980 if (!getDerived().AlwaysRebuild() &&
7981 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007982 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007983
John McCall9ae2f072010-08-23 23:25:46 +00007984 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007985 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007986}
7987
Mike Stump1eb44332009-09-09 15:08:12 +00007988template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007989ExprResult
John McCall454feb92009-12-08 09:21:05 +00007990TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007991 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007992 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007993 SubExprs.reserve(E->getNumSubExprs());
7994 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7995 SubExprs, &ArgumentChanged))
7996 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007997
Douglas Gregorb98b1992009-08-11 05:31:07 +00007998 if (!getDerived().AlwaysRebuild() &&
7999 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008000 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008001
Douglas Gregorb98b1992009-08-11 05:31:07 +00008002 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8003 move_arg(SubExprs),
8004 E->getRParenLoc());
8005}
8006
Mike Stump1eb44332009-09-09 15:08:12 +00008007template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008008ExprResult
John McCall454feb92009-12-08 09:21:05 +00008009TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008010 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008011
John McCallc6ac9c32011-02-04 18:33:18 +00008012 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8013 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8014
8015 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008016 // We built a new blockScopeInfo in call to ActOnBlockStart
8017 // in above, CapturesCXXThis need be set here from the block
8018 // expression.
8019 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
8020
Chris Lattner686775d2011-07-20 06:58:45 +00008021 SmallVector<ParmVarDecl*, 4> params;
8022 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008023
8024 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008025 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8026 oldBlock->param_begin(),
8027 oldBlock->param_size(),
8028 0, paramTypes, &params))
Douglas Gregora779d9c2011-01-19 21:32:01 +00008029 return true;
John McCallc6ac9c32011-02-04 18:33:18 +00008030
8031 const FunctionType *exprFunctionType = E->getFunctionType();
8032 QualType exprResultType = exprFunctionType->getResultType();
8033 if (!exprResultType.isNull()) {
8034 if (!exprResultType->isDependentType())
8035 blockScope->ReturnType = exprResultType;
8036 else if (exprResultType != getSema().Context.DependentTy)
8037 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008038 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008039
8040 // If the return type has not been determined yet, leave it as a dependent
8041 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00008042 if (blockScope->ReturnType.isNull())
8043 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00008044
8045 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00008046 if (blockScope->ReturnType->isObjCObjectType()) {
8047 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008048 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00008049 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00008050 return ExprError();
8051 }
John McCall711c52b2011-01-05 12:14:39 +00008052
John McCallc6ac9c32011-02-04 18:33:18 +00008053 QualType functionType = getDerived().RebuildFunctionProtoType(
8054 blockScope->ReturnType,
8055 paramTypes.data(),
8056 paramTypes.size(),
8057 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00008058 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008059 exprFunctionType->getExtInfo());
8060 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008061
8062 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008063 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008064 blockScope->TheDecl->setParams(params);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008065
8066 // If the return type wasn't explicitly set, it will have been marked as a
8067 // dependent type (DependentTy); clear out the return type setting so
8068 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00008069 if (blockScope->ReturnType == getSema().Context.DependentTy)
8070 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00008071
John McCall711c52b2011-01-05 12:14:39 +00008072 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008073 StmtResult body = getDerived().TransformStmt(E->getBody());
8074 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00008075 return ExprError();
8076
John McCallc6ac9c32011-02-04 18:33:18 +00008077#ifndef NDEBUG
8078 // In builds with assertions, make sure that we captured everything we
8079 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008080 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8081 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8082 e = oldBlock->capture_end(); i != e; ++i) {
8083 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008084
Douglas Gregorfc921372011-05-20 15:32:55 +00008085 // Ignore parameter packs.
8086 if (isa<ParmVarDecl>(oldCapture) &&
8087 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8088 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008089
Douglas Gregorfc921372011-05-20 15:32:55 +00008090 VarDecl *newCapture =
8091 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8092 oldCapture));
8093 assert(blockScope->CaptureMap.count(newCapture));
8094 }
John McCallc6ac9c32011-02-04 18:33:18 +00008095 }
8096#endif
8097
8098 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8099 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008100}
8101
Mike Stump1eb44332009-09-09 15:08:12 +00008102template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008103ExprResult
John McCall454feb92009-12-08 09:21:05 +00008104TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008105 ValueDecl *ND
8106 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8107 E->getDecl()));
8108 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00008109 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00008110
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008111 if (!getDerived().AlwaysRebuild() &&
8112 ND == E->getDecl()) {
8113 // Mark it referenced in the new context regardless.
8114 // FIXME: this is a bit instantiation-specific.
8115 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8116
John McCall3fa5cae2010-10-26 07:05:15 +00008117 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008118 }
8119
Abramo Bagnara25777432010-08-11 22:01:17 +00008120 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00008121 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00008122 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008123}
Mike Stump1eb44332009-09-09 15:08:12 +00008124
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008125template<typename Derived>
8126ExprResult
8127TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008128 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008129}
Eli Friedman276b0612011-10-11 02:20:01 +00008130
8131template<typename Derived>
8132ExprResult
8133TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008134 QualType RetTy = getDerived().TransformType(E->getType());
8135 bool ArgumentChanged = false;
8136 ASTOwningVector<Expr*> SubExprs(SemaRef);
8137 SubExprs.reserve(E->getNumSubExprs());
8138 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8139 SubExprs, &ArgumentChanged))
8140 return ExprError();
8141
8142 if (!getDerived().AlwaysRebuild() &&
8143 !ArgumentChanged)
8144 return SemaRef.Owned(E);
8145
8146 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8147 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008148}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008149
Douglas Gregorb98b1992009-08-11 05:31:07 +00008150//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008151// Type reconstruction
8152//===----------------------------------------------------------------------===//
8153
Mike Stump1eb44332009-09-09 15:08:12 +00008154template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008155QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8156 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008157 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008158 getDerived().getBaseEntity());
8159}
8160
Mike Stump1eb44332009-09-09 15:08:12 +00008161template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008162QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8163 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008164 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008165 getDerived().getBaseEntity());
8166}
8167
Mike Stump1eb44332009-09-09 15:08:12 +00008168template<typename Derived>
8169QualType
John McCall85737a72009-10-30 00:06:24 +00008170TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8171 bool WrittenAsLValue,
8172 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008173 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008174 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008175}
8176
8177template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008178QualType
John McCall85737a72009-10-30 00:06:24 +00008179TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8180 QualType ClassType,
8181 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008182 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008183 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008184}
8185
8186template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008187QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008188TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8189 ArrayType::ArraySizeModifier SizeMod,
8190 const llvm::APInt *Size,
8191 Expr *SizeExpr,
8192 unsigned IndexTypeQuals,
8193 SourceRange BracketsRange) {
8194 if (SizeExpr || !Size)
8195 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8196 IndexTypeQuals, BracketsRange,
8197 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008198
8199 QualType Types[] = {
8200 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8201 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8202 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008203 };
8204 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8205 QualType SizeType;
8206 for (unsigned I = 0; I != NumTypes; ++I)
8207 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8208 SizeType = Types[I];
8209 break;
8210 }
Mike Stump1eb44332009-09-09 15:08:12 +00008211
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008212 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8213 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00008214 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008215 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008216 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008217}
Mike Stump1eb44332009-09-09 15:08:12 +00008218
Douglas Gregor577f75a2009-08-04 16:50:30 +00008219template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008220QualType
8221TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008222 ArrayType::ArraySizeModifier SizeMod,
8223 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008224 unsigned IndexTypeQuals,
8225 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008226 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008227 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008228}
8229
8230template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008231QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008232TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008233 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008234 unsigned IndexTypeQuals,
8235 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008236 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008237 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008238}
Mike Stump1eb44332009-09-09 15:08:12 +00008239
Douglas Gregor577f75a2009-08-04 16:50:30 +00008240template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008241QualType
8242TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008243 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008244 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008245 unsigned IndexTypeQuals,
8246 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008247 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008248 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008249 IndexTypeQuals, BracketsRange);
8250}
8251
8252template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008253QualType
8254TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008255 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008256 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008257 unsigned IndexTypeQuals,
8258 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008259 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008260 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008261 IndexTypeQuals, BracketsRange);
8262}
8263
8264template<typename Derived>
8265QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008266 unsigned NumElements,
8267 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008268 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008269 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008270}
Mike Stump1eb44332009-09-09 15:08:12 +00008271
Douglas Gregor577f75a2009-08-04 16:50:30 +00008272template<typename Derived>
8273QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8274 unsigned NumElements,
8275 SourceLocation AttributeLoc) {
8276 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8277 NumElements, true);
8278 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008279 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8280 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008281 return SemaRef.BuildExtVectorType(ElementType, VectorSize, 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>
Mike Stump1eb44332009-09-09 15:08:12 +00008285QualType
8286TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008287 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008288 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008289 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008290}
Mike Stump1eb44332009-09-09 15:08:12 +00008291
Douglas Gregor577f75a2009-08-04 16:50:30 +00008292template<typename Derived>
8293QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008294 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008295 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008296 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00008297 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008298 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008299 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008300 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00008301 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008302 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008303 getDerived().getBaseEntity(),
8304 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008305}
Mike Stump1eb44332009-09-09 15:08:12 +00008306
Douglas Gregor577f75a2009-08-04 16:50:30 +00008307template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008308QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8309 return SemaRef.Context.getFunctionNoProtoType(T);
8310}
8311
8312template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008313QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8314 assert(D && "no decl found");
8315 if (D->isInvalidDecl()) return QualType();
8316
Douglas Gregor92e986e2010-04-22 16:44:27 +00008317 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008318 TypeDecl *Ty;
8319 if (isa<UsingDecl>(D)) {
8320 UsingDecl *Using = cast<UsingDecl>(D);
8321 assert(Using->isTypeName() &&
8322 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8323
8324 // A valid resolved using typename decl points to exactly one type decl.
8325 assert(++Using->shadow_begin() == Using->shadow_end());
8326 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008327
John McCalled976492009-12-04 22:46:56 +00008328 } else {
8329 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8330 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8331 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8332 }
8333
8334 return SemaRef.Context.getTypeDeclType(Ty);
8335}
8336
8337template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008338QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8339 SourceLocation Loc) {
8340 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008341}
8342
8343template<typename Derived>
8344QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8345 return SemaRef.Context.getTypeOfType(Underlying);
8346}
8347
8348template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008349QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8350 SourceLocation Loc) {
8351 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008352}
8353
8354template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008355QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8356 UnaryTransformType::UTTKind UKind,
8357 SourceLocation Loc) {
8358 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8359}
8360
8361template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008362QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008363 TemplateName Template,
8364 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008365 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008366 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008367}
Mike Stump1eb44332009-09-09 15:08:12 +00008368
Douglas Gregordcee1a12009-08-06 05:28:30 +00008369template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00008370QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8371 SourceLocation KWLoc) {
8372 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8373}
8374
8375template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008376TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008377TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008378 bool TemplateKW,
8379 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008380 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008381 Template);
8382}
8383
8384template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008385TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008386TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8387 const IdentifierInfo &Name,
8388 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008389 QualType ObjectType,
8390 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008391 UnqualifiedId TemplateName;
8392 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008393 Sema::TemplateTy Template;
8394 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008395 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008396 SS,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008397 TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008398 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008399 /*EnteringContext=*/false,
8400 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008401 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008402}
Mike Stump1eb44332009-09-09 15:08:12 +00008403
Douglas Gregorb98b1992009-08-11 05:31:07 +00008404template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008405TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008406TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008407 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008408 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008409 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008410 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008411 // FIXME: Bogus location information.
8412 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8413 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008414 Sema::TemplateTy Template;
8415 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008416 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008417 SS,
8418 Name,
John McCallb3d87482010-08-24 05:47:05 +00008419 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008420 /*EnteringContext=*/false,
8421 Template);
8422 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008423}
Sean Huntc3021132010-05-05 15:23:54 +00008424
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008425template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008426ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008427TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8428 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008429 Expr *OrigCallee,
8430 Expr *First,
8431 Expr *Second) {
8432 Expr *Callee = OrigCallee->IgnoreParenCasts();
8433 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008434
Douglas Gregorb98b1992009-08-11 05:31:07 +00008435 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008436 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008437 if (!First->getType()->isOverloadableType() &&
8438 !Second->getType()->isOverloadableType())
8439 return getSema().CreateBuiltinArraySubscriptExpr(First,
8440 Callee->getLocStart(),
8441 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008442 } else if (Op == OO_Arrow) {
8443 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008444 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8445 } else if (Second == 0 || isPostIncDec) {
8446 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008447 // The argument is not of overloadable type, so try to create a
8448 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008449 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008450 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008451
John McCall9ae2f072010-08-23 23:25:46 +00008452 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008453 }
8454 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008455 if (!First->getType()->isOverloadableType() &&
8456 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008457 // Neither of the arguments is an overloadable type, so try to
8458 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008459 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008460 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008461 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008462 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008463 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008464
Douglas Gregorb98b1992009-08-11 05:31:07 +00008465 return move(Result);
8466 }
8467 }
Mike Stump1eb44332009-09-09 15:08:12 +00008468
8469 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008470 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008471 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008472
John McCall9ae2f072010-08-23 23:25:46 +00008473 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008474 assert(ULE->requiresADL());
8475
8476 // FIXME: Do we have to check
8477 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008478 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008479 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008480 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008481 }
Mike Stump1eb44332009-09-09 15:08:12 +00008482
Douglas Gregorb98b1992009-08-11 05:31:07 +00008483 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008484 Expr *Args[2] = { First, Second };
8485 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008486
Douglas Gregorb98b1992009-08-11 05:31:07 +00008487 // Create the overloaded operator invocation for unary operators.
8488 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008489 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008490 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008491 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008492 }
Mike Stump1eb44332009-09-09 15:08:12 +00008493
Douglas Gregor5b8968c2011-07-15 16:25:15 +00008494 if (Op == OO_Subscript) {
8495 SourceLocation LBrace;
8496 SourceLocation RBrace;
8497
8498 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8499 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8500 LBrace = SourceLocation::getFromRawEncoding(
8501 NameLoc.CXXOperatorName.BeginOpNameLoc);
8502 RBrace = SourceLocation::getFromRawEncoding(
8503 NameLoc.CXXOperatorName.EndOpNameLoc);
8504 } else {
8505 LBrace = Callee->getLocStart();
8506 RBrace = OpLoc;
8507 }
8508
8509 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8510 First, Second);
8511 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00008512
Douglas Gregorb98b1992009-08-11 05:31:07 +00008513 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008514 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008515 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008516 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8517 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008518 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008519
Mike Stump1eb44332009-09-09 15:08:12 +00008520 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008521}
Mike Stump1eb44332009-09-09 15:08:12 +00008522
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008523template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008524ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008525TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008526 SourceLocation OperatorLoc,
8527 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008528 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008529 TypeSourceInfo *ScopeType,
8530 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008531 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008532 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008533 QualType BaseType = Base->getType();
8534 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008535 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008536 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008537 !BaseType->getAs<PointerType>()->getPointeeType()
8538 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008539 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008540 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008541 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008542 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008543 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008544 /*FIXME?*/true);
8545 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008546
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008547 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008548 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8549 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8550 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8551 NameInfo.setNamedTypeInfo(DestroyedType);
8552
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008553 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008554
John McCall9ae2f072010-08-23 23:25:46 +00008555 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008556 OperatorLoc, isArrow,
8557 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008558 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008559 /*TemplateArgs*/ 0);
8560}
8561
Douglas Gregor577f75a2009-08-04 16:50:30 +00008562} // end namespace clang
8563
8564#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H