blob: 8744f413a12563e455cf93e6aa67aa64ef94d860 [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,
Abramo Bagnarae4b92762012-01-27 09:46:47 +0000421 SourceLocation NameLoc,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000422 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 Gregord1bb4ae2012-01-25 16:15:54 +0000533 llvm::Optional<unsigned> NumExpansions,
534 bool ExpectParameterPack);
John McCall21ef0fa2010-03-11 09:03:00 +0000535
John McCall43fed0d2010-11-12 08:19:04 +0000536 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000537
John McCall60d7b3a2010-08-24 06:29:42 +0000538 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
539 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000540
Douglas Gregor43959a92009-08-20 07:17:43 +0000541#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000542 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000543#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000544 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000545#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000546#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000547
Douglas Gregor577f75a2009-08-04 16:50:30 +0000548 /// \brief Build a new pointer type given its pointee type.
549 ///
550 /// By default, performs semantic analysis when building the pointer type.
551 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000552 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000553
554 /// \brief Build a new block pointer type given its pointee type.
555 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000556 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000557 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000558 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000559
John McCall85737a72009-10-30 00:06:24 +0000560 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000561 ///
John McCall85737a72009-10-30 00:06:24 +0000562 /// By default, performs semantic analysis when building the
563 /// reference type. Subclasses may override this routine to provide
564 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000565 ///
John McCall85737a72009-10-30 00:06:24 +0000566 /// \param LValue whether the type was written with an lvalue sigil
567 /// or an rvalue sigil.
568 QualType RebuildReferenceType(QualType ReferentType,
569 bool LValue,
570 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000571
Douglas Gregor577f75a2009-08-04 16:50:30 +0000572 /// \brief Build a new member pointer type given the pointee type and the
573 /// class type it refers into.
574 ///
575 /// By default, performs semantic analysis when building the member pointer
576 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000577 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
578 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000579
Douglas Gregor577f75a2009-08-04 16:50:30 +0000580 /// \brief Build a new array type given the element type, size
581 /// modifier, size of the array (if known), size expression, and index type
582 /// qualifiers.
583 ///
584 /// By default, performs semantic analysis when building the array type.
585 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000586 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000587 QualType RebuildArrayType(QualType ElementType,
588 ArrayType::ArraySizeModifier SizeMod,
589 const llvm::APInt *Size,
590 Expr *SizeExpr,
591 unsigned IndexTypeQuals,
592 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000593
Douglas Gregor577f75a2009-08-04 16:50:30 +0000594 /// \brief Build a new constant array type given the element type, size
595 /// modifier, (known) size of the array, and index type qualifiers.
596 ///
597 /// By default, performs semantic analysis when building the array type.
598 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000599 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000600 ArrayType::ArraySizeModifier SizeMod,
601 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000602 unsigned IndexTypeQuals,
603 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000604
Douglas Gregor577f75a2009-08-04 16:50:30 +0000605 /// \brief Build a new incomplete array type given the element type, size
606 /// modifier, and index type qualifiers.
607 ///
608 /// By default, performs semantic analysis when building the array type.
609 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000610 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000611 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000612 unsigned IndexTypeQuals,
613 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000614
Mike Stump1eb44332009-09-09 15:08:12 +0000615 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000616 /// size modifier, size expression, and index type qualifiers.
617 ///
618 /// By default, performs semantic analysis when building the array type.
619 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000620 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000622 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000623 unsigned IndexTypeQuals,
624 SourceRange BracketsRange);
625
Mike Stump1eb44332009-09-09 15:08:12 +0000626 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000627 /// size modifier, size expression, and index type qualifiers.
628 ///
629 /// By default, performs semantic analysis when building the array type.
630 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000631 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000632 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000633 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000634 unsigned IndexTypeQuals,
635 SourceRange BracketsRange);
636
637 /// \brief Build a new vector type given the element type and
638 /// number of elements.
639 ///
640 /// By default, performs semantic analysis when building the vector type.
641 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000642 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000643 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000644
Douglas Gregor577f75a2009-08-04 16:50:30 +0000645 /// \brief Build a new extended vector type given the element type and
646 /// number of elements.
647 ///
648 /// By default, performs semantic analysis when building the vector type.
649 /// Subclasses may override this routine to provide different behavior.
650 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
651 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000652
653 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 /// given the element type and number of elements.
655 ///
656 /// By default, performs semantic analysis when building the vector type.
657 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000658 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000659 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000660 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000661
Douglas Gregor577f75a2009-08-04 16:50:30 +0000662 /// \brief Build a new function type.
663 ///
664 /// By default, performs semantic analysis when building the function type.
665 /// Subclasses may override this routine to provide different behavior.
666 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000667 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000668 unsigned NumParamTypes,
Richard Smitheefb3d52012-02-10 09:58:53 +0000669 bool Variadic, bool HasTrailingReturn,
670 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000671 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000672 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000673
John McCalla2becad2009-10-21 00:40:46 +0000674 /// \brief Build a new unprototyped function type.
675 QualType RebuildFunctionNoProtoType(QualType ResultType);
676
John McCalled976492009-12-04 22:46:56 +0000677 /// \brief Rebuild an unresolved typename type, given the decl that
678 /// the UnresolvedUsingTypenameDecl was transformed to.
679 QualType RebuildUnresolvedUsingType(Decl *D);
680
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000682 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000683 return SemaRef.Context.getTypeDeclType(Typedef);
684 }
685
686 /// \brief Build a new class/struct/union type.
687 QualType RebuildRecordType(RecordDecl *Record) {
688 return SemaRef.Context.getTypeDeclType(Record);
689 }
690
691 /// \brief Build a new Enum type.
692 QualType RebuildEnumType(EnumDecl *Enum) {
693 return SemaRef.Context.getTypeDeclType(Enum);
694 }
John McCall7da24312009-09-05 00:15:47 +0000695
Mike Stump1eb44332009-09-09 15:08:12 +0000696 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000697 ///
698 /// By default, performs semantic analysis when building the typeof type.
699 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000700 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000701
Mike Stump1eb44332009-09-09 15:08:12 +0000702 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000703 ///
704 /// By default, builds a new TypeOfType with the given underlying type.
705 QualType RebuildTypeOfType(QualType Underlying);
706
Sean Huntca63c202011-05-24 22:41:36 +0000707 /// \brief Build a new unary transform type.
708 QualType RebuildUnaryTransformType(QualType BaseType,
709 UnaryTransformType::UTTKind UKind,
710 SourceLocation Loc);
711
Mike Stump1eb44332009-09-09 15:08:12 +0000712 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000713 ///
714 /// By default, performs semantic analysis when building the decltype type.
715 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000716 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000717
Richard Smith34b41d92011-02-20 03:19:35 +0000718 /// \brief Build a new C++0x auto type.
719 ///
720 /// By default, builds a new AutoType with the given deduced type.
721 QualType RebuildAutoType(QualType Deduced) {
722 return SemaRef.Context.getAutoType(Deduced);
723 }
724
Douglas Gregor577f75a2009-08-04 16:50:30 +0000725 /// \brief Build a new template specialization type.
726 ///
727 /// By default, performs semantic analysis when building the template
728 /// specialization type. Subclasses may override this routine to provide
729 /// different behavior.
730 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000731 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000732 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000733
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000734 /// \brief Build a new parenthesized type.
735 ///
736 /// By default, builds a new ParenType type from the inner type.
737 /// Subclasses may override this routine to provide different behavior.
738 QualType RebuildParenType(QualType InnerType) {
739 return SemaRef.Context.getParenType(InnerType);
740 }
741
Douglas Gregor577f75a2009-08-04 16:50:30 +0000742 /// \brief Build a new qualified name type.
743 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000744 /// By default, builds a new ElaboratedType type from the keyword,
745 /// the nested-name-specifier and the named type.
746 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000747 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
748 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000749 NestedNameSpecifierLoc QualifierLoc,
750 QualType Named) {
751 return SemaRef.Context.getElaboratedType(Keyword,
752 QualifierLoc.getNestedNameSpecifier(),
753 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000754 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000755
756 /// \brief Build a new typename type that refers to a template-id.
757 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000758 /// By default, builds a new DependentNameType type from the
759 /// nested-name-specifier and the given type. Subclasses may override
760 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000761 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000762 ElaboratedTypeKeyword Keyword,
763 NestedNameSpecifierLoc QualifierLoc,
764 const IdentifierInfo *Name,
765 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000766 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000767 // Rebuild the template name.
768 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000769 CXXScopeSpec SS;
770 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000771 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000772 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000773
774 if (InstName.isNull())
775 return QualType();
776
777 // If it's still dependent, make a dependent specialization.
778 if (InstName.getAsDependentTemplateName())
779 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
780 QualifierLoc.getNestedNameSpecifier(),
781 Name,
782 Args);
783
784 // Otherwise, make an elaborated type wrapping a non-dependent
785 // specialization.
786 QualType T =
787 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
788 if (T.isNull()) return QualType();
789
790 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
791 return T;
792
793 return SemaRef.Context.getElaboratedType(Keyword,
794 QualifierLoc.getNestedNameSpecifier(),
795 T);
796 }
797
Douglas Gregor577f75a2009-08-04 16:50:30 +0000798 /// \brief Build a new typename type that refers to an identifier.
799 ///
800 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000801 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000802 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000803 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000804 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000805 NestedNameSpecifierLoc QualifierLoc,
806 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000807 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000808 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000809 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000810
Douglas Gregor2494dd02011-03-01 01:34:45 +0000811 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000812 // If the name is still dependent, just build a new dependent name type.
813 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000814 return SemaRef.Context.getDependentNameType(Keyword,
815 QualifierLoc.getNestedNameSpecifier(),
816 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000817 }
818
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000819 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000820 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000821 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000822
823 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
824
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000825 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000826 // into a non-dependent elaborated-type-specifier. Find the tag we're
827 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000828 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000829 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
830 if (!DC)
831 return QualType();
832
John McCall56138762010-05-27 06:40:31 +0000833 if (SemaRef.RequireCompleteDeclContext(SS, DC))
834 return QualType();
835
Douglas Gregor40336422010-03-31 22:19:08 +0000836 TagDecl *Tag = 0;
837 SemaRef.LookupQualifiedName(Result, DC);
838 switch (Result.getResultKind()) {
839 case LookupResult::NotFound:
840 case LookupResult::NotFoundInCurrentInstantiation:
841 break;
Sean Huntc3021132010-05-05 15:23:54 +0000842
Douglas Gregor40336422010-03-31 22:19:08 +0000843 case LookupResult::Found:
844 Tag = Result.getAsSingle<TagDecl>();
845 break;
Sean Huntc3021132010-05-05 15:23:54 +0000846
Douglas Gregor40336422010-03-31 22:19:08 +0000847 case LookupResult::FoundOverloaded:
848 case LookupResult::FoundUnresolvedValue:
849 llvm_unreachable("Tag lookup cannot find non-tags");
850 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000851
Douglas Gregor40336422010-03-31 22:19:08 +0000852 case LookupResult::Ambiguous:
853 // Let the LookupResult structure handle ambiguities.
854 return QualType();
855 }
856
857 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000858 // Check where the name exists but isn't a tag type and use that to emit
859 // better diagnostics.
860 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
861 SemaRef.LookupQualifiedName(Result, DC);
862 switch (Result.getResultKind()) {
863 case LookupResult::Found:
864 case LookupResult::FoundOverloaded:
865 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000866 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000867 unsigned Kind = 0;
868 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000869 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
870 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000871 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
872 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
873 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000874 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000875 default:
876 // FIXME: Would be nice to highlight just the source range.
877 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
878 << Kind << Id << DC;
879 break;
880 }
Douglas Gregor40336422010-03-31 22:19:08 +0000881 return QualType();
882 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000883
Richard Trieubbf34c02011-06-10 03:11:26 +0000884 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
885 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000886 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000887 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
888 return QualType();
889 }
890
891 // Build the elaborated-type-specifier type.
892 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000893 return SemaRef.Context.getElaboratedType(Keyword,
894 QualifierLoc.getNestedNameSpecifier(),
895 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000896 }
Mike Stump1eb44332009-09-09 15:08:12 +0000897
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000898 /// \brief Build a new pack expansion type.
899 ///
900 /// By default, builds a new PackExpansionType type from the given pattern.
901 /// Subclasses may override this routine to provide different behavior.
902 QualType RebuildPackExpansionType(QualType Pattern,
903 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000904 SourceLocation EllipsisLoc,
905 llvm::Optional<unsigned> NumExpansions) {
906 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
907 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000908 }
909
Eli Friedmanb001de72011-10-06 23:00:33 +0000910 /// \brief Build a new atomic type given its value type.
911 ///
912 /// By default, performs semantic analysis when building the atomic type.
913 /// Subclasses may override this routine to provide different behavior.
914 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
915
Douglas Gregord1067e52009-08-06 06:41:21 +0000916 /// \brief Build a new template name given a nested name specifier, a flag
917 /// indicating whether the "template" keyword was provided, and the template
918 /// that the template name refers to.
919 ///
920 /// By default, builds the new template name directly. Subclasses may override
921 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000922 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000923 bool TemplateKW,
924 TemplateDecl *Template);
925
Douglas Gregord1067e52009-08-06 06:41:21 +0000926 /// \brief Build a new template name given a nested name specifier and the
927 /// name that is referred to as a template.
928 ///
929 /// By default, performs semantic analysis to determine whether the name can
930 /// be resolved to a specific template, then builds the appropriate kind of
931 /// template name. Subclasses may override this routine to provide different
932 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000933 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
934 const IdentifierInfo &Name,
935 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000936 QualType ObjectType,
937 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000938
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000939 /// \brief Build a new template name given a nested name specifier and the
940 /// overloaded operator name that is referred to as a template.
941 ///
942 /// By default, performs semantic analysis to determine whether the name can
943 /// be resolved to a specific template, then builds the appropriate kind of
944 /// template name. Subclasses may override this routine to provide different
945 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000946 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000947 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000948 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000949 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000950
951 /// \brief Build a new template name given a template template parameter pack
952 /// and the
953 ///
954 /// By default, performs semantic analysis to determine whether the name can
955 /// be resolved to a specific template, then builds the appropriate kind of
956 /// template name. Subclasses may override this routine to provide different
957 /// behavior.
958 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
959 const TemplateArgument &ArgPack) {
960 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
961 }
962
Douglas Gregor43959a92009-08-20 07:17:43 +0000963 /// \brief Build a new compound statement.
964 ///
965 /// By default, performs semantic analysis to build the new statement.
966 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000967 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000968 MultiStmtArg Statements,
969 SourceLocation RBraceLoc,
970 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000971 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000972 IsStmtExpr);
973 }
974
975 /// \brief Build a new case statement.
976 ///
977 /// By default, performs semantic analysis to build the new statement.
978 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000979 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000980 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000981 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000982 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000983 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000984 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000985 ColonLoc);
986 }
Mike Stump1eb44332009-09-09 15:08:12 +0000987
Douglas Gregor43959a92009-08-20 07:17:43 +0000988 /// \brief Attach the body to a new case statement.
989 ///
990 /// By default, performs semantic analysis to build the new statement.
991 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000992 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000993 getSema().ActOnCaseStmtBody(S, Body);
994 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000995 }
Mike Stump1eb44332009-09-09 15:08:12 +0000996
Douglas Gregor43959a92009-08-20 07:17:43 +0000997 /// \brief Build a new default statement.
998 ///
999 /// By default, performs semantic analysis to build the new statement.
1000 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001001 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001002 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001003 Stmt *SubStmt) {
1004 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +00001005 /*CurScope=*/0);
1006 }
Mike Stump1eb44332009-09-09 15:08:12 +00001007
Douglas Gregor43959a92009-08-20 07:17:43 +00001008 /// \brief Build a new label statement.
1009 ///
1010 /// By default, performs semantic analysis to build the new statement.
1011 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001012 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1013 SourceLocation ColonLoc, Stmt *SubStmt) {
1014 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001015 }
Mike Stump1eb44332009-09-09 15:08:12 +00001016
Douglas Gregor43959a92009-08-20 07:17:43 +00001017 /// \brief Build a new "if" statement.
1018 ///
1019 /// By default, performs semantic analysis to build the new statement.
1020 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001021 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001022 VarDecl *CondVar, Stmt *Then,
1023 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001024 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001025 }
Mike Stump1eb44332009-09-09 15:08:12 +00001026
Douglas Gregor43959a92009-08-20 07:17:43 +00001027 /// \brief Start building a new switch statement.
1028 ///
1029 /// By default, performs semantic analysis to build the new statement.
1030 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001031 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001032 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001033 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001034 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001035 }
Mike Stump1eb44332009-09-09 15:08:12 +00001036
Douglas Gregor43959a92009-08-20 07:17:43 +00001037 /// \brief Attach the body to the switch statement.
1038 ///
1039 /// By default, performs semantic analysis to build the new statement.
1040 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001041 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001042 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001043 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001044 }
1045
1046 /// \brief Build a new while statement.
1047 ///
1048 /// By default, performs semantic analysis to build the new statement.
1049 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001050 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1051 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001052 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001053 }
Mike Stump1eb44332009-09-09 15:08:12 +00001054
Douglas Gregor43959a92009-08-20 07:17:43 +00001055 /// \brief Build a new do-while statement.
1056 ///
1057 /// By default, performs semantic analysis to build the new statement.
1058 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001059 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001060 SourceLocation WhileLoc, SourceLocation LParenLoc,
1061 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001062 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1063 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001064 }
1065
1066 /// \brief Build a new for statement.
1067 ///
1068 /// By default, performs semantic analysis to build the new statement.
1069 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001070 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1071 Stmt *Init, Sema::FullExprArg Cond,
1072 VarDecl *CondVar, Sema::FullExprArg Inc,
1073 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001074 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001075 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001076 }
Mike Stump1eb44332009-09-09 15:08:12 +00001077
Douglas Gregor43959a92009-08-20 07:17:43 +00001078 /// \brief Build a new goto statement.
1079 ///
1080 /// By default, performs semantic analysis to build the new statement.
1081 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001082 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1083 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001084 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001085 }
1086
1087 /// \brief Build a new indirect goto statement.
1088 ///
1089 /// By default, performs semantic analysis to build the new statement.
1090 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001091 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001092 SourceLocation StarLoc,
1093 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001094 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001095 }
Mike Stump1eb44332009-09-09 15:08:12 +00001096
Douglas Gregor43959a92009-08-20 07:17:43 +00001097 /// \brief Build a new return statement.
1098 ///
1099 /// By default, performs semantic analysis to build the new statement.
1100 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001101 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001102 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001103 }
Mike Stump1eb44332009-09-09 15:08:12 +00001104
Douglas Gregor43959a92009-08-20 07:17:43 +00001105 /// \brief Build a new declaration statement.
1106 ///
1107 /// By default, performs semantic analysis to build the new statement.
1108 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001109 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001110 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001111 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001112 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1113 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001114 }
Mike Stump1eb44332009-09-09 15:08:12 +00001115
Anders Carlsson703e3942010-01-24 05:50:09 +00001116 /// \brief Build a new inline asm statement.
1117 ///
1118 /// By default, performs semantic analysis to build the new statement.
1119 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001120 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001121 bool IsSimple,
1122 bool IsVolatile,
1123 unsigned NumOutputs,
1124 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001125 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001126 MultiExprArg Constraints,
1127 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001128 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001129 MultiExprArg Clobbers,
1130 SourceLocation RParenLoc,
1131 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001132 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001133 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001134 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001135 RParenLoc, MSAsm);
1136 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001137
1138 /// \brief Build a new Objective-C @try statement.
1139 ///
1140 /// By default, performs semantic analysis to build the new statement.
1141 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001142 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001143 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001144 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001145 Stmt *Finally) {
1146 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1147 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001148 }
1149
Douglas Gregorbe270a02010-04-26 17:57:08 +00001150 /// \brief Rebuild an Objective-C exception declaration.
1151 ///
1152 /// By default, performs semantic analysis to build the new declaration.
1153 /// Subclasses may override this routine to provide different behavior.
1154 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1155 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001156 return getSema().BuildObjCExceptionDecl(TInfo, T,
1157 ExceptionDecl->getInnerLocStart(),
1158 ExceptionDecl->getLocation(),
1159 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001160 }
Sean Huntc3021132010-05-05 15:23:54 +00001161
Douglas Gregorbe270a02010-04-26 17:57:08 +00001162 /// \brief Build a new Objective-C @catch statement.
1163 ///
1164 /// By default, performs semantic analysis to build the new statement.
1165 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001166 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001167 SourceLocation RParenLoc,
1168 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001169 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001170 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001171 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001172 }
Sean Huntc3021132010-05-05 15:23:54 +00001173
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001174 /// \brief Build a new Objective-C @finally statement.
1175 ///
1176 /// By default, performs semantic analysis to build the new statement.
1177 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001178 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001179 Stmt *Body) {
1180 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001181 }
Sean Huntc3021132010-05-05 15:23:54 +00001182
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001183 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001184 ///
1185 /// By default, performs semantic analysis to build the new statement.
1186 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001187 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001188 Expr *Operand) {
1189 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001190 }
Sean Huntc3021132010-05-05 15:23:54 +00001191
John McCall07524032011-07-27 21:50:02 +00001192 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1193 ///
1194 /// By default, performs semantic analysis to build the new statement.
1195 /// Subclasses may override this routine to provide different behavior.
1196 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1197 Expr *object) {
1198 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1199 }
1200
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001201 /// \brief Build a new Objective-C @synchronized statement.
1202 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001203 /// By default, performs semantic analysis to build the new statement.
1204 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001205 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall07524032011-07-27 21:50:02 +00001206 Expr *Object, Stmt *Body) {
1207 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001208 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001209
John McCallf85e1932011-06-15 23:02:42 +00001210 /// \brief Build a new Objective-C @autoreleasepool statement.
1211 ///
1212 /// By default, performs semantic analysis to build the new statement.
1213 /// Subclasses may override this routine to provide different behavior.
1214 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1215 Stmt *Body) {
1216 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1217 }
John McCall990567c2011-07-27 01:07:15 +00001218
1219 /// \brief Build the collection operand to a new Objective-C fast
1220 /// enumeration statement.
1221 ///
1222 /// By default, performs semantic analysis to build the new statement.
1223 /// Subclasses may override this routine to provide different behavior.
1224 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1225 Expr *collection) {
1226 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1227 }
John McCallf85e1932011-06-15 23:02:42 +00001228
Douglas Gregorc3203e72010-04-22 23:10:45 +00001229 /// \brief Build a new Objective-C fast enumeration statement.
1230 ///
1231 /// By default, performs semantic analysis to build the new statement.
1232 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001233 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001234 SourceLocation LParenLoc,
1235 Stmt *Element,
1236 Expr *Collection,
1237 SourceLocation RParenLoc,
1238 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001239 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001240 Element,
1241 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001242 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001243 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001244 }
Sean Huntc3021132010-05-05 15:23:54 +00001245
Douglas Gregor43959a92009-08-20 07:17:43 +00001246 /// \brief Build a new C++ exception declaration.
1247 ///
1248 /// By default, performs semantic analysis to build the new decaration.
1249 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001250 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001251 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001252 SourceLocation StartLoc,
1253 SourceLocation IdLoc,
1254 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001255 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1256 StartLoc, IdLoc, Id);
1257 if (Var)
1258 getSema().CurContext->addDecl(Var);
1259 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001260 }
1261
1262 /// \brief Build a new C++ catch statement.
1263 ///
1264 /// By default, performs semantic analysis to build the new statement.
1265 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001266 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001267 VarDecl *ExceptionDecl,
1268 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001269 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1270 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001271 }
Mike Stump1eb44332009-09-09 15:08:12 +00001272
Douglas Gregor43959a92009-08-20 07:17:43 +00001273 /// \brief Build a new C++ try statement.
1274 ///
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001277 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001278 Stmt *TryBlock,
1279 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001280 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001281 }
Mike Stump1eb44332009-09-09 15:08:12 +00001282
Richard Smithad762fc2011-04-14 22:09:26 +00001283 /// \brief Build a new C++0x range-based for statement.
1284 ///
1285 /// By default, performs semantic analysis to build the new statement.
1286 /// Subclasses may override this routine to provide different behavior.
1287 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1288 SourceLocation ColonLoc,
1289 Stmt *Range, Stmt *BeginEnd,
1290 Expr *Cond, Expr *Inc,
1291 Stmt *LoopVar,
1292 SourceLocation RParenLoc) {
1293 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1294 Cond, Inc, LoopVar, RParenLoc);
1295 }
Douglas Gregorba0513d2011-10-25 01:33:02 +00001296
1297 /// \brief Build a new C++0x range-based for statement.
1298 ///
1299 /// By default, performs semantic analysis to build the new statement.
1300 /// Subclasses may override this routine to provide different behavior.
1301 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
1302 bool IsIfExists,
1303 NestedNameSpecifierLoc QualifierLoc,
1304 DeclarationNameInfo NameInfo,
1305 Stmt *Nested) {
1306 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1307 QualifierLoc, NameInfo, Nested);
1308 }
1309
Richard Smithad762fc2011-04-14 22:09:26 +00001310 /// \brief Attach body to a C++0x range-based for statement.
1311 ///
1312 /// By default, performs semantic analysis to finish the new statement.
1313 /// Subclasses may override this routine to provide different behavior.
1314 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1315 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1316 }
1317
John Wiegley28bbe4b2011-04-28 01:08:34 +00001318 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1319 SourceLocation TryLoc,
1320 Stmt *TryBlock,
1321 Stmt *Handler) {
1322 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1323 }
1324
1325 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1326 Expr *FilterExpr,
1327 Stmt *Block) {
1328 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1329 }
1330
1331 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1332 Stmt *Block) {
1333 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1334 }
1335
Douglas Gregorb98b1992009-08-11 05:31:07 +00001336 /// \brief Build a new expression that references a declaration.
1337 ///
1338 /// By default, performs semantic analysis to build the new expression.
1339 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001340 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001341 LookupResult &R,
1342 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001343 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1344 }
1345
1346
1347 /// \brief Build a new expression that references a declaration.
1348 ///
1349 /// By default, performs semantic analysis to build the new expression.
1350 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001351 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001352 ValueDecl *VD,
1353 const DeclarationNameInfo &NameInfo,
1354 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001355 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001356 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001357
1358 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001359
1360 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001361 }
Mike Stump1eb44332009-09-09 15:08:12 +00001362
Douglas Gregorb98b1992009-08-11 05:31:07 +00001363 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001364 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001365 /// By default, performs semantic analysis to build the new expression.
1366 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001367 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001368 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001369 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001370 }
1371
Douglas Gregora71d8192009-09-04 17:36:40 +00001372 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001373 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001374 /// By default, performs semantic analysis to build the new expression.
1375 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001376 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001377 SourceLocation OperatorLoc,
1378 bool isArrow,
1379 CXXScopeSpec &SS,
1380 TypeSourceInfo *ScopeType,
1381 SourceLocation CCLoc,
1382 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001383 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001384
Douglas Gregorb98b1992009-08-11 05:31:07 +00001385 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001386 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001387 /// By default, performs semantic analysis to build the new expression.
1388 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001389 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001390 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001391 Expr *SubExpr) {
1392 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001393 }
Mike Stump1eb44332009-09-09 15:08:12 +00001394
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001395 /// \brief Build a new builtin offsetof expression.
1396 ///
1397 /// By default, performs semantic analysis to build the new expression.
1398 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001399 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001400 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001401 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001402 unsigned NumComponents,
1403 SourceLocation RParenLoc) {
1404 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1405 NumComponents, RParenLoc);
1406 }
Sean Huntc3021132010-05-05 15:23:54 +00001407
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001408 /// \brief Build a new sizeof, alignof or vec_step expression with a
1409 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001410 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001411 /// By default, performs semantic analysis to build the new expression.
1412 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001413 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1414 SourceLocation OpLoc,
1415 UnaryExprOrTypeTrait ExprKind,
1416 SourceRange R) {
1417 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001418 }
1419
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001420 /// \brief Build a new sizeof, alignof or vec step expression with an
1421 /// expression argument.
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.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001425 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1426 UnaryExprOrTypeTrait ExprKind,
1427 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001428 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001429 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001430 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001431 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001432
Douglas Gregorb98b1992009-08-11 05:31:07 +00001433 return move(Result);
1434 }
Mike Stump1eb44332009-09-09 15:08:12 +00001435
Douglas Gregorb98b1992009-08-11 05:31:07 +00001436 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001437 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001438 /// By default, performs semantic analysis to build the new expression.
1439 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001440 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001441 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001442 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001443 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001444 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1445 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001446 RBracketLoc);
1447 }
1448
1449 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001450 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001451 /// By default, performs semantic analysis to build the new expression.
1452 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001453 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001454 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001455 SourceLocation RParenLoc,
1456 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001457 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001458 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001459 }
1460
1461 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001462 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 /// By default, performs semantic analysis to build the new expression.
1464 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001465 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001466 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001467 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001468 SourceLocation TemplateKWLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001469 const DeclarationNameInfo &MemberNameInfo,
1470 ValueDecl *Member,
1471 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001472 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001473 NamedDecl *FirstQualifierInScope) {
Richard Smith9138b4e2011-10-26 19:06:56 +00001474 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1475 isArrow);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001476 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001477 // We have a reference to an unnamed field. This is always the
1478 // base of an anonymous struct/union member access, i.e. the
1479 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001480 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001481 assert(Member->getType()->isRecordType() &&
1482 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001483
Richard Smith9138b4e2011-10-26 19:06:56 +00001484 BaseResult =
1485 getSema().PerformObjectMemberConversion(BaseResult.take(),
John Wiegley429bb272011-04-08 18:41:53 +00001486 QualifierLoc.getNestedNameSpecifier(),
1487 FoundDecl, Member);
1488 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001489 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001490 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001491 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001492 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001493 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001494 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001495 cast<FieldDecl>(Member)->getType(),
1496 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001497 return getSema().Owned(ME);
1498 }
Mike Stump1eb44332009-09-09 15:08:12 +00001499
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001500 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001501 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001502
John Wiegley429bb272011-04-08 18:41:53 +00001503 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001504 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001505
John McCall6bb80172010-03-30 21:47:33 +00001506 // FIXME: this involves duplicating earlier analysis in a lot of
1507 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001508 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001509 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001510 R.resolveKind();
1511
John McCall9ae2f072010-08-23 23:25:46 +00001512 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001513 SS, TemplateKWLoc,
1514 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001515 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 }
Mike Stump1eb44332009-09-09 15:08:12 +00001517
Douglas Gregorb98b1992009-08-11 05:31:07 +00001518 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001519 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001520 /// By default, performs semantic analysis to build the new expression.
1521 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001522 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001523 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001524 Expr *LHS, Expr *RHS) {
1525 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001526 }
1527
1528 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001529 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001530 /// By default, performs semantic analysis to build the new expression.
1531 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001532 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001533 SourceLocation QuestionLoc,
1534 Expr *LHS,
1535 SourceLocation ColonLoc,
1536 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001537 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1538 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001539 }
1540
Douglas Gregorb98b1992009-08-11 05:31:07 +00001541 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001542 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001543 /// By default, performs semantic analysis to build the new expression.
1544 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001545 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001546 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001547 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001548 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001549 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001550 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001551 }
Mike Stump1eb44332009-09-09 15:08:12 +00001552
Douglas Gregorb98b1992009-08-11 05:31:07 +00001553 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001554 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 /// By default, performs semantic analysis to build the new expression.
1556 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001557 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001558 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001559 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001560 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001561 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001562 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001563 }
Mike Stump1eb44332009-09-09 15:08:12 +00001564
Douglas Gregorb98b1992009-08-11 05:31:07 +00001565 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001566 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 /// By default, performs semantic analysis to build the new expression.
1568 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001569 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 SourceLocation OpLoc,
1571 SourceLocation AccessorLoc,
1572 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001573
John McCall129e2df2009-11-30 22:42:35 +00001574 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001575 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001576 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001577 OpLoc, /*IsArrow*/ false,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00001578 SS, SourceLocation(),
1579 /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001580 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001581 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001582 }
Mike Stump1eb44332009-09-09 15:08:12 +00001583
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001585 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 /// By default, performs semantic analysis to build the new expression.
1587 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001588 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCallc8fc90a2011-07-06 07:30:07 +00001589 MultiExprArg Inits,
1590 SourceLocation RBraceLoc,
1591 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001592 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001593 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1594 if (Result.isInvalid() || ResultTy->isDependentType())
1595 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001596
Douglas Gregore48319a2009-11-09 17:16:50 +00001597 // Patch in the result type we were given, which may have been computed
1598 // when the initial InitListExpr was built.
1599 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1600 ILE->setType(ResultTy);
1601 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001602 }
Mike Stump1eb44332009-09-09 15:08:12 +00001603
Douglas Gregorb98b1992009-08-11 05:31:07 +00001604 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001605 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001606 /// By default, performs semantic analysis to build the new expression.
1607 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001608 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001609 MultiExprArg ArrayExprs,
1610 SourceLocation EqualOrColonLoc,
1611 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001612 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001613 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001615 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001617 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001618
Douglas Gregorb98b1992009-08-11 05:31:07 +00001619 ArrayExprs.release();
1620 return move(Result);
1621 }
Mike Stump1eb44332009-09-09 15:08:12 +00001622
Douglas Gregorb98b1992009-08-11 05:31:07 +00001623 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001624 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001625 /// By default, builds the implicit value initialization without performing
1626 /// any semantic analysis. Subclasses may override this routine to provide
1627 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001628 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001629 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1630 }
Mike Stump1eb44332009-09-09 15:08:12 +00001631
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 /// \brief Build a new \c va_arg expression.
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 RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001637 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001638 SourceLocation RParenLoc) {
1639 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001640 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001641 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 }
1643
1644 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001645 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001646 /// By default, performs semantic analysis to build the new expression.
1647 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001648 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redl5b9cc5d2012-02-11 23:51:47 +00001649 MultiExprArg SubExprs,
1650 SourceLocation RParenLoc) {
1651 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 }
Mike Stump1eb44332009-09-09 15:08:12 +00001653
Douglas Gregorb98b1992009-08-11 05:31:07 +00001654 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001655 ///
1656 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001657 /// rather than attempting to map the label statement itself.
1658 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001659 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001660 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001661 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001662 }
Mike Stump1eb44332009-09-09 15:08:12 +00001663
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001665 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001666 /// By default, performs semantic analysis to build the new expression.
1667 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001668 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001669 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001671 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001672 }
Mike Stump1eb44332009-09-09 15:08:12 +00001673
Douglas Gregorb98b1992009-08-11 05:31:07 +00001674 /// \brief Build a new __builtin_choose_expr expression.
1675 ///
1676 /// By default, performs semantic analysis to build the new expression.
1677 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001678 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001679 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 SourceLocation RParenLoc) {
1681 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001682 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 RParenLoc);
1684 }
Mike Stump1eb44332009-09-09 15:08:12 +00001685
Peter Collingbournef111d932011-04-15 00:35:48 +00001686 /// \brief Build a new generic selection expression.
1687 ///
1688 /// By default, performs semantic analysis to build the new expression.
1689 /// Subclasses may override this routine to provide different behavior.
1690 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1691 SourceLocation DefaultLoc,
1692 SourceLocation RParenLoc,
1693 Expr *ControllingExpr,
1694 TypeSourceInfo **Types,
1695 Expr **Exprs,
1696 unsigned NumAssocs) {
1697 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1698 ControllingExpr, Types, Exprs,
1699 NumAssocs);
1700 }
1701
Douglas Gregorb98b1992009-08-11 05:31:07 +00001702 /// \brief Build a new overloaded operator call expression.
1703 ///
1704 /// By default, performs semantic analysis to build the new expression.
1705 /// The semantic analysis provides the behavior of template instantiation,
1706 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001707 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001708 /// argument-dependent lookup, etc. Subclasses may override this routine to
1709 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001710 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001711 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001712 Expr *Callee,
1713 Expr *First,
1714 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001715
1716 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001717 /// reinterpret_cast.
1718 ///
1719 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001720 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001721 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001722 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001723 Stmt::StmtClass Class,
1724 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001725 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001726 SourceLocation RAngleLoc,
1727 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001728 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001729 SourceLocation RParenLoc) {
1730 switch (Class) {
1731 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001732 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001733 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001734 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001735
1736 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001737 return getDerived().RebuildCXXDynamicCastExpr(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 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001742 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001743 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001744 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001745 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001746
Douglas Gregorb98b1992009-08-11 05:31:07 +00001747 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001748 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001749 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001750 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001751
Douglas Gregorb98b1992009-08-11 05:31:07 +00001752 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001753 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001754 }
Mike Stump1eb44332009-09-09 15:08:12 +00001755
John McCallf312b1e2010-08-26 23:41:50 +00001756 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001757 }
Mike Stump1eb44332009-09-09 15:08:12 +00001758
Douglas Gregorb98b1992009-08-11 05:31:07 +00001759 /// \brief Build a new C++ static_cast expression.
1760 ///
1761 /// By default, performs semantic analysis to build the new expression.
1762 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001763 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001764 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001765 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001766 SourceLocation RAngleLoc,
1767 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001768 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001769 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001770 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001771 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001772 SourceRange(LAngleLoc, RAngleLoc),
1773 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001774 }
1775
1776 /// \brief Build a new C++ dynamic_cast expression.
1777 ///
1778 /// By default, performs semantic analysis to build the new expression.
1779 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001780 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001781 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001782 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783 SourceLocation RAngleLoc,
1784 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001785 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001786 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001787 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001788 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001789 SourceRange(LAngleLoc, RAngleLoc),
1790 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001791 }
1792
1793 /// \brief Build a new C++ reinterpret_cast expression.
1794 ///
1795 /// By default, performs semantic analysis to build the new expression.
1796 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001797 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001798 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001799 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 SourceLocation RAngleLoc,
1801 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001802 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001804 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001805 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001806 SourceRange(LAngleLoc, RAngleLoc),
1807 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001808 }
1809
1810 /// \brief Build a new C++ const_cast expression.
1811 ///
1812 /// By default, performs semantic analysis to build the new expression.
1813 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001814 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001815 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001816 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001817 SourceLocation RAngleLoc,
1818 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001819 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001820 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001821 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001822 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001823 SourceRange(LAngleLoc, RAngleLoc),
1824 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001825 }
Mike Stump1eb44332009-09-09 15:08:12 +00001826
Douglas Gregorb98b1992009-08-11 05:31:07 +00001827 /// \brief Build a new C++ functional-style cast expression.
1828 ///
1829 /// By default, performs semantic analysis to build the new expression.
1830 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001831 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1832 SourceLocation LParenLoc,
1833 Expr *Sub,
1834 SourceLocation RParenLoc) {
1835 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001836 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001837 RParenLoc);
1838 }
Mike Stump1eb44332009-09-09 15:08:12 +00001839
Douglas Gregorb98b1992009-08-11 05:31:07 +00001840 /// \brief Build a new C++ typeid(type) expression.
1841 ///
1842 /// By default, performs semantic analysis to build the new expression.
1843 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001844 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001845 SourceLocation TypeidLoc,
1846 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001847 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001848 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001849 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001850 }
Mike Stump1eb44332009-09-09 15:08:12 +00001851
Francois Pichet01b7c302010-09-08 12:20:18 +00001852
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 /// \brief Build a new C++ typeid(expr) expression.
1854 ///
1855 /// By default, performs semantic analysis to build the new expression.
1856 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001857 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001858 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001859 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001860 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001861 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001862 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001863 }
1864
Francois Pichet01b7c302010-09-08 12:20:18 +00001865 /// \brief Build a new C++ __uuidof(type) expression.
1866 ///
1867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
1869 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1870 SourceLocation TypeidLoc,
1871 TypeSourceInfo *Operand,
1872 SourceLocation RParenLoc) {
1873 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1874 RParenLoc);
1875 }
1876
1877 /// \brief Build a new C++ __uuidof(expr) expression.
1878 ///
1879 /// By default, performs semantic analysis to build the new expression.
1880 /// Subclasses may override this routine to provide different behavior.
1881 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1882 SourceLocation TypeidLoc,
1883 Expr *Operand,
1884 SourceLocation RParenLoc) {
1885 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1886 RParenLoc);
1887 }
1888
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 /// \brief Build a new C++ "this" expression.
1890 ///
1891 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001892 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001893 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001894 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001895 QualType ThisType,
1896 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001897 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001898 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001899 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1900 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001901 }
1902
1903 /// \brief Build a new C++ throw expression.
1904 ///
1905 /// By default, performs semantic analysis to build the new expression.
1906 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001907 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1908 bool IsThrownVariableInScope) {
1909 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001910 }
1911
1912 /// \brief Build a new C++ default-argument expression.
1913 ///
1914 /// By default, builds a new default-argument expression, which does not
1915 /// require any semantic analysis. Subclasses may override this routine to
1916 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001917 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001918 ParmVarDecl *Param) {
1919 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1920 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001921 }
1922
1923 /// \brief Build a new C++ zero-initialization expression.
1924 ///
1925 /// By default, performs semantic analysis to build the new expression.
1926 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001927 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1928 SourceLocation LParenLoc,
1929 SourceLocation RParenLoc) {
1930 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001931 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001932 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001933 }
Mike Stump1eb44332009-09-09 15:08:12 +00001934
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 /// \brief Build a new C++ "new" expression.
1936 ///
1937 /// By default, performs semantic analysis to build the new expression.
1938 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001939 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001940 bool UseGlobal,
1941 SourceLocation PlacementLParen,
1942 MultiExprArg PlacementArgs,
1943 SourceLocation PlacementRParen,
1944 SourceRange TypeIdParens,
1945 QualType AllocatedType,
1946 TypeSourceInfo *AllocatedTypeInfo,
1947 Expr *ArraySize,
1948 SourceLocation ConstructorLParen,
1949 MultiExprArg ConstructorArgs,
1950 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001951 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001952 PlacementLParen,
1953 move(PlacementArgs),
1954 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001955 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001956 AllocatedType,
1957 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001958 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001959 ConstructorLParen,
1960 move(ConstructorArgs),
1961 ConstructorRParen);
1962 }
Mike Stump1eb44332009-09-09 15:08:12 +00001963
Douglas Gregorb98b1992009-08-11 05:31:07 +00001964 /// \brief Build a new C++ "delete" 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 RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001969 bool IsGlobalDelete,
1970 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001971 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001972 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001973 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001974 }
Mike Stump1eb44332009-09-09 15:08:12 +00001975
Douglas Gregorb98b1992009-08-11 05:31:07 +00001976 /// \brief Build a new unary type trait expression.
1977 ///
1978 /// By default, performs semantic analysis to build the new expression.
1979 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001980 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001981 SourceLocation StartLoc,
1982 TypeSourceInfo *T,
1983 SourceLocation RParenLoc) {
1984 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001985 }
1986
Francois Pichet6ad6f282010-12-07 00:08:36 +00001987 /// \brief Build a new binary 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 RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1992 SourceLocation StartLoc,
1993 TypeSourceInfo *LhsT,
1994 TypeSourceInfo *RhsT,
1995 SourceLocation RParenLoc) {
1996 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1997 }
1998
John Wiegley21ff2e52011-04-28 00:16:57 +00001999 /// \brief Build a new array type 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 RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2004 SourceLocation StartLoc,
2005 TypeSourceInfo *TSInfo,
2006 Expr *DimExpr,
2007 SourceLocation RParenLoc) {
2008 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2009 }
2010
John Wiegley55262202011-04-25 06:54:41 +00002011 /// \brief Build a new expression trait expression.
2012 ///
2013 /// By default, performs semantic analysis to build the new expression.
2014 /// Subclasses may override this routine to provide different behavior.
2015 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2016 SourceLocation StartLoc,
2017 Expr *Queried,
2018 SourceLocation RParenLoc) {
2019 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2020 }
2021
Mike Stump1eb44332009-09-09 15:08:12 +00002022 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002023 /// expression.
2024 ///
2025 /// By default, performs semantic analysis to build the new expression.
2026 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002027 ExprResult RebuildDependentScopeDeclRefExpr(
2028 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002029 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002030 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002031 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002032 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002033 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002034
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002035 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002036 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002037 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002038
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002039 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002040 }
2041
2042 /// \brief Build a new template-id expression.
2043 ///
2044 /// By default, performs semantic analysis to build the new expression.
2045 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002046 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002047 SourceLocation TemplateKWLoc,
2048 LookupResult &R,
2049 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002050 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002051 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2052 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002053 }
2054
2055 /// \brief Build a new object-construction expression.
2056 ///
2057 /// By default, performs semantic analysis to build the new expression.
2058 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002059 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002060 SourceLocation Loc,
2061 CXXConstructorDecl *Constructor,
2062 bool IsElidable,
2063 MultiExprArg Args,
2064 bool HadMultipleCandidates,
2065 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002066 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002067 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002068 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002069 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002070 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002071 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002072
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002073 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002074 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002075 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002076 RequiresZeroInit, ConstructKind,
2077 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002078 }
2079
2080 /// \brief Build a new object-construction expression.
2081 ///
2082 /// By default, performs semantic analysis to build the new expression.
2083 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002084 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2085 SourceLocation LParenLoc,
2086 MultiExprArg Args,
2087 SourceLocation RParenLoc) {
2088 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002089 LParenLoc,
2090 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002091 RParenLoc);
2092 }
2093
2094 /// \brief Build a new object-construction expression.
2095 ///
2096 /// By default, performs semantic analysis to build the new expression.
2097 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002098 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2099 SourceLocation LParenLoc,
2100 MultiExprArg Args,
2101 SourceLocation RParenLoc) {
2102 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002103 LParenLoc,
2104 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002105 RParenLoc);
2106 }
Mike Stump1eb44332009-09-09 15:08:12 +00002107
Douglas Gregorb98b1992009-08-11 05:31:07 +00002108 /// \brief Build a new member reference expression.
2109 ///
2110 /// By default, performs semantic analysis to build the new expression.
2111 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002112 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002113 QualType BaseType,
2114 bool IsArrow,
2115 SourceLocation OperatorLoc,
2116 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002117 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002118 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002119 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002120 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002121 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002122 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002123
John McCall9ae2f072010-08-23 23:25:46 +00002124 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002125 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002126 SS, TemplateKWLoc,
2127 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002128 MemberNameInfo,
2129 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002130 }
2131
John McCall129e2df2009-11-30 22:42:35 +00002132 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002133 ///
2134 /// By default, performs semantic analysis to build the new expression.
2135 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002136 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2137 SourceLocation OperatorLoc,
2138 bool IsArrow,
2139 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002140 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002141 NamedDecl *FirstQualifierInScope,
2142 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002143 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002144 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002145 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002146
John McCall9ae2f072010-08-23 23:25:46 +00002147 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002148 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002149 SS, TemplateKWLoc,
2150 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002151 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002152 }
Mike Stump1eb44332009-09-09 15:08:12 +00002153
Sebastian Redl2e156222010-09-10 20:55:43 +00002154 /// \brief Build a new noexcept expression.
2155 ///
2156 /// By default, performs semantic analysis to build the new expression.
2157 /// Subclasses may override this routine to provide different behavior.
2158 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2159 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2160 }
2161
Douglas Gregoree8aff02011-01-04 17:33:58 +00002162 /// \brief Build a new expression to compute the length of a parameter pack.
2163 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2164 SourceLocation PackLoc,
2165 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002166 llvm::Optional<unsigned> Length) {
2167 if (Length)
2168 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2169 OperatorLoc, Pack, PackLoc,
2170 RParenLoc, *Length);
2171
Douglas Gregoree8aff02011-01-04 17:33:58 +00002172 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2173 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002174 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002175 }
2176
Douglas Gregorb98b1992009-08-11 05:31:07 +00002177 /// \brief Build a new Objective-C @encode expression.
2178 ///
2179 /// By default, performs semantic analysis to build the new expression.
2180 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002181 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002182 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002183 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002184 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002185 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002186 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002187
Douglas Gregor92e986e2010-04-22 16:44:27 +00002188 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002189 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002190 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002191 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002192 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002193 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002194 MultiExprArg Args,
2195 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002196 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2197 ReceiverTypeInfo->getType(),
2198 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002199 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002200 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002201 }
2202
2203 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002204 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002205 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002206 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002207 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002208 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002209 MultiExprArg Args,
2210 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002211 return SemaRef.BuildInstanceMessage(Receiver,
2212 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002213 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002214 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002215 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002216 }
2217
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002218 /// \brief Build a new Objective-C ivar reference expression.
2219 ///
2220 /// By default, performs semantic analysis to build the new expression.
2221 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002222 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002223 SourceLocation IvarLoc,
2224 bool IsArrow, bool IsFreeIvar) {
2225 // FIXME: We lose track of the IsFreeIvar bit.
2226 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002227 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002228 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2229 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002230 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002231 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002232 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002233 false);
John Wiegley429bb272011-04-08 18:41:53 +00002234 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002235 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002236
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002237 if (Result.get())
2238 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002239
John Wiegley429bb272011-04-08 18:41:53 +00002240 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002241 /*FIXME:*/IvarLoc, IsArrow,
2242 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002243 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002244 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002245 /*TemplateArgs=*/0);
2246 }
Douglas Gregore3303542010-04-26 20:47:02 +00002247
2248 /// \brief Build a new Objective-C property reference expression.
2249 ///
2250 /// By default, performs semantic analysis to build the new expression.
2251 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002252 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002253 ObjCPropertyDecl *Property,
2254 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002255 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002256 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002257 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2258 Sema::LookupMemberName);
2259 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002260 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002261 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002262 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002263 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002264 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002265
Douglas Gregore3303542010-04-26 20:47:02 +00002266 if (Result.get())
2267 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002268
John Wiegley429bb272011-04-08 18:41:53 +00002269 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002270 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002271 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002272 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002273 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002274 /*TemplateArgs=*/0);
2275 }
Sean Huntc3021132010-05-05 15:23:54 +00002276
John McCall12f78a62010-12-02 01:19:52 +00002277 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002278 ///
2279 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002280 /// Subclasses may override this routine to provide different behavior.
2281 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2282 ObjCMethodDecl *Getter,
2283 ObjCMethodDecl *Setter,
2284 SourceLocation PropertyLoc) {
2285 // Since these expressions can only be value-dependent, we do not
2286 // need to perform semantic analysis again.
2287 return Owned(
2288 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2289 VK_LValue, OK_ObjCProperty,
2290 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002291 }
2292
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002293 /// \brief Build a new Objective-C "isa" expression.
2294 ///
2295 /// By default, performs semantic analysis to build the new expression.
2296 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002297 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002298 bool IsArrow) {
2299 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002300 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002301 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2302 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002303 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002304 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002305 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002306 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002307 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002308
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002309 if (Result.get())
2310 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002311
John Wiegley429bb272011-04-08 18:41:53 +00002312 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002313 /*FIXME:*/IsaLoc, IsArrow,
2314 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002315 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002316 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002317 /*TemplateArgs=*/0);
2318 }
Sean Huntc3021132010-05-05 15:23:54 +00002319
Douglas Gregorb98b1992009-08-11 05:31:07 +00002320 /// \brief Build a new shuffle vector expression.
2321 ///
2322 /// By default, performs semantic analysis to build the new expression.
2323 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002324 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002325 MultiExprArg SubExprs,
2326 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002327 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002328 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002329 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2330 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2331 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2332 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002333
Douglas Gregorb98b1992009-08-11 05:31:07 +00002334 // Build a reference to the __builtin_shufflevector builtin
2335 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002336 ExprResult Callee
2337 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2338 VK_LValue, BuiltinLoc));
2339 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2340 if (Callee.isInvalid())
2341 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002342
2343 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002344 unsigned NumSubExprs = SubExprs.size();
2345 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002346 ExprResult TheCall = SemaRef.Owned(
2347 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002348 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002349 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002350 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002351 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002352
Douglas Gregorb98b1992009-08-11 05:31:07 +00002353 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002354 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002355 }
John McCall43fed0d2010-11-12 08:19:04 +00002356
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002357 /// \brief Build a new template argument pack expansion.
2358 ///
2359 /// By default, performs semantic analysis to build a new pack expansion
2360 /// for a template argument. Subclasses may override this routine to provide
2361 /// different behavior.
2362 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002363 SourceLocation EllipsisLoc,
2364 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002365 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002366 case TemplateArgument::Expression: {
2367 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002368 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2369 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002370 if (Result.isInvalid())
2371 return TemplateArgumentLoc();
2372
2373 return TemplateArgumentLoc(Result.get(), Result.get());
2374 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002375
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002376 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002377 return TemplateArgumentLoc(TemplateArgument(
2378 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002379 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002380 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002381 Pattern.getTemplateNameLoc(),
2382 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002383
2384 case TemplateArgument::Null:
2385 case TemplateArgument::Integral:
2386 case TemplateArgument::Declaration:
2387 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002388 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002389 llvm_unreachable("Pack expansion pattern has no parameter packs");
2390
2391 case TemplateArgument::Type:
2392 if (TypeSourceInfo *Expansion
2393 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002394 EllipsisLoc,
2395 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002396 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2397 Expansion);
2398 break;
2399 }
2400
2401 return TemplateArgumentLoc();
2402 }
2403
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002404 /// \brief Build a new expression pack expansion.
2405 ///
2406 /// By default, performs semantic analysis to build a new pack expansion
2407 /// for an expression. Subclasses may override this routine to provide
2408 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002409 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2410 llvm::Optional<unsigned> NumExpansions) {
2411 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002412 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002413
2414 /// \brief Build a new atomic operation expression.
2415 ///
2416 /// By default, performs semantic analysis to build the new expression.
2417 /// Subclasses may override this routine to provide different behavior.
2418 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2419 MultiExprArg SubExprs,
2420 QualType RetTy,
2421 AtomicExpr::AtomicOp Op,
2422 SourceLocation RParenLoc) {
2423 // Just create the expression; there is not any interesting semantic
2424 // analysis here because we can't actually build an AtomicExpr until
2425 // we are sure it is semantically sound.
2426 unsigned NumSubExprs = SubExprs.size();
2427 Expr **Subs = (Expr **)SubExprs.release();
2428 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2429 NumSubExprs, RetTy, Op,
2430 RParenLoc);
2431 }
2432
John McCall43fed0d2010-11-12 08:19:04 +00002433private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002434 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2435 QualType ObjectType,
2436 NamedDecl *FirstQualifierInScope,
2437 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002438
2439 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2440 QualType ObjectType,
2441 NamedDecl *FirstQualifierInScope,
2442 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002443};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002444
Douglas Gregor43959a92009-08-20 07:17:43 +00002445template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002446StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002447 if (!S)
2448 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002449
Douglas Gregor43959a92009-08-20 07:17:43 +00002450 switch (S->getStmtClass()) {
2451 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002452
Douglas Gregor43959a92009-08-20 07:17:43 +00002453 // Transform individual statement nodes
2454#define STMT(Node, Parent) \
2455 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002456#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002457#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002458#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002459
Douglas Gregor43959a92009-08-20 07:17:43 +00002460 // Transform expressions by calling TransformExpr.
2461#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002462#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002463#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002464#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002465 {
John McCall60d7b3a2010-08-24 06:29:42 +00002466 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002467 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002468 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002469
John McCall9ae2f072010-08-23 23:25:46 +00002470 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002471 }
Mike Stump1eb44332009-09-09 15:08:12 +00002472 }
2473
John McCall3fa5cae2010-10-26 07:05:15 +00002474 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002475}
Mike Stump1eb44332009-09-09 15:08:12 +00002476
2477
Douglas Gregor670444e2009-08-04 22:27:00 +00002478template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002479ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002480 if (!E)
2481 return SemaRef.Owned(E);
2482
2483 switch (E->getStmtClass()) {
2484 case Stmt::NoStmtClass: break;
2485#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002486#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002487#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002488 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002489#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002490 }
2491
John McCall3fa5cae2010-10-26 07:05:15 +00002492 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002493}
2494
2495template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002496bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2497 unsigned NumInputs,
2498 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002499 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002500 bool *ArgChanged) {
2501 for (unsigned I = 0; I != NumInputs; ++I) {
2502 // If requested, drop call arguments that need to be dropped.
2503 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2504 if (ArgChanged)
2505 *ArgChanged = true;
2506
2507 break;
2508 }
2509
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002510 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2511 Expr *Pattern = Expansion->getPattern();
2512
Chris Lattner686775d2011-07-20 06:58:45 +00002513 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002514 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2515 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2516
2517 // Determine whether the set of unexpanded parameter packs can and should
2518 // be expanded.
2519 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002520 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002521 llvm::Optional<unsigned> OrigNumExpansions
2522 = Expansion->getNumExpansions();
2523 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002524 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2525 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002526 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002527 Expand, RetainExpansion,
2528 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002529 return true;
2530
2531 if (!Expand) {
2532 // The transform has determined that we should perform a simple
2533 // transformation on the pack expansion, producing another pack
2534 // expansion.
2535 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2536 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2537 if (OutPattern.isInvalid())
2538 return true;
2539
2540 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002541 Expansion->getEllipsisLoc(),
2542 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002543 if (Out.isInvalid())
2544 return true;
2545
2546 if (ArgChanged)
2547 *ArgChanged = true;
2548 Outputs.push_back(Out.get());
2549 continue;
2550 }
John McCallc8fc90a2011-07-06 07:30:07 +00002551
2552 // Record right away that the argument was changed. This needs
2553 // to happen even if the array expands to nothing.
2554 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002555
2556 // The transform has determined that we should perform an elementwise
2557 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002558 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002559 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2560 ExprResult Out = getDerived().TransformExpr(Pattern);
2561 if (Out.isInvalid())
2562 return true;
2563
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002564 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002565 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2566 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002567 if (Out.isInvalid())
2568 return true;
2569 }
2570
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002571 Outputs.push_back(Out.get());
2572 }
2573
2574 continue;
2575 }
2576
Douglas Gregoraa165f82011-01-03 19:04:46 +00002577 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2578 if (Result.isInvalid())
2579 return true;
2580
2581 if (Result.get() != Inputs[I] && ArgChanged)
2582 *ArgChanged = true;
2583
2584 Outputs.push_back(Result.get());
2585 }
2586
2587 return false;
2588}
2589
2590template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002591NestedNameSpecifierLoc
2592TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2593 NestedNameSpecifierLoc NNS,
2594 QualType ObjectType,
2595 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002596 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002597 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2598 Qualifier = Qualifier.getPrefix())
2599 Qualifiers.push_back(Qualifier);
2600
2601 CXXScopeSpec SS;
2602 while (!Qualifiers.empty()) {
2603 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2604 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2605
2606 switch (QNNS->getKind()) {
2607 case NestedNameSpecifier::Identifier:
2608 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2609 *QNNS->getAsIdentifier(),
2610 Q.getLocalBeginLoc(),
2611 Q.getLocalEndLoc(),
2612 ObjectType, false, SS,
2613 FirstQualifierInScope, false))
2614 return NestedNameSpecifierLoc();
2615
2616 break;
2617
2618 case NestedNameSpecifier::Namespace: {
2619 NamespaceDecl *NS
2620 = cast_or_null<NamespaceDecl>(
2621 getDerived().TransformDecl(
2622 Q.getLocalBeginLoc(),
2623 QNNS->getAsNamespace()));
2624 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2625 break;
2626 }
2627
2628 case NestedNameSpecifier::NamespaceAlias: {
2629 NamespaceAliasDecl *Alias
2630 = cast_or_null<NamespaceAliasDecl>(
2631 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2632 QNNS->getAsNamespaceAlias()));
2633 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2634 Q.getLocalEndLoc());
2635 break;
2636 }
2637
2638 case NestedNameSpecifier::Global:
2639 // There is no meaningful transformation that one could perform on the
2640 // global scope.
2641 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2642 break;
2643
2644 case NestedNameSpecifier::TypeSpecWithTemplate:
2645 case NestedNameSpecifier::TypeSpec: {
2646 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2647 FirstQualifierInScope, SS);
2648
2649 if (!TL)
2650 return NestedNameSpecifierLoc();
2651
2652 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2653 (SemaRef.getLangOptions().CPlusPlus0x &&
2654 TL.getType()->isEnumeralType())) {
2655 assert(!TL.getType().hasLocalQualifiers() &&
2656 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002657 if (TL.getType()->isEnumeralType())
2658 SemaRef.Diag(TL.getBeginLoc(),
2659 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002660 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2661 Q.getLocalEndLoc());
2662 break;
2663 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002664 // If the nested-name-specifier is an invalid type def, don't emit an
2665 // error because a previous error should have already been emitted.
2666 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2667 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2668 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2669 << TL.getType() << SS.getRange();
2670 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002671 return NestedNameSpecifierLoc();
2672 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002673 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002674
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002675 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002676 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002677 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002678 }
2679
2680 // Don't rebuild the nested-name-specifier if we don't have to.
2681 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2682 !getDerived().AlwaysRebuild())
2683 return NNS;
2684
2685 // If we can re-use the source-location data from the original
2686 // nested-name-specifier, do so.
2687 if (SS.location_size() == NNS.getDataLength() &&
2688 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2689 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2690
2691 // Allocate new nested-name-specifier location information.
2692 return SS.getWithLocInContext(SemaRef.Context);
2693}
2694
2695template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002696DeclarationNameInfo
2697TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002698::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002699 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002700 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002701 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002702
2703 switch (Name.getNameKind()) {
2704 case DeclarationName::Identifier:
2705 case DeclarationName::ObjCZeroArgSelector:
2706 case DeclarationName::ObjCOneArgSelector:
2707 case DeclarationName::ObjCMultiArgSelector:
2708 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002709 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002710 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002711 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002712
Douglas Gregor81499bb2009-09-03 22:13:48 +00002713 case DeclarationName::CXXConstructorName:
2714 case DeclarationName::CXXDestructorName:
2715 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002716 TypeSourceInfo *NewTInfo;
2717 CanQualType NewCanTy;
2718 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002719 NewTInfo = getDerived().TransformType(OldTInfo);
2720 if (!NewTInfo)
2721 return DeclarationNameInfo();
2722 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002723 }
2724 else {
2725 NewTInfo = 0;
2726 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002727 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002728 if (NewT.isNull())
2729 return DeclarationNameInfo();
2730 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2731 }
Mike Stump1eb44332009-09-09 15:08:12 +00002732
Abramo Bagnara25777432010-08-11 22:01:17 +00002733 DeclarationName NewName
2734 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2735 NewCanTy);
2736 DeclarationNameInfo NewNameInfo(NameInfo);
2737 NewNameInfo.setName(NewName);
2738 NewNameInfo.setNamedTypeInfo(NewTInfo);
2739 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002740 }
Mike Stump1eb44332009-09-09 15:08:12 +00002741 }
2742
David Blaikieb219cfc2011-09-23 05:06:16 +00002743 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002744}
2745
2746template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002747TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002748TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2749 TemplateName Name,
2750 SourceLocation NameLoc,
2751 QualType ObjectType,
2752 NamedDecl *FirstQualifierInScope) {
2753 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2754 TemplateDecl *Template = QTN->getTemplateDecl();
2755 assert(Template && "qualified template name must refer to a template");
2756
2757 TemplateDecl *TransTemplate
2758 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2759 Template));
2760 if (!TransTemplate)
2761 return TemplateName();
2762
2763 if (!getDerived().AlwaysRebuild() &&
2764 SS.getScopeRep() == QTN->getQualifier() &&
2765 TransTemplate == Template)
2766 return Name;
2767
2768 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2769 TransTemplate);
2770 }
2771
2772 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2773 if (SS.getScopeRep()) {
2774 // These apply to the scope specifier, not the template.
2775 ObjectType = QualType();
2776 FirstQualifierInScope = 0;
2777 }
2778
2779 if (!getDerived().AlwaysRebuild() &&
2780 SS.getScopeRep() == DTN->getQualifier() &&
2781 ObjectType.isNull())
2782 return Name;
2783
2784 if (DTN->isIdentifier()) {
2785 return getDerived().RebuildTemplateName(SS,
2786 *DTN->getIdentifier(),
2787 NameLoc,
2788 ObjectType,
2789 FirstQualifierInScope);
2790 }
2791
2792 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2793 ObjectType);
2794 }
2795
2796 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2797 TemplateDecl *TransTemplate
2798 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2799 Template));
2800 if (!TransTemplate)
2801 return TemplateName();
2802
2803 if (!getDerived().AlwaysRebuild() &&
2804 TransTemplate == Template)
2805 return Name;
2806
2807 return TemplateName(TransTemplate);
2808 }
2809
2810 if (SubstTemplateTemplateParmPackStorage *SubstPack
2811 = Name.getAsSubstTemplateTemplateParmPack()) {
2812 TemplateTemplateParmDecl *TransParam
2813 = cast_or_null<TemplateTemplateParmDecl>(
2814 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2815 if (!TransParam)
2816 return TemplateName();
2817
2818 if (!getDerived().AlwaysRebuild() &&
2819 TransParam == SubstPack->getParameterPack())
2820 return Name;
2821
2822 return getDerived().RebuildTemplateName(TransParam,
2823 SubstPack->getArgumentPack());
2824 }
2825
2826 // These should be getting filtered out before they reach the AST.
2827 llvm_unreachable("overloaded function decl survived to here");
2828 return TemplateName();
2829}
2830
2831template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002832void TreeTransform<Derived>::InventTemplateArgumentLoc(
2833 const TemplateArgument &Arg,
2834 TemplateArgumentLoc &Output) {
2835 SourceLocation Loc = getDerived().getBaseLocation();
2836 switch (Arg.getKind()) {
2837 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002838 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002839 break;
2840
2841 case TemplateArgument::Type:
2842 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002843 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002844
John McCall833ca992009-10-29 08:12:44 +00002845 break;
2846
Douglas Gregor788cd062009-11-11 01:00:40 +00002847 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002848 case TemplateArgument::TemplateExpansion: {
2849 NestedNameSpecifierLocBuilder Builder;
2850 TemplateName Template = Arg.getAsTemplate();
2851 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2852 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2853 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2854 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2855
2856 if (Arg.getKind() == TemplateArgument::Template)
2857 Output = TemplateArgumentLoc(Arg,
2858 Builder.getWithLocInContext(SemaRef.Context),
2859 Loc);
2860 else
2861 Output = TemplateArgumentLoc(Arg,
2862 Builder.getWithLocInContext(SemaRef.Context),
2863 Loc, Loc);
2864
Douglas Gregor788cd062009-11-11 01:00:40 +00002865 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002866 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002867
John McCall833ca992009-10-29 08:12:44 +00002868 case TemplateArgument::Expression:
2869 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2870 break;
2871
2872 case TemplateArgument::Declaration:
2873 case TemplateArgument::Integral:
2874 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002875 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002876 break;
2877 }
2878}
2879
2880template<typename Derived>
2881bool TreeTransform<Derived>::TransformTemplateArgument(
2882 const TemplateArgumentLoc &Input,
2883 TemplateArgumentLoc &Output) {
2884 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002885 switch (Arg.getKind()) {
2886 case TemplateArgument::Null:
2887 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002888 Output = Input;
2889 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002890
Douglas Gregor670444e2009-08-04 22:27:00 +00002891 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002892 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002893 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002894 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002895
2896 DI = getDerived().TransformType(DI);
2897 if (!DI) return true;
2898
2899 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2900 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002901 }
Mike Stump1eb44332009-09-09 15:08:12 +00002902
Douglas Gregor670444e2009-08-04 22:27:00 +00002903 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002904 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002905 DeclarationName Name;
2906 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2907 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002908 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002909 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002910 if (!D) return true;
2911
John McCall828bff22009-10-29 18:45:58 +00002912 Expr *SourceExpr = Input.getSourceDeclExpression();
2913 if (SourceExpr) {
2914 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002915 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002916 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002917 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002918 }
2919
2920 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002921 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002922 }
Mike Stump1eb44332009-09-09 15:08:12 +00002923
Douglas Gregor788cd062009-11-11 01:00:40 +00002924 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002925 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2926 if (QualifierLoc) {
2927 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2928 if (!QualifierLoc)
2929 return true;
2930 }
2931
Douglas Gregor1d752d72011-03-02 18:46:51 +00002932 CXXScopeSpec SS;
2933 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002934 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002935 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2936 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002937 if (Template.isNull())
2938 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002939
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002940 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002941 Input.getTemplateNameLoc());
2942 return false;
2943 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002944
2945 case TemplateArgument::TemplateExpansion:
2946 llvm_unreachable("Caller should expand pack expansions");
2947
Douglas Gregor670444e2009-08-04 22:27:00 +00002948 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00002949 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00002950 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002951 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002952
John McCall833ca992009-10-29 08:12:44 +00002953 Expr *InputExpr = Input.getSourceExpression();
2954 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2955
Chris Lattner223de242011-04-25 20:37:58 +00002956 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall833ca992009-10-29 08:12:44 +00002957 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002958 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002959 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002960 }
Mike Stump1eb44332009-09-09 15:08:12 +00002961
Douglas Gregor670444e2009-08-04 22:27:00 +00002962 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00002963 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00002964 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002965 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002966 AEnd = Arg.pack_end();
2967 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002968
John McCall833ca992009-10-29 08:12:44 +00002969 // FIXME: preserve source information here when we start
2970 // caring about parameter packs.
2971
John McCall828bff22009-10-29 18:45:58 +00002972 TemplateArgumentLoc InputArg;
2973 TemplateArgumentLoc OutputArg;
2974 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2975 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002976 return true;
2977
John McCall828bff22009-10-29 18:45:58 +00002978 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002979 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002980
2981 TemplateArgument *TransformedArgsPtr
2982 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2983 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2984 TransformedArgsPtr);
2985 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2986 TransformedArgs.size()),
2987 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002988 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002989 }
2990 }
Mike Stump1eb44332009-09-09 15:08:12 +00002991
Douglas Gregor670444e2009-08-04 22:27:00 +00002992 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002993 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002994}
2995
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002996/// \brief Iterator adaptor that invents template argument location information
2997/// for each of the template arguments in its underlying iterator.
2998template<typename Derived, typename InputIterator>
2999class TemplateArgumentLocInventIterator {
3000 TreeTransform<Derived> &Self;
3001 InputIterator Iter;
3002
3003public:
3004 typedef TemplateArgumentLoc value_type;
3005 typedef TemplateArgumentLoc reference;
3006 typedef typename std::iterator_traits<InputIterator>::difference_type
3007 difference_type;
3008 typedef std::input_iterator_tag iterator_category;
3009
3010 class pointer {
3011 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003012
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003013 public:
3014 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3015
3016 const TemplateArgumentLoc *operator->() const { return &Arg; }
3017 };
3018
3019 TemplateArgumentLocInventIterator() { }
3020
3021 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3022 InputIterator Iter)
3023 : Self(Self), Iter(Iter) { }
3024
3025 TemplateArgumentLocInventIterator &operator++() {
3026 ++Iter;
3027 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003028 }
3029
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003030 TemplateArgumentLocInventIterator operator++(int) {
3031 TemplateArgumentLocInventIterator Old(*this);
3032 ++(*this);
3033 return Old;
3034 }
3035
3036 reference operator*() const {
3037 TemplateArgumentLoc Result;
3038 Self.InventTemplateArgumentLoc(*Iter, Result);
3039 return Result;
3040 }
3041
3042 pointer operator->() const { return pointer(**this); }
3043
3044 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3045 const TemplateArgumentLocInventIterator &Y) {
3046 return X.Iter == Y.Iter;
3047 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003048
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003049 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3050 const TemplateArgumentLocInventIterator &Y) {
3051 return X.Iter != Y.Iter;
3052 }
3053};
3054
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003055template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003056template<typename InputIterator>
3057bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3058 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003059 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003060 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003061 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003062 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003063
3064 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3065 // Unpack argument packs, which we translate them into separate
3066 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003067 // FIXME: We could do much better if we could guarantee that the
3068 // TemplateArgumentLocInfo for the pack expansion would be usable for
3069 // all of the template arguments in the argument pack.
3070 typedef TemplateArgumentLocInventIterator<Derived,
3071 TemplateArgument::pack_iterator>
3072 PackLocIterator;
3073 if (TransformTemplateArguments(PackLocIterator(*this,
3074 In.getArgument().pack_begin()),
3075 PackLocIterator(*this,
3076 In.getArgument().pack_end()),
3077 Outputs))
3078 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003079
3080 continue;
3081 }
3082
3083 if (In.getArgument().isPackExpansion()) {
3084 // We have a pack expansion, for which we will be substituting into
3085 // the pattern.
3086 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003087 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003088 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003089 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3090 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003091
Chris Lattner686775d2011-07-20 06:58:45 +00003092 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003093 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3094 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3095
3096 // Determine whether the set of unexpanded parameter packs can and should
3097 // be expanded.
3098 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003099 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003100 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003101 if (getDerived().TryExpandParameterPacks(Ellipsis,
3102 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003103 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003104 Expand,
3105 RetainExpansion,
3106 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003107 return true;
3108
3109 if (!Expand) {
3110 // The transform has determined that we should perform a simple
3111 // transformation on the pack expansion, producing another pack
3112 // expansion.
3113 TemplateArgumentLoc OutPattern;
3114 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3115 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3116 return true;
3117
Douglas Gregorcded4f62011-01-14 17:04:44 +00003118 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3119 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003120 if (Out.getArgument().isNull())
3121 return true;
3122
3123 Outputs.addArgument(Out);
3124 continue;
3125 }
3126
3127 // The transform has determined that we should perform an elementwise
3128 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003129 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003130 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3131
3132 if (getDerived().TransformTemplateArgument(Pattern, Out))
3133 return true;
3134
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003135 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003136 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3137 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003138 if (Out.getArgument().isNull())
3139 return true;
3140 }
3141
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003142 Outputs.addArgument(Out);
3143 }
3144
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003145 // If we're supposed to retain a pack expansion, do so by temporarily
3146 // forgetting the partially-substituted parameter pack.
3147 if (RetainExpansion) {
3148 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3149
3150 if (getDerived().TransformTemplateArgument(Pattern, Out))
3151 return true;
3152
Douglas Gregorcded4f62011-01-14 17:04:44 +00003153 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3154 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003155 if (Out.getArgument().isNull())
3156 return true;
3157
3158 Outputs.addArgument(Out);
3159 }
Douglas Gregord3731192011-01-10 07:32:04 +00003160
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003161 continue;
3162 }
3163
3164 // The simple case:
3165 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003166 return true;
3167
3168 Outputs.addArgument(Out);
3169 }
3170
3171 return false;
3172
3173}
3174
Douglas Gregor577f75a2009-08-04 16:50:30 +00003175//===----------------------------------------------------------------------===//
3176// Type transformation
3177//===----------------------------------------------------------------------===//
3178
3179template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003180QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003181 if (getDerived().AlreadyTransformed(T))
3182 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003183
John McCalla2becad2009-10-21 00:40:46 +00003184 // Temporary workaround. All of these transformations should
3185 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003186 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3187 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003188
John McCall43fed0d2010-11-12 08:19:04 +00003189 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003190
John McCalla2becad2009-10-21 00:40:46 +00003191 if (!NewDI)
3192 return QualType();
3193
3194 return NewDI->getType();
3195}
3196
3197template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003198TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003199 // Refine the base location to the type's location.
3200 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3201 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003202 if (getDerived().AlreadyTransformed(DI->getType()))
3203 return DI;
3204
3205 TypeLocBuilder TLB;
3206
3207 TypeLoc TL = DI->getTypeLoc();
3208 TLB.reserve(TL.getFullDataSize());
3209
John McCall43fed0d2010-11-12 08:19:04 +00003210 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003211 if (Result.isNull())
3212 return 0;
3213
John McCalla93c9342009-12-07 02:54:59 +00003214 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003215}
3216
3217template<typename Derived>
3218QualType
John McCall43fed0d2010-11-12 08:19:04 +00003219TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003220 switch (T.getTypeLocClass()) {
3221#define ABSTRACT_TYPELOC(CLASS, PARENT)
3222#define TYPELOC(CLASS, PARENT) \
3223 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003224 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003225#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003226 }
Mike Stump1eb44332009-09-09 15:08:12 +00003227
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003228 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003229 return QualType();
3230}
3231
3232/// FIXME: By default, this routine adds type qualifiers only to types
3233/// that can have qualifiers, and silently suppresses those qualifiers
3234/// that are not permitted (e.g., qualifiers on reference or function
3235/// types). This is the right thing for template instantiation, but
3236/// probably not for other clients.
3237template<typename Derived>
3238QualType
3239TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003240 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003241 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003242
John McCall43fed0d2010-11-12 08:19:04 +00003243 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003244 if (Result.isNull())
3245 return QualType();
3246
3247 // Silently suppress qualifiers if the result type can't be qualified.
3248 // FIXME: this is the right thing for template instantiation, but
3249 // probably not for other clients.
3250 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003251 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003252
John McCallf85e1932011-06-15 23:02:42 +00003253 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003254 // resulting type.
3255 if (Quals.hasObjCLifetime()) {
3256 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3257 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003258 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003259 // Objective-C ARC:
3260 // A lifetime qualifier applied to a substituted template parameter
3261 // overrides the lifetime qualifier from the template argument.
3262 if (const SubstTemplateTypeParmType *SubstTypeParam
3263 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3264 QualType Replacement = SubstTypeParam->getReplacementType();
3265 Qualifiers Qs = Replacement.getQualifiers();
3266 Qs.removeObjCLifetime();
3267 Replacement
3268 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3269 Qs);
3270 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3271 SubstTypeParam->getReplacedParameter(),
3272 Replacement);
3273 TLB.TypeWasModifiedSafely(Result);
3274 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003275 // Otherwise, complain about the addition of a qualifier to an
3276 // already-qualified type.
3277 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003278 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003279 << Result << R;
3280
Douglas Gregore559ca12011-06-17 22:11:49 +00003281 Quals.removeObjCLifetime();
3282 }
3283 }
3284 }
John McCall28654742010-06-05 06:41:15 +00003285 if (!Quals.empty()) {
3286 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3287 TLB.push<QualifiedTypeLoc>(Result);
3288 // No location information to preserve.
3289 }
John McCalla2becad2009-10-21 00:40:46 +00003290
3291 return Result;
3292}
3293
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003294template<typename Derived>
3295TypeLoc
3296TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3297 QualType ObjectType,
3298 NamedDecl *UnqualLookup,
3299 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003300 QualType T = TL.getType();
3301 if (getDerived().AlreadyTransformed(T))
3302 return TL;
3303
3304 TypeLocBuilder TLB;
3305 QualType Result;
3306
3307 if (isa<TemplateSpecializationType>(T)) {
3308 TemplateSpecializationTypeLoc SpecTL
3309 = cast<TemplateSpecializationTypeLoc>(TL);
3310
3311 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003312 getDerived().TransformTemplateName(SS,
3313 SpecTL.getTypePtr()->getTemplateName(),
3314 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003315 ObjectType, UnqualLookup);
3316 if (Template.isNull())
3317 return TypeLoc();
3318
3319 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3320 Template);
3321 } else if (isa<DependentTemplateSpecializationType>(T)) {
3322 DependentTemplateSpecializationTypeLoc SpecTL
3323 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3324
Douglas Gregora88f09f2011-02-28 17:23:35 +00003325 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003326 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003327 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003328 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003329 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003330 if (Template.isNull())
3331 return TypeLoc();
3332
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003333 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003334 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003335 Template,
3336 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003337 } else {
3338 // Nothing special needs to be done for these.
3339 Result = getDerived().TransformType(TLB, TL);
3340 }
3341
3342 if (Result.isNull())
3343 return TypeLoc();
3344
3345 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3346}
3347
Douglas Gregorb71d8212011-03-02 18:32:08 +00003348template<typename Derived>
3349TypeSourceInfo *
3350TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3351 QualType ObjectType,
3352 NamedDecl *UnqualLookup,
3353 CXXScopeSpec &SS) {
3354 // FIXME: Painfully copy-paste from the above!
3355
3356 QualType T = TSInfo->getType();
3357 if (getDerived().AlreadyTransformed(T))
3358 return TSInfo;
3359
3360 TypeLocBuilder TLB;
3361 QualType Result;
3362
3363 TypeLoc TL = TSInfo->getTypeLoc();
3364 if (isa<TemplateSpecializationType>(T)) {
3365 TemplateSpecializationTypeLoc SpecTL
3366 = cast<TemplateSpecializationTypeLoc>(TL);
3367
3368 TemplateName Template
3369 = getDerived().TransformTemplateName(SS,
3370 SpecTL.getTypePtr()->getTemplateName(),
3371 SpecTL.getTemplateNameLoc(),
3372 ObjectType, UnqualLookup);
3373 if (Template.isNull())
3374 return 0;
3375
3376 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3377 Template);
3378 } else if (isa<DependentTemplateSpecializationType>(T)) {
3379 DependentTemplateSpecializationTypeLoc SpecTL
3380 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3381
3382 TemplateName Template
3383 = getDerived().RebuildTemplateName(SS,
3384 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003385 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003386 ObjectType, UnqualLookup);
3387 if (Template.isNull())
3388 return 0;
3389
3390 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3391 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003392 Template,
3393 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003394 } else {
3395 // Nothing special needs to be done for these.
3396 Result = getDerived().TransformType(TLB, TL);
3397 }
3398
3399 if (Result.isNull())
3400 return 0;
3401
3402 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3403}
3404
John McCalla2becad2009-10-21 00:40:46 +00003405template <class TyLoc> static inline
3406QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3407 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3408 NewT.setNameLoc(T.getNameLoc());
3409 return T.getType();
3410}
3411
John McCalla2becad2009-10-21 00:40:46 +00003412template<typename Derived>
3413QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003414 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003415 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3416 NewT.setBuiltinLoc(T.getBuiltinLoc());
3417 if (T.needsExtraLocalData())
3418 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3419 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003420}
Mike Stump1eb44332009-09-09 15:08:12 +00003421
Douglas Gregor577f75a2009-08-04 16:50:30 +00003422template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003423QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003424 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003425 // FIXME: recurse?
3426 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003427}
Mike Stump1eb44332009-09-09 15:08:12 +00003428
Douglas Gregor577f75a2009-08-04 16:50:30 +00003429template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003430QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003431 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003432 QualType PointeeType
3433 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003434 if (PointeeType.isNull())
3435 return QualType();
3436
3437 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003438 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003439 // A dependent pointer type 'T *' has is being transformed such
3440 // that an Objective-C class type is being replaced for 'T'. The
3441 // resulting pointer type is an ObjCObjectPointerType, not a
3442 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003443 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003444
John McCallc12c5bb2010-05-15 11:32:37 +00003445 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3446 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003447 return Result;
3448 }
John McCall43fed0d2010-11-12 08:19:04 +00003449
Douglas Gregor92e986e2010-04-22 16:44:27 +00003450 if (getDerived().AlwaysRebuild() ||
3451 PointeeType != TL.getPointeeLoc().getType()) {
3452 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3453 if (Result.isNull())
3454 return QualType();
3455 }
John McCallf85e1932011-06-15 23:02:42 +00003456
3457 // Objective-C ARC can add lifetime qualifiers to the type that we're
3458 // pointing to.
3459 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3460
Douglas Gregor92e986e2010-04-22 16:44:27 +00003461 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3462 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003463 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003464}
Mike Stump1eb44332009-09-09 15:08:12 +00003465
3466template<typename Derived>
3467QualType
John McCalla2becad2009-10-21 00:40:46 +00003468TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003469 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003470 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003471 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3472 if (PointeeType.isNull())
3473 return QualType();
3474
3475 QualType Result = TL.getType();
3476 if (getDerived().AlwaysRebuild() ||
3477 PointeeType != TL.getPointeeLoc().getType()) {
3478 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003479 TL.getSigilLoc());
3480 if (Result.isNull())
3481 return QualType();
3482 }
3483
Douglas Gregor39968ad2010-04-22 16:50:51 +00003484 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003485 NewT.setSigilLoc(TL.getSigilLoc());
3486 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003487}
3488
John McCall85737a72009-10-30 00:06:24 +00003489/// Transforms a reference type. Note that somewhat paradoxically we
3490/// don't care whether the type itself is an l-value type or an r-value
3491/// type; we only care if the type was *written* as an l-value type
3492/// or an r-value type.
3493template<typename Derived>
3494QualType
3495TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003496 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003497 const ReferenceType *T = TL.getTypePtr();
3498
3499 // Note that this works with the pointee-as-written.
3500 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3501 if (PointeeType.isNull())
3502 return QualType();
3503
3504 QualType Result = TL.getType();
3505 if (getDerived().AlwaysRebuild() ||
3506 PointeeType != T->getPointeeTypeAsWritten()) {
3507 Result = getDerived().RebuildReferenceType(PointeeType,
3508 T->isSpelledAsLValue(),
3509 TL.getSigilLoc());
3510 if (Result.isNull())
3511 return QualType();
3512 }
3513
John McCallf85e1932011-06-15 23:02:42 +00003514 // Objective-C ARC can add lifetime qualifiers to the type that we're
3515 // referring to.
3516 TLB.TypeWasModifiedSafely(
3517 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3518
John McCall85737a72009-10-30 00:06:24 +00003519 // r-value references can be rebuilt as l-value references.
3520 ReferenceTypeLoc NewTL;
3521 if (isa<LValueReferenceType>(Result))
3522 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3523 else
3524 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3525 NewTL.setSigilLoc(TL.getSigilLoc());
3526
3527 return Result;
3528}
3529
Mike Stump1eb44332009-09-09 15:08:12 +00003530template<typename Derived>
3531QualType
John McCalla2becad2009-10-21 00:40:46 +00003532TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003533 LValueReferenceTypeLoc TL) {
3534 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003535}
3536
Mike Stump1eb44332009-09-09 15:08:12 +00003537template<typename Derived>
3538QualType
John McCalla2becad2009-10-21 00:40:46 +00003539TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003540 RValueReferenceTypeLoc TL) {
3541 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003542}
Mike Stump1eb44332009-09-09 15:08:12 +00003543
Douglas Gregor577f75a2009-08-04 16:50:30 +00003544template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003545QualType
John McCalla2becad2009-10-21 00:40:46 +00003546TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003547 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003548 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003549 if (PointeeType.isNull())
3550 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003551
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003552 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3553 TypeSourceInfo* NewClsTInfo = 0;
3554 if (OldClsTInfo) {
3555 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3556 if (!NewClsTInfo)
3557 return QualType();
3558 }
3559
3560 const MemberPointerType *T = TL.getTypePtr();
3561 QualType OldClsType = QualType(T->getClass(), 0);
3562 QualType NewClsType;
3563 if (NewClsTInfo)
3564 NewClsType = NewClsTInfo->getType();
3565 else {
3566 NewClsType = getDerived().TransformType(OldClsType);
3567 if (NewClsType.isNull())
3568 return QualType();
3569 }
Mike Stump1eb44332009-09-09 15:08:12 +00003570
John McCalla2becad2009-10-21 00:40:46 +00003571 QualType Result = TL.getType();
3572 if (getDerived().AlwaysRebuild() ||
3573 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003574 NewClsType != OldClsType) {
3575 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003576 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003577 if (Result.isNull())
3578 return QualType();
3579 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003580
John McCalla2becad2009-10-21 00:40:46 +00003581 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3582 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003583 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003584
3585 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003586}
3587
Mike Stump1eb44332009-09-09 15:08:12 +00003588template<typename Derived>
3589QualType
John McCalla2becad2009-10-21 00:40:46 +00003590TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003591 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003592 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003593 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003594 if (ElementType.isNull())
3595 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003596
John McCalla2becad2009-10-21 00:40:46 +00003597 QualType Result = TL.getType();
3598 if (getDerived().AlwaysRebuild() ||
3599 ElementType != T->getElementType()) {
3600 Result = getDerived().RebuildConstantArrayType(ElementType,
3601 T->getSizeModifier(),
3602 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003603 T->getIndexTypeCVRQualifiers(),
3604 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003605 if (Result.isNull())
3606 return QualType();
3607 }
Eli Friedman457a3772012-01-25 22:19:07 +00003608
3609 // We might have either a ConstantArrayType or a VariableArrayType now:
3610 // a ConstantArrayType is allowed to have an element type which is a
3611 // VariableArrayType if the type is dependent. Fortunately, all array
3612 // types have the same location layout.
3613 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003614 NewTL.setLBracketLoc(TL.getLBracketLoc());
3615 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003616
John McCalla2becad2009-10-21 00:40:46 +00003617 Expr *Size = TL.getSizeExpr();
3618 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003619 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3620 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003621 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3622 }
3623 NewTL.setSizeExpr(Size);
3624
3625 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003626}
Mike Stump1eb44332009-09-09 15:08:12 +00003627
Douglas Gregor577f75a2009-08-04 16:50:30 +00003628template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003629QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003630 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003631 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003632 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003633 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003634 if (ElementType.isNull())
3635 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003636
John McCalla2becad2009-10-21 00:40:46 +00003637 QualType Result = TL.getType();
3638 if (getDerived().AlwaysRebuild() ||
3639 ElementType != T->getElementType()) {
3640 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003641 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003642 T->getIndexTypeCVRQualifiers(),
3643 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003644 if (Result.isNull())
3645 return QualType();
3646 }
Sean Huntc3021132010-05-05 15:23:54 +00003647
John McCalla2becad2009-10-21 00:40:46 +00003648 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3649 NewTL.setLBracketLoc(TL.getLBracketLoc());
3650 NewTL.setRBracketLoc(TL.getRBracketLoc());
3651 NewTL.setSizeExpr(0);
3652
3653 return Result;
3654}
3655
3656template<typename Derived>
3657QualType
3658TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003659 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003660 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003661 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3662 if (ElementType.isNull())
3663 return QualType();
3664
John McCall60d7b3a2010-08-24 06:29:42 +00003665 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003666 = getDerived().TransformExpr(T->getSizeExpr());
3667 if (SizeResult.isInvalid())
3668 return QualType();
3669
John McCall9ae2f072010-08-23 23:25:46 +00003670 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003671
3672 QualType Result = TL.getType();
3673 if (getDerived().AlwaysRebuild() ||
3674 ElementType != T->getElementType() ||
3675 Size != T->getSizeExpr()) {
3676 Result = getDerived().RebuildVariableArrayType(ElementType,
3677 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003678 Size,
John McCalla2becad2009-10-21 00:40:46 +00003679 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003680 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003681 if (Result.isNull())
3682 return QualType();
3683 }
Sean Huntc3021132010-05-05 15:23:54 +00003684
John McCalla2becad2009-10-21 00:40:46 +00003685 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3686 NewTL.setLBracketLoc(TL.getLBracketLoc());
3687 NewTL.setRBracketLoc(TL.getRBracketLoc());
3688 NewTL.setSizeExpr(Size);
3689
3690 return Result;
3691}
3692
3693template<typename Derived>
3694QualType
3695TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003696 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003697 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003698 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3699 if (ElementType.isNull())
3700 return QualType();
3701
Richard Smithf6702a32011-12-20 02:08:33 +00003702 // Array bounds are constant expressions.
3703 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3704 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003705
John McCall3b657512011-01-19 10:06:00 +00003706 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3707 Expr *origSize = TL.getSizeExpr();
3708 if (!origSize) origSize = T->getSizeExpr();
3709
3710 ExprResult sizeResult
3711 = getDerived().TransformExpr(origSize);
3712 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003713 return QualType();
3714
John McCall3b657512011-01-19 10:06:00 +00003715 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003716
3717 QualType Result = TL.getType();
3718 if (getDerived().AlwaysRebuild() ||
3719 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003720 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003721 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3722 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003723 size,
John McCalla2becad2009-10-21 00:40:46 +00003724 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003725 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003726 if (Result.isNull())
3727 return QualType();
3728 }
John McCalla2becad2009-10-21 00:40:46 +00003729
3730 // We might have any sort of array type now, but fortunately they
3731 // all have the same location layout.
3732 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3733 NewTL.setLBracketLoc(TL.getLBracketLoc());
3734 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003735 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003736
3737 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003738}
Mike Stump1eb44332009-09-09 15:08:12 +00003739
3740template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003741QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003742 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003743 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003744 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003745
3746 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003747 QualType ElementType = getDerived().TransformType(T->getElementType());
3748 if (ElementType.isNull())
3749 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003750
Richard Smithf6702a32011-12-20 02:08:33 +00003751 // Vector sizes are constant expressions.
3752 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3753 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003754
John McCall60d7b3a2010-08-24 06:29:42 +00003755 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003756 if (Size.isInvalid())
3757 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003758
John McCalla2becad2009-10-21 00:40:46 +00003759 QualType Result = TL.getType();
3760 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003761 ElementType != T->getElementType() ||
3762 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003763 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003764 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003765 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003766 if (Result.isNull())
3767 return QualType();
3768 }
John McCalla2becad2009-10-21 00:40:46 +00003769
3770 // Result might be dependent or not.
3771 if (isa<DependentSizedExtVectorType>(Result)) {
3772 DependentSizedExtVectorTypeLoc NewTL
3773 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3774 NewTL.setNameLoc(TL.getNameLoc());
3775 } else {
3776 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3777 NewTL.setNameLoc(TL.getNameLoc());
3778 }
3779
3780 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003781}
Mike Stump1eb44332009-09-09 15:08:12 +00003782
3783template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003784QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003785 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003786 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003787 QualType ElementType = getDerived().TransformType(T->getElementType());
3788 if (ElementType.isNull())
3789 return QualType();
3790
John McCalla2becad2009-10-21 00:40:46 +00003791 QualType Result = TL.getType();
3792 if (getDerived().AlwaysRebuild() ||
3793 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003794 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003795 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003796 if (Result.isNull())
3797 return QualType();
3798 }
Sean Huntc3021132010-05-05 15:23:54 +00003799
John McCalla2becad2009-10-21 00:40:46 +00003800 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3801 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003802
John McCalla2becad2009-10-21 00:40:46 +00003803 return Result;
3804}
3805
3806template<typename Derived>
3807QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003808 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003809 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003810 QualType ElementType = getDerived().TransformType(T->getElementType());
3811 if (ElementType.isNull())
3812 return QualType();
3813
3814 QualType Result = TL.getType();
3815 if (getDerived().AlwaysRebuild() ||
3816 ElementType != T->getElementType()) {
3817 Result = getDerived().RebuildExtVectorType(ElementType,
3818 T->getNumElements(),
3819 /*FIXME*/ SourceLocation());
3820 if (Result.isNull())
3821 return QualType();
3822 }
Sean Huntc3021132010-05-05 15:23:54 +00003823
John McCalla2becad2009-10-21 00:40:46 +00003824 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3825 NewTL.setNameLoc(TL.getNameLoc());
3826
3827 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003828}
Mike Stump1eb44332009-09-09 15:08:12 +00003829
3830template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003831ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003832TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003833 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003834 llvm::Optional<unsigned> NumExpansions,
3835 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003836 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003837 TypeSourceInfo *NewDI = 0;
3838
3839 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3840 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003841 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003842 TypeLoc OldTL = OldDI->getTypeLoc();
3843 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3844
3845 TypeLocBuilder TLB;
3846 TypeLoc NewTL = OldDI->getTypeLoc();
3847 TLB.reserve(NewTL.getFullDataSize());
3848
3849 QualType Result = getDerived().TransformType(TLB,
3850 OldExpansionTL.getPatternLoc());
3851 if (Result.isNull())
3852 return 0;
3853
3854 Result = RebuildPackExpansionType(Result,
3855 OldExpansionTL.getPatternLoc().getSourceRange(),
3856 OldExpansionTL.getEllipsisLoc(),
3857 NumExpansions);
3858 if (Result.isNull())
3859 return 0;
3860
3861 PackExpansionTypeLoc NewExpansionTL
3862 = TLB.push<PackExpansionTypeLoc>(Result);
3863 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3864 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3865 } else
3866 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003867 if (!NewDI)
3868 return 0;
3869
John McCallfb44de92011-05-01 22:35:37 +00003870 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003871 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003872
3873 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3874 OldParm->getDeclContext(),
3875 OldParm->getInnerLocStart(),
3876 OldParm->getLocation(),
3877 OldParm->getIdentifier(),
3878 NewDI->getType(),
3879 NewDI,
3880 OldParm->getStorageClass(),
3881 OldParm->getStorageClassAsWritten(),
3882 /* DefArg */ NULL);
3883 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3884 OldParm->getFunctionScopeIndex() + indexAdjustment);
3885 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003886}
3887
3888template<typename Derived>
3889bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003890 TransformFunctionTypeParams(SourceLocation Loc,
3891 ParmVarDecl **Params, unsigned NumParams,
3892 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003893 SmallVectorImpl<QualType> &OutParamTypes,
3894 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003895 int indexAdjustment = 0;
3896
Douglas Gregora009b592011-01-07 00:20:55 +00003897 for (unsigned i = 0; i != NumParams; ++i) {
3898 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003899 assert(OldParm->getFunctionScopeIndex() == i);
3900
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003901 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003902 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003903 if (OldParm->isParameterPack()) {
3904 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003905 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003906
Douglas Gregor603cfb42011-01-05 23:12:31 +00003907 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003908 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3909 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3910 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3911 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003912 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3913
Douglas Gregor603cfb42011-01-05 23:12:31 +00003914 // Determine whether we should expand the parameter packs.
3915 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003916 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003917 llvm::Optional<unsigned> OrigNumExpansions
3918 = ExpansionTL.getTypePtr()->getNumExpansions();
3919 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003920 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3921 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003922 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003923 ShouldExpand,
3924 RetainExpansion,
3925 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003926 return true;
3927 }
3928
3929 if (ShouldExpand) {
3930 // Expand the function parameter pack into multiple, separate
3931 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003932 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003933 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003934 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3935 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003936 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003937 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003938 OrigNumExpansions,
3939 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003940 if (!NewParm)
3941 return true;
3942
Douglas Gregora009b592011-01-07 00:20:55 +00003943 OutParamTypes.push_back(NewParm->getType());
3944 if (PVars)
3945 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003946 }
Douglas Gregord3731192011-01-10 07:32:04 +00003947
3948 // If we're supposed to retain a pack expansion, do so by temporarily
3949 // forgetting the partially-substituted parameter pack.
3950 if (RetainExpansion) {
3951 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3952 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003953 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003954 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003955 OrigNumExpansions,
3956 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00003957 if (!NewParm)
3958 return true;
3959
3960 OutParamTypes.push_back(NewParm->getType());
3961 if (PVars)
3962 PVars->push_back(NewParm);
3963 }
3964
John McCallfb44de92011-05-01 22:35:37 +00003965 // The next parameter should have the same adjustment as the
3966 // last thing we pushed, but we post-incremented indexAdjustment
3967 // on every push. Also, if we push nothing, the adjustment should
3968 // go down by one.
3969 indexAdjustment--;
3970
Douglas Gregor603cfb42011-01-05 23:12:31 +00003971 // We're done with the pack expansion.
3972 continue;
3973 }
3974
3975 // We'll substitute the parameter now without expanding the pack
3976 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003977 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3978 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003979 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003980 NumExpansions,
3981 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003982 } else {
3983 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003984 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003985 llvm::Optional<unsigned>(),
3986 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003987 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003988
John McCall21ef0fa2010-03-11 09:03:00 +00003989 if (!NewParm)
3990 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003991
Douglas Gregora009b592011-01-07 00:20:55 +00003992 OutParamTypes.push_back(NewParm->getType());
3993 if (PVars)
3994 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003995 continue;
3996 }
John McCall21ef0fa2010-03-11 09:03:00 +00003997
3998 // Deal with the possibility that we don't have a parameter
3999 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004000 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004001 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004002 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004003 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004004 if (const PackExpansionType *Expansion
4005 = dyn_cast<PackExpansionType>(OldType)) {
4006 // We have a function parameter pack that may need to be expanded.
4007 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004008 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004009 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4010
4011 // Determine whether we should expand the parameter packs.
4012 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004013 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004014 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004015 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004016 ShouldExpand,
4017 RetainExpansion,
4018 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004019 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004020 }
4021
4022 if (ShouldExpand) {
4023 // Expand the function parameter pack into multiple, separate
4024 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004025 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004026 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4027 QualType NewType = getDerived().TransformType(Pattern);
4028 if (NewType.isNull())
4029 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004030
Douglas Gregora009b592011-01-07 00:20:55 +00004031 OutParamTypes.push_back(NewType);
4032 if (PVars)
4033 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004034 }
4035
4036 // We're done with the pack expansion.
4037 continue;
4038 }
4039
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004040 // If we're supposed to retain a pack expansion, do so by temporarily
4041 // forgetting the partially-substituted parameter pack.
4042 if (RetainExpansion) {
4043 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4044 QualType NewType = getDerived().TransformType(Pattern);
4045 if (NewType.isNull())
4046 return true;
4047
4048 OutParamTypes.push_back(NewType);
4049 if (PVars)
4050 PVars->push_back(0);
4051 }
Douglas Gregord3731192011-01-10 07:32:04 +00004052
Douglas Gregor603cfb42011-01-05 23:12:31 +00004053 // We'll substitute the parameter now without expanding the pack
4054 // expansion.
4055 OldType = Expansion->getPattern();
4056 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004057 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4058 NewType = getDerived().TransformType(OldType);
4059 } else {
4060 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004061 }
4062
Douglas Gregor603cfb42011-01-05 23:12:31 +00004063 if (NewType.isNull())
4064 return true;
4065
4066 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004067 NewType = getSema().Context.getPackExpansionType(NewType,
4068 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004069
Douglas Gregora009b592011-01-07 00:20:55 +00004070 OutParamTypes.push_back(NewType);
4071 if (PVars)
4072 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004073 }
4074
John McCallfb44de92011-05-01 22:35:37 +00004075#ifndef NDEBUG
4076 if (PVars) {
4077 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4078 if (ParmVarDecl *parm = (*PVars)[i])
4079 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004080 }
John McCallfb44de92011-05-01 22:35:37 +00004081#endif
4082
4083 return false;
4084}
John McCall21ef0fa2010-03-11 09:03:00 +00004085
4086template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004087QualType
John McCalla2becad2009-10-21 00:40:46 +00004088TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004089 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004090 // Transform the parameters and return type.
4091 //
4092 // We instantiate in source order, with the return type first followed by
4093 // the parameters, because users tend to expect this (even if they shouldn't
4094 // rely on it!).
4095 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004096 // When the function has a trailing return type, we instantiate the
4097 // parameters before the return type, since the return type can then refer
4098 // to the parameters themselves (via decltype, sizeof, etc.).
4099 //
Chris Lattner686775d2011-07-20 06:58:45 +00004100 SmallVector<QualType, 4> ParamTypes;
4101 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004102 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004103
Douglas Gregordab60ad2010-10-01 18:44:50 +00004104 QualType ResultType;
4105
4106 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004107 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4108 TL.getParmArray(),
4109 TL.getNumArgs(),
4110 TL.getTypePtr()->arg_type_begin(),
4111 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004112 return QualType();
4113
4114 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4115 if (ResultType.isNull())
4116 return QualType();
4117 }
4118 else {
4119 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4120 if (ResultType.isNull())
4121 return QualType();
4122
Douglas Gregora009b592011-01-07 00:20:55 +00004123 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4124 TL.getParmArray(),
4125 TL.getNumArgs(),
4126 TL.getTypePtr()->arg_type_begin(),
4127 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004128 return QualType();
4129 }
4130
John McCalla2becad2009-10-21 00:40:46 +00004131 QualType Result = TL.getType();
4132 if (getDerived().AlwaysRebuild() ||
4133 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004134 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004135 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4136 Result = getDerived().RebuildFunctionProtoType(ResultType,
4137 ParamTypes.data(),
4138 ParamTypes.size(),
4139 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004140 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004141 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004142 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004143 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004144 if (Result.isNull())
4145 return QualType();
4146 }
Mike Stump1eb44332009-09-09 15:08:12 +00004147
John McCalla2becad2009-10-21 00:40:46 +00004148 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004149 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4150 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004151 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004152 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4153 NewTL.setArg(i, ParamDecls[i]);
4154
4155 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004156}
Mike Stump1eb44332009-09-09 15:08:12 +00004157
Douglas Gregor577f75a2009-08-04 16:50:30 +00004158template<typename Derived>
4159QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004160 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004161 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004162 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004163 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4164 if (ResultType.isNull())
4165 return QualType();
4166
4167 QualType Result = TL.getType();
4168 if (getDerived().AlwaysRebuild() ||
4169 ResultType != T->getResultType())
4170 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4171
4172 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004173 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4174 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004175 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004176
4177 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004178}
Mike Stump1eb44332009-09-09 15:08:12 +00004179
John McCalled976492009-12-04 22:46:56 +00004180template<typename Derived> QualType
4181TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004182 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004183 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004184 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004185 if (!D)
4186 return QualType();
4187
4188 QualType Result = TL.getType();
4189 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4190 Result = getDerived().RebuildUnresolvedUsingType(D);
4191 if (Result.isNull())
4192 return QualType();
4193 }
4194
4195 // We might get an arbitrary type spec type back. We should at
4196 // least always get a type spec type, though.
4197 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4198 NewTL.setNameLoc(TL.getNameLoc());
4199
4200 return Result;
4201}
4202
Douglas Gregor577f75a2009-08-04 16:50:30 +00004203template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004204QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004205 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004206 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004207 TypedefNameDecl *Typedef
4208 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4209 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004210 if (!Typedef)
4211 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004212
John McCalla2becad2009-10-21 00:40:46 +00004213 QualType Result = TL.getType();
4214 if (getDerived().AlwaysRebuild() ||
4215 Typedef != T->getDecl()) {
4216 Result = getDerived().RebuildTypedefType(Typedef);
4217 if (Result.isNull())
4218 return QualType();
4219 }
Mike Stump1eb44332009-09-09 15:08:12 +00004220
John McCalla2becad2009-10-21 00:40:46 +00004221 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4222 NewTL.setNameLoc(TL.getNameLoc());
4223
4224 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004225}
Mike Stump1eb44332009-09-09 15:08:12 +00004226
Douglas Gregor577f75a2009-08-04 16:50:30 +00004227template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004228QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004229 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004230 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004231 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004232
John McCall60d7b3a2010-08-24 06:29:42 +00004233 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004234 if (E.isInvalid())
4235 return QualType();
4236
John McCalla2becad2009-10-21 00:40:46 +00004237 QualType Result = TL.getType();
4238 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004239 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004240 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004241 if (Result.isNull())
4242 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004243 }
John McCalla2becad2009-10-21 00:40:46 +00004244 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004245
John McCalla2becad2009-10-21 00:40:46 +00004246 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004247 NewTL.setTypeofLoc(TL.getTypeofLoc());
4248 NewTL.setLParenLoc(TL.getLParenLoc());
4249 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004250
4251 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004252}
Mike Stump1eb44332009-09-09 15:08:12 +00004253
4254template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004255QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004256 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004257 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4258 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4259 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004260 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004261
John McCalla2becad2009-10-21 00:40:46 +00004262 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004263 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4264 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004265 if (Result.isNull())
4266 return QualType();
4267 }
Mike Stump1eb44332009-09-09 15:08:12 +00004268
John McCalla2becad2009-10-21 00:40:46 +00004269 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004270 NewTL.setTypeofLoc(TL.getTypeofLoc());
4271 NewTL.setLParenLoc(TL.getLParenLoc());
4272 NewTL.setRParenLoc(TL.getRParenLoc());
4273 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004274
4275 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004276}
Mike Stump1eb44332009-09-09 15:08:12 +00004277
4278template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004279QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004280 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004281 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004282
Douglas Gregor670444e2009-08-04 22:27:00 +00004283 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004284 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004285
John McCall60d7b3a2010-08-24 06:29:42 +00004286 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004287 if (E.isInvalid())
4288 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004289
John McCalla2becad2009-10-21 00:40:46 +00004290 QualType Result = TL.getType();
4291 if (getDerived().AlwaysRebuild() ||
4292 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004293 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004294 if (Result.isNull())
4295 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004296 }
John McCalla2becad2009-10-21 00:40:46 +00004297 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004298
John McCalla2becad2009-10-21 00:40:46 +00004299 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4300 NewTL.setNameLoc(TL.getNameLoc());
4301
4302 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004303}
4304
4305template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004306QualType TreeTransform<Derived>::TransformUnaryTransformType(
4307 TypeLocBuilder &TLB,
4308 UnaryTransformTypeLoc TL) {
4309 QualType Result = TL.getType();
4310 if (Result->isDependentType()) {
4311 const UnaryTransformType *T = TL.getTypePtr();
4312 QualType NewBase =
4313 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4314 Result = getDerived().RebuildUnaryTransformType(NewBase,
4315 T->getUTTKind(),
4316 TL.getKWLoc());
4317 if (Result.isNull())
4318 return QualType();
4319 }
4320
4321 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4322 NewTL.setKWLoc(TL.getKWLoc());
4323 NewTL.setParensRange(TL.getParensRange());
4324 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4325 return Result;
4326}
4327
4328template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004329QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4330 AutoTypeLoc TL) {
4331 const AutoType *T = TL.getTypePtr();
4332 QualType OldDeduced = T->getDeducedType();
4333 QualType NewDeduced;
4334 if (!OldDeduced.isNull()) {
4335 NewDeduced = getDerived().TransformType(OldDeduced);
4336 if (NewDeduced.isNull())
4337 return QualType();
4338 }
4339
4340 QualType Result = TL.getType();
4341 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4342 Result = getDerived().RebuildAutoType(NewDeduced);
4343 if (Result.isNull())
4344 return QualType();
4345 }
4346
4347 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4348 NewTL.setNameLoc(TL.getNameLoc());
4349
4350 return Result;
4351}
4352
4353template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004354QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004355 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004356 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004357 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004358 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4359 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004360 if (!Record)
4361 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004362
John McCalla2becad2009-10-21 00:40:46 +00004363 QualType Result = TL.getType();
4364 if (getDerived().AlwaysRebuild() ||
4365 Record != T->getDecl()) {
4366 Result = getDerived().RebuildRecordType(Record);
4367 if (Result.isNull())
4368 return QualType();
4369 }
Mike Stump1eb44332009-09-09 15:08:12 +00004370
John McCalla2becad2009-10-21 00:40:46 +00004371 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4372 NewTL.setNameLoc(TL.getNameLoc());
4373
4374 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004375}
Mike Stump1eb44332009-09-09 15:08:12 +00004376
4377template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004378QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004379 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004380 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004381 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004382 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4383 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004384 if (!Enum)
4385 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004386
John McCalla2becad2009-10-21 00:40:46 +00004387 QualType Result = TL.getType();
4388 if (getDerived().AlwaysRebuild() ||
4389 Enum != T->getDecl()) {
4390 Result = getDerived().RebuildEnumType(Enum);
4391 if (Result.isNull())
4392 return QualType();
4393 }
Mike Stump1eb44332009-09-09 15:08:12 +00004394
John McCalla2becad2009-10-21 00:40:46 +00004395 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4396 NewTL.setNameLoc(TL.getNameLoc());
4397
4398 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004399}
John McCall7da24312009-09-05 00:15:47 +00004400
John McCall3cb0ebd2010-03-10 03:28:59 +00004401template<typename Derived>
4402QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4403 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004404 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004405 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4406 TL.getTypePtr()->getDecl());
4407 if (!D) return QualType();
4408
4409 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4410 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4411 return T;
4412}
4413
Douglas Gregor577f75a2009-08-04 16:50:30 +00004414template<typename Derived>
4415QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004416 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004417 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004418 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004419}
4420
Mike Stump1eb44332009-09-09 15:08:12 +00004421template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004422QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004423 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004424 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004425 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4426
4427 // Substitute into the replacement type, which itself might involve something
4428 // that needs to be transformed. This only tends to occur with default
4429 // template arguments of template template parameters.
4430 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4431 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4432 if (Replacement.isNull())
4433 return QualType();
4434
4435 // Always canonicalize the replacement type.
4436 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4437 QualType Result
4438 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4439 Replacement);
4440
4441 // Propagate type-source information.
4442 SubstTemplateTypeParmTypeLoc NewTL
4443 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4444 NewTL.setNameLoc(TL.getNameLoc());
4445 return Result;
4446
John McCall49a832b2009-10-18 09:09:24 +00004447}
4448
4449template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004450QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4451 TypeLocBuilder &TLB,
4452 SubstTemplateTypeParmPackTypeLoc TL) {
4453 return TransformTypeSpecType(TLB, TL);
4454}
4455
4456template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004457QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004458 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004459 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004460 const TemplateSpecializationType *T = TL.getTypePtr();
4461
Douglas Gregor1d752d72011-03-02 18:46:51 +00004462 // The nested-name-specifier never matters in a TemplateSpecializationType,
4463 // because we can't have a dependent nested-name-specifier anyway.
4464 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004465 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004466 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4467 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004468 if (Template.isNull())
4469 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004470
John McCall43fed0d2010-11-12 08:19:04 +00004471 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4472}
4473
Eli Friedmanb001de72011-10-06 23:00:33 +00004474template<typename Derived>
4475QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4476 AtomicTypeLoc TL) {
4477 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4478 if (ValueType.isNull())
4479 return QualType();
4480
4481 QualType Result = TL.getType();
4482 if (getDerived().AlwaysRebuild() ||
4483 ValueType != TL.getValueLoc().getType()) {
4484 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4485 if (Result.isNull())
4486 return QualType();
4487 }
4488
4489 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4490 NewTL.setKWLoc(TL.getKWLoc());
4491 NewTL.setLParenLoc(TL.getLParenLoc());
4492 NewTL.setRParenLoc(TL.getRParenLoc());
4493
4494 return Result;
4495}
4496
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004497namespace {
4498 /// \brief Simple iterator that traverses the template arguments in a
4499 /// container that provides a \c getArgLoc() member function.
4500 ///
4501 /// This iterator is intended to be used with the iterator form of
4502 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4503 template<typename ArgLocContainer>
4504 class TemplateArgumentLocContainerIterator {
4505 ArgLocContainer *Container;
4506 unsigned Index;
4507
4508 public:
4509 typedef TemplateArgumentLoc value_type;
4510 typedef TemplateArgumentLoc reference;
4511 typedef int difference_type;
4512 typedef std::input_iterator_tag iterator_category;
4513
4514 class pointer {
4515 TemplateArgumentLoc Arg;
4516
4517 public:
4518 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4519
4520 const TemplateArgumentLoc *operator->() const {
4521 return &Arg;
4522 }
4523 };
4524
4525
4526 TemplateArgumentLocContainerIterator() {}
4527
4528 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4529 unsigned Index)
4530 : Container(&Container), Index(Index) { }
4531
4532 TemplateArgumentLocContainerIterator &operator++() {
4533 ++Index;
4534 return *this;
4535 }
4536
4537 TemplateArgumentLocContainerIterator operator++(int) {
4538 TemplateArgumentLocContainerIterator Old(*this);
4539 ++(*this);
4540 return Old;
4541 }
4542
4543 TemplateArgumentLoc operator*() const {
4544 return Container->getArgLoc(Index);
4545 }
4546
4547 pointer operator->() const {
4548 return pointer(Container->getArgLoc(Index));
4549 }
4550
4551 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004552 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004553 return X.Container == Y.Container && X.Index == Y.Index;
4554 }
4555
4556 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004557 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004558 return !(X == Y);
4559 }
4560 };
4561}
4562
4563
John McCall43fed0d2010-11-12 08:19:04 +00004564template <typename Derived>
4565QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4566 TypeLocBuilder &TLB,
4567 TemplateSpecializationTypeLoc TL,
4568 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004569 TemplateArgumentListInfo NewTemplateArgs;
4570 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4571 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004572 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4573 ArgIterator;
4574 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4575 ArgIterator(TL, TL.getNumArgs()),
4576 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004577 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004578
John McCall833ca992009-10-29 08:12:44 +00004579 // FIXME: maybe don't rebuild if all the template arguments are the same.
4580
4581 QualType Result =
4582 getDerived().RebuildTemplateSpecializationType(Template,
4583 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004584 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004585
4586 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004587 // Specializations of template template parameters are represented as
4588 // TemplateSpecializationTypes, and substitution of type alias templates
4589 // within a dependent context can transform them into
4590 // DependentTemplateSpecializationTypes.
4591 if (isa<DependentTemplateSpecializationType>(Result)) {
4592 DependentTemplateSpecializationTypeLoc NewTL
4593 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004594 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004595 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004596 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004597 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004598 NewTL.setLAngleLoc(TL.getLAngleLoc());
4599 NewTL.setRAngleLoc(TL.getRAngleLoc());
4600 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4601 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4602 return Result;
4603 }
4604
John McCall833ca992009-10-29 08:12:44 +00004605 TemplateSpecializationTypeLoc NewTL
4606 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004607 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004608 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4609 NewTL.setLAngleLoc(TL.getLAngleLoc());
4610 NewTL.setRAngleLoc(TL.getRAngleLoc());
4611 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4612 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004613 }
Mike Stump1eb44332009-09-09 15:08:12 +00004614
John McCall833ca992009-10-29 08:12:44 +00004615 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004616}
Mike Stump1eb44332009-09-09 15:08:12 +00004617
Douglas Gregora88f09f2011-02-28 17:23:35 +00004618template <typename Derived>
4619QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4620 TypeLocBuilder &TLB,
4621 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004622 TemplateName Template,
4623 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004624 TemplateArgumentListInfo NewTemplateArgs;
4625 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4626 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4627 typedef TemplateArgumentLocContainerIterator<
4628 DependentTemplateSpecializationTypeLoc> ArgIterator;
4629 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4630 ArgIterator(TL, TL.getNumArgs()),
4631 NewTemplateArgs))
4632 return QualType();
4633
4634 // FIXME: maybe don't rebuild if all the template arguments are the same.
4635
4636 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4637 QualType Result
4638 = getSema().Context.getDependentTemplateSpecializationType(
4639 TL.getTypePtr()->getKeyword(),
4640 DTN->getQualifier(),
4641 DTN->getIdentifier(),
4642 NewTemplateArgs);
4643
4644 DependentTemplateSpecializationTypeLoc NewTL
4645 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004646 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004647 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004648 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004649 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004650 NewTL.setLAngleLoc(TL.getLAngleLoc());
4651 NewTL.setRAngleLoc(TL.getRAngleLoc());
4652 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4653 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4654 return Result;
4655 }
4656
4657 QualType Result
4658 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004659 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004660 NewTemplateArgs);
4661
4662 if (!Result.isNull()) {
4663 /// FIXME: Wrap this in an elaborated-type-specifier?
4664 TemplateSpecializationTypeLoc NewTL
4665 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004666 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004667 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004668 NewTL.setLAngleLoc(TL.getLAngleLoc());
4669 NewTL.setRAngleLoc(TL.getRAngleLoc());
4670 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4671 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4672 }
4673
4674 return Result;
4675}
4676
Mike Stump1eb44332009-09-09 15:08:12 +00004677template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004678QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004679TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004680 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004681 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004682
Douglas Gregor9e876872011-03-01 18:12:44 +00004683 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004684 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004685 if (TL.getQualifierLoc()) {
4686 QualifierLoc
4687 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4688 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004689 return QualType();
4690 }
Mike Stump1eb44332009-09-09 15:08:12 +00004691
John McCall43fed0d2010-11-12 08:19:04 +00004692 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4693 if (NamedT.isNull())
4694 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004695
Richard Smith3e4c6c42011-05-05 21:57:07 +00004696 // C++0x [dcl.type.elab]p2:
4697 // If the identifier resolves to a typedef-name or the simple-template-id
4698 // resolves to an alias template specialization, the
4699 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004700 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4701 if (const TemplateSpecializationType *TST =
4702 NamedT->getAs<TemplateSpecializationType>()) {
4703 TemplateName Template = TST->getTemplateName();
4704 if (TypeAliasTemplateDecl *TAT =
4705 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4706 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4707 diag::err_tag_reference_non_tag) << 4;
4708 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4709 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004710 }
4711 }
4712
John McCalla2becad2009-10-21 00:40:46 +00004713 QualType Result = TL.getType();
4714 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004715 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004716 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004717 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004718 T->getKeyword(),
4719 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004720 if (Result.isNull())
4721 return QualType();
4722 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004723
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004724 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004725 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004726 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004727 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004728}
Mike Stump1eb44332009-09-09 15:08:12 +00004729
4730template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004731QualType TreeTransform<Derived>::TransformAttributedType(
4732 TypeLocBuilder &TLB,
4733 AttributedTypeLoc TL) {
4734 const AttributedType *oldType = TL.getTypePtr();
4735 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4736 if (modifiedType.isNull())
4737 return QualType();
4738
4739 QualType result = TL.getType();
4740
4741 // FIXME: dependent operand expressions?
4742 if (getDerived().AlwaysRebuild() ||
4743 modifiedType != oldType->getModifiedType()) {
4744 // TODO: this is really lame; we should really be rebuilding the
4745 // equivalent type from first principles.
4746 QualType equivalentType
4747 = getDerived().TransformType(oldType->getEquivalentType());
4748 if (equivalentType.isNull())
4749 return QualType();
4750 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4751 modifiedType,
4752 equivalentType);
4753 }
4754
4755 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4756 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4757 if (TL.hasAttrOperand())
4758 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4759 if (TL.hasAttrExprOperand())
4760 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4761 else if (TL.hasAttrEnumOperand())
4762 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4763
4764 return result;
4765}
4766
4767template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004768QualType
4769TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4770 ParenTypeLoc TL) {
4771 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4772 if (Inner.isNull())
4773 return QualType();
4774
4775 QualType Result = TL.getType();
4776 if (getDerived().AlwaysRebuild() ||
4777 Inner != TL.getInnerLoc().getType()) {
4778 Result = getDerived().RebuildParenType(Inner);
4779 if (Result.isNull())
4780 return QualType();
4781 }
4782
4783 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4784 NewTL.setLParenLoc(TL.getLParenLoc());
4785 NewTL.setRParenLoc(TL.getRParenLoc());
4786 return Result;
4787}
4788
4789template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004790QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004791 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004792 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004793
Douglas Gregor2494dd02011-03-01 01:34:45 +00004794 NestedNameSpecifierLoc QualifierLoc
4795 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4796 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004797 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004798
John McCall33500952010-06-11 00:33:02 +00004799 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004800 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004801 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004802 QualifierLoc,
4803 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004804 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004805 if (Result.isNull())
4806 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004807
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004808 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4809 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004810 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4811
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004812 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004813 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004814 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004815 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004816 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004817 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004818 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004819 NewTL.setNameLoc(TL.getNameLoc());
4820 }
John McCalla2becad2009-10-21 00:40:46 +00004821 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004822}
Mike Stump1eb44332009-09-09 15:08:12 +00004823
Douglas Gregor577f75a2009-08-04 16:50:30 +00004824template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004825QualType TreeTransform<Derived>::
4826 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004827 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004828 NestedNameSpecifierLoc QualifierLoc;
4829 if (TL.getQualifierLoc()) {
4830 QualifierLoc
4831 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4832 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004833 return QualType();
4834 }
4835
John McCall43fed0d2010-11-12 08:19:04 +00004836 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004837 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004838}
4839
4840template<typename Derived>
4841QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004842TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4843 DependentTemplateSpecializationTypeLoc TL,
4844 NestedNameSpecifierLoc QualifierLoc) {
4845 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4846
4847 TemplateArgumentListInfo NewTemplateArgs;
4848 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4849 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4850
4851 typedef TemplateArgumentLocContainerIterator<
4852 DependentTemplateSpecializationTypeLoc> ArgIterator;
4853 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4854 ArgIterator(TL, TL.getNumArgs()),
4855 NewTemplateArgs))
4856 return QualType();
4857
4858 QualType Result
4859 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4860 QualifierLoc,
4861 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004862 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004863 NewTemplateArgs);
4864 if (Result.isNull())
4865 return QualType();
4866
4867 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4868 QualType NamedT = ElabT->getNamedType();
4869
4870 // Copy information relevant to the template specialization.
4871 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004872 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004873 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004874 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004875 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4876 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004877 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004878 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004879
4880 // Copy information relevant to the elaborated type.
4881 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004882 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004883 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004884 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4885 DependentTemplateSpecializationTypeLoc SpecTL
4886 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004887 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004888 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004889 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004890 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004891 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4892 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004893 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004894 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004895 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004896 TemplateSpecializationTypeLoc SpecTL
4897 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004898 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004899 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004900 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4901 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004902 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004903 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004904 }
4905 return Result;
4906}
4907
4908template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004909QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4910 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004911 QualType Pattern
4912 = getDerived().TransformType(TLB, TL.getPatternLoc());
4913 if (Pattern.isNull())
4914 return QualType();
4915
4916 QualType Result = TL.getType();
4917 if (getDerived().AlwaysRebuild() ||
4918 Pattern != TL.getPatternLoc().getType()) {
4919 Result = getDerived().RebuildPackExpansionType(Pattern,
4920 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004921 TL.getEllipsisLoc(),
4922 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004923 if (Result.isNull())
4924 return QualType();
4925 }
4926
4927 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4928 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4929 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004930}
4931
4932template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004933QualType
4934TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004935 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004936 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004937 TLB.pushFullCopy(TL);
4938 return TL.getType();
4939}
4940
4941template<typename Derived>
4942QualType
4943TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004944 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004945 // ObjCObjectType is never dependent.
4946 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004947 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004948}
Mike Stump1eb44332009-09-09 15:08:12 +00004949
4950template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004951QualType
4952TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004953 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004954 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004955 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004956 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004957}
4958
Douglas Gregor577f75a2009-08-04 16:50:30 +00004959//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004960// Statement transformation
4961//===----------------------------------------------------------------------===//
4962template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004963StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004964TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004965 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004966}
4967
4968template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004969StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004970TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4971 return getDerived().TransformCompoundStmt(S, false);
4972}
4973
4974template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004975StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004976TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004977 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004978 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004979 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004980 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004981 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4982 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004983 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004984 if (Result.isInvalid()) {
4985 // Immediately fail if this was a DeclStmt, since it's very
4986 // likely that this will cause problems for future statements.
4987 if (isa<DeclStmt>(*B))
4988 return StmtError();
4989
4990 // Otherwise, just keep processing substatements and fail later.
4991 SubStmtInvalid = true;
4992 continue;
4993 }
Mike Stump1eb44332009-09-09 15:08:12 +00004994
Douglas Gregor43959a92009-08-20 07:17:43 +00004995 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4996 Statements.push_back(Result.takeAs<Stmt>());
4997 }
Mike Stump1eb44332009-09-09 15:08:12 +00004998
John McCall7114cba2010-08-27 19:56:05 +00004999 if (SubStmtInvalid)
5000 return StmtError();
5001
Douglas Gregor43959a92009-08-20 07:17:43 +00005002 if (!getDerived().AlwaysRebuild() &&
5003 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005004 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005005
5006 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5007 move_arg(Statements),
5008 S->getRBracLoc(),
5009 IsStmtExpr);
5010}
Mike Stump1eb44332009-09-09 15:08:12 +00005011
Douglas Gregor43959a92009-08-20 07:17:43 +00005012template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005013StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005014TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005015 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005016 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005017 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5018 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005019
Eli Friedman264c1f82009-11-19 03:14:00 +00005020 // Transform the left-hand case value.
5021 LHS = getDerived().TransformExpr(S->getLHS());
5022 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005023 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005024
Eli Friedman264c1f82009-11-19 03:14:00 +00005025 // Transform the right-hand case value (for the GNU case-range extension).
5026 RHS = getDerived().TransformExpr(S->getRHS());
5027 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005028 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005029 }
Mike Stump1eb44332009-09-09 15:08:12 +00005030
Douglas Gregor43959a92009-08-20 07:17:43 +00005031 // Build the case statement.
5032 // Case statements are always rebuilt so that they will attached to their
5033 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005034 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005035 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005036 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005037 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005038 S->getColonLoc());
5039 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005040 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005041
Douglas Gregor43959a92009-08-20 07:17:43 +00005042 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005043 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005044 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005045 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005046
Douglas Gregor43959a92009-08-20 07:17:43 +00005047 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005048 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005049}
5050
5051template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005052StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005053TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005054 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005055 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005056 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005057 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005058
Douglas Gregor43959a92009-08-20 07:17:43 +00005059 // Default statements are always rebuilt
5060 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005061 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005062}
Mike Stump1eb44332009-09-09 15:08:12 +00005063
Douglas Gregor43959a92009-08-20 07:17:43 +00005064template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005065StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005066TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005067 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005068 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005069 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005070
Chris Lattner57ad3782011-02-17 20:34:02 +00005071 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5072 S->getDecl());
5073 if (!LD)
5074 return StmtError();
5075
5076
Douglas Gregor43959a92009-08-20 07:17:43 +00005077 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005078 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005079 cast<LabelDecl>(LD), SourceLocation(),
5080 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005081}
Mike Stump1eb44332009-09-09 15:08:12 +00005082
Douglas Gregor43959a92009-08-20 07:17:43 +00005083template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005084StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005085TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005086 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005087 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005088 VarDecl *ConditionVar = 0;
5089 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005090 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005091 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005092 getDerived().TransformDefinition(
5093 S->getConditionVariable()->getLocation(),
5094 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005095 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005096 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005097 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005098 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005099
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005100 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005101 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005102
5103 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005104 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005105 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5106 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005107 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005108 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005109
John McCall9ae2f072010-08-23 23:25:46 +00005110 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005111 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005112 }
Sean Huntc3021132010-05-05 15:23:54 +00005113
John McCall9ae2f072010-08-23 23:25:46 +00005114 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5115 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005116 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005117
Douglas Gregor43959a92009-08-20 07:17:43 +00005118 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005119 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005120 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005121 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005122
Douglas Gregor43959a92009-08-20 07:17:43 +00005123 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005124 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005125 if (Else.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 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005129 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005130 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005131 Then.get() == S->getThen() &&
5132 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005133 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005134
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005135 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005136 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005137 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005138}
5139
5140template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005141StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005142TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005143 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005144 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005145 VarDecl *ConditionVar = 0;
5146 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005147 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005148 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005149 getDerived().TransformDefinition(
5150 S->getConditionVariable()->getLocation(),
5151 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005152 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005153 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005154 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005155 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005156
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005157 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005158 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005159 }
Mike Stump1eb44332009-09-09 15:08:12 +00005160
Douglas Gregor43959a92009-08-20 07:17:43 +00005161 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005162 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005163 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005164 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005165 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005166 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005167
Douglas Gregor43959a92009-08-20 07:17:43 +00005168 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005169 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005170 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005171 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005172
Douglas Gregor43959a92009-08-20 07:17:43 +00005173 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005174 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5175 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005176}
Mike Stump1eb44332009-09-09 15:08:12 +00005177
Douglas Gregor43959a92009-08-20 07:17:43 +00005178template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005179StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005180TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005181 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005182 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005183 VarDecl *ConditionVar = 0;
5184 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005185 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005186 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005187 getDerived().TransformDefinition(
5188 S->getConditionVariable()->getLocation(),
5189 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005190 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005191 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005192 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005193 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005194
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005195 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005196 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005197
5198 if (S->getCond()) {
5199 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005200 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5201 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005202 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005203 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005204 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005205 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005206 }
Mike Stump1eb44332009-09-09 15:08:12 +00005207
John McCall9ae2f072010-08-23 23:25:46 +00005208 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5209 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005210 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005211
Douglas Gregor43959a92009-08-20 07:17:43 +00005212 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005213 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005214 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005215 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005216
Douglas Gregor43959a92009-08-20 07:17:43 +00005217 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005218 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005219 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005220 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005221 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005222
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005223 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005224 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005225}
Mike Stump1eb44332009-09-09 15:08:12 +00005226
Douglas Gregor43959a92009-08-20 07:17:43 +00005227template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005228StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005229TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005230 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005231 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005232 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005233 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005234
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005235 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005236 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005237 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005238 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005239
Douglas Gregor43959a92009-08-20 07:17:43 +00005240 if (!getDerived().AlwaysRebuild() &&
5241 Cond.get() == S->getCond() &&
5242 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005243 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005244
John McCall9ae2f072010-08-23 23:25:46 +00005245 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5246 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005247 S->getRParenLoc());
5248}
Mike Stump1eb44332009-09-09 15:08:12 +00005249
Douglas Gregor43959a92009-08-20 07:17:43 +00005250template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005251StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005252TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005253 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005254 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005255 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005256 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005257
Douglas Gregor43959a92009-08-20 07:17:43 +00005258 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005259 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005260 VarDecl *ConditionVar = 0;
5261 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005262 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005263 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005264 getDerived().TransformDefinition(
5265 S->getConditionVariable()->getLocation(),
5266 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005267 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005268 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005269 } else {
5270 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005271
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005272 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005273 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005274
5275 if (S->getCond()) {
5276 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005277 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5278 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005279 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005280 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005281
John McCall9ae2f072010-08-23 23:25:46 +00005282 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005283 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005284 }
Mike Stump1eb44332009-09-09 15:08:12 +00005285
John McCall9ae2f072010-08-23 23:25:46 +00005286 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5287 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005288 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005289
Douglas Gregor43959a92009-08-20 07:17:43 +00005290 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005291 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005292 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005293 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005294
John McCall9ae2f072010-08-23 23:25:46 +00005295 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5296 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005297 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005298
Douglas Gregor43959a92009-08-20 07:17:43 +00005299 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005300 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005301 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005302 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005303
Douglas Gregor43959a92009-08-20 07:17:43 +00005304 if (!getDerived().AlwaysRebuild() &&
5305 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005306 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005307 Inc.get() == S->getInc() &&
5308 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005309 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005310
Douglas Gregor43959a92009-08-20 07:17:43 +00005311 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005312 Init.get(), FullCond, ConditionVar,
5313 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005314}
5315
5316template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005317StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005318TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005319 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5320 S->getLabel());
5321 if (!LD)
5322 return StmtError();
5323
Douglas Gregor43959a92009-08-20 07:17:43 +00005324 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005325 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005326 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005327}
5328
5329template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005330StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005331TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005332 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005333 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005334 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005335 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005336
Douglas Gregor43959a92009-08-20 07:17:43 +00005337 if (!getDerived().AlwaysRebuild() &&
5338 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005339 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005340
5341 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005342 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005343}
5344
5345template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005346StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005347TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005348 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005349}
Mike Stump1eb44332009-09-09 15:08:12 +00005350
Douglas Gregor43959a92009-08-20 07:17:43 +00005351template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005352StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005353TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005354 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005355}
Mike Stump1eb44332009-09-09 15:08:12 +00005356
Douglas Gregor43959a92009-08-20 07:17:43 +00005357template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005358StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005359TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005360 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005361 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005362 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005363
Mike Stump1eb44332009-09-09 15:08:12 +00005364 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005365 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005366 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005367}
Mike Stump1eb44332009-09-09 15:08:12 +00005368
Douglas Gregor43959a92009-08-20 07:17:43 +00005369template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005370StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005371TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005372 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005373 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005374 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5375 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005376 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5377 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005378 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005379 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005380
Douglas Gregor43959a92009-08-20 07:17:43 +00005381 if (Transformed != *D)
5382 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005383
Douglas Gregor43959a92009-08-20 07:17:43 +00005384 Decls.push_back(Transformed);
5385 }
Mike Stump1eb44332009-09-09 15:08:12 +00005386
Douglas Gregor43959a92009-08-20 07:17:43 +00005387 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005388 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005389
5390 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005391 S->getStartLoc(), S->getEndLoc());
5392}
Mike Stump1eb44332009-09-09 15:08:12 +00005393
Douglas Gregor43959a92009-08-20 07:17:43 +00005394template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005395StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005396TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005397
John McCallca0408f2010-08-23 06:44:23 +00005398 ASTOwningVector<Expr*> Constraints(getSema());
5399 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005400 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005401
John McCall60d7b3a2010-08-24 06:29:42 +00005402 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005403 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005404
5405 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005406
Anders Carlsson703e3942010-01-24 05:50:09 +00005407 // Go through the outputs.
5408 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005409 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005410
Anders Carlsson703e3942010-01-24 05:50:09 +00005411 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005412 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005413
Anders Carlsson703e3942010-01-24 05:50:09 +00005414 // Transform the output expr.
5415 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005416 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005417 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005418 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005419
Anders Carlsson703e3942010-01-24 05:50:09 +00005420 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005421
John McCall9ae2f072010-08-23 23:25:46 +00005422 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005423 }
Sean Huntc3021132010-05-05 15:23:54 +00005424
Anders Carlsson703e3942010-01-24 05:50:09 +00005425 // Go through the inputs.
5426 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005427 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005428
Anders Carlsson703e3942010-01-24 05:50:09 +00005429 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005430 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005431
Anders Carlsson703e3942010-01-24 05:50:09 +00005432 // Transform the input expr.
5433 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005434 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005435 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005436 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005437
Anders Carlsson703e3942010-01-24 05:50:09 +00005438 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005439
John McCall9ae2f072010-08-23 23:25:46 +00005440 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005441 }
Sean Huntc3021132010-05-05 15:23:54 +00005442
Anders Carlsson703e3942010-01-24 05:50:09 +00005443 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005444 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005445
5446 // Go through the clobbers.
5447 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005448 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005449
5450 // No need to transform the asm string literal.
5451 AsmString = SemaRef.Owned(S->getAsmString());
5452
5453 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5454 S->isSimple(),
5455 S->isVolatile(),
5456 S->getNumOutputs(),
5457 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005458 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005459 move_arg(Constraints),
5460 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005461 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005462 move_arg(Clobbers),
5463 S->getRParenLoc(),
5464 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005465}
5466
5467
5468template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005469StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005470TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005471 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005472 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005473 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005474 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005475
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005476 // Transform the @catch statements (if present).
5477 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005478 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005479 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005480 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005481 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005482 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005483 if (Catch.get() != S->getCatchStmt(I))
5484 AnyCatchChanged = true;
5485 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005486 }
Sean Huntc3021132010-05-05 15:23:54 +00005487
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005488 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005489 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005490 if (S->getFinallyStmt()) {
5491 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5492 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005493 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005494 }
5495
5496 // If nothing changed, just retain this statement.
5497 if (!getDerived().AlwaysRebuild() &&
5498 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005499 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005500 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005501 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005502
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005503 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005504 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5505 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005506}
Mike Stump1eb44332009-09-09 15:08:12 +00005507
Douglas Gregor43959a92009-08-20 07:17:43 +00005508template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005509StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005510TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005511 // Transform the @catch parameter, if there is one.
5512 VarDecl *Var = 0;
5513 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5514 TypeSourceInfo *TSInfo = 0;
5515 if (FromVar->getTypeSourceInfo()) {
5516 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5517 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005518 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005519 }
Sean Huntc3021132010-05-05 15:23:54 +00005520
Douglas Gregorbe270a02010-04-26 17:57:08 +00005521 QualType T;
5522 if (TSInfo)
5523 T = TSInfo->getType();
5524 else {
5525 T = getDerived().TransformType(FromVar->getType());
5526 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005527 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005528 }
Sean Huntc3021132010-05-05 15:23:54 +00005529
Douglas Gregorbe270a02010-04-26 17:57:08 +00005530 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5531 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005532 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005533 }
Sean Huntc3021132010-05-05 15:23:54 +00005534
John McCall60d7b3a2010-08-24 06:29:42 +00005535 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005536 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005537 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005538
5539 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005540 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005541 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005542}
Mike Stump1eb44332009-09-09 15:08:12 +00005543
Douglas Gregor43959a92009-08-20 07:17:43 +00005544template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005545StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005546TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005547 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005548 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005549 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005550 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005551
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005552 // If nothing changed, just retain this statement.
5553 if (!getDerived().AlwaysRebuild() &&
5554 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005555 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005556
5557 // Build a new statement.
5558 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005559 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005560}
Mike Stump1eb44332009-09-09 15:08:12 +00005561
Douglas Gregor43959a92009-08-20 07:17:43 +00005562template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005563StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005564TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005565 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005566 if (S->getThrowExpr()) {
5567 Operand = getDerived().TransformExpr(S->getThrowExpr());
5568 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005569 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005570 }
Sean Huntc3021132010-05-05 15:23:54 +00005571
Douglas Gregord1377b22010-04-22 21:44:01 +00005572 if (!getDerived().AlwaysRebuild() &&
5573 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005574 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005575
John McCall9ae2f072010-08-23 23:25:46 +00005576 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005577}
Mike Stump1eb44332009-09-09 15:08:12 +00005578
Douglas Gregor43959a92009-08-20 07:17:43 +00005579template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005580StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005581TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005582 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005583 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005584 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005585 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005586 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005587 Object =
5588 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5589 Object.get());
5590 if (Object.isInvalid())
5591 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005592
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005593 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005594 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005595 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005596 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005597
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005598 // If nothing change, just retain the current statement.
5599 if (!getDerived().AlwaysRebuild() &&
5600 Object.get() == S->getSynchExpr() &&
5601 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005602 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005603
5604 // Build a new statement.
5605 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005606 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005607}
5608
5609template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005610StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005611TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5612 ObjCAutoreleasePoolStmt *S) {
5613 // Transform the body.
5614 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5615 if (Body.isInvalid())
5616 return StmtError();
5617
5618 // If nothing changed, just retain this statement.
5619 if (!getDerived().AlwaysRebuild() &&
5620 Body.get() == S->getSubStmt())
5621 return SemaRef.Owned(S);
5622
5623 // Build a new statement.
5624 return getDerived().RebuildObjCAutoreleasePoolStmt(
5625 S->getAtLoc(), Body.get());
5626}
5627
5628template<typename Derived>
5629StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005630TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005631 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005632 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005633 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005634 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005635 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005636
Douglas Gregorc3203e72010-04-22 23:10:45 +00005637 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005638 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005639 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005640 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005641 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5642 Collection.take());
5643 if (Collection.isInvalid())
5644 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005645
Douglas Gregorc3203e72010-04-22 23:10:45 +00005646 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005647 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005648 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005649 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005650
Douglas Gregorc3203e72010-04-22 23:10:45 +00005651 // If nothing changed, just retain this statement.
5652 if (!getDerived().AlwaysRebuild() &&
5653 Element.get() == S->getElement() &&
5654 Collection.get() == S->getCollection() &&
5655 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005656 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005657
Douglas Gregorc3203e72010-04-22 23:10:45 +00005658 // Build a new statement.
5659 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5660 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005661 Element.get(),
5662 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005663 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005664 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005665}
5666
5667
5668template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005669StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005670TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5671 // Transform the exception declaration, if any.
5672 VarDecl *Var = 0;
5673 if (S->getExceptionDecl()) {
5674 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005675 TypeSourceInfo *T = getDerived().TransformType(
5676 ExceptionDecl->getTypeSourceInfo());
5677 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005678 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005679
Douglas Gregor83cb9422010-09-09 17:09:21 +00005680 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005681 ExceptionDecl->getInnerLocStart(),
5682 ExceptionDecl->getLocation(),
5683 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005684 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005685 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005686 }
Mike Stump1eb44332009-09-09 15:08:12 +00005687
Douglas Gregor43959a92009-08-20 07:17:43 +00005688 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005689 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005690 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005691 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005692
Douglas Gregor43959a92009-08-20 07:17:43 +00005693 if (!getDerived().AlwaysRebuild() &&
5694 !Var &&
5695 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005696 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005697
5698 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5699 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005700 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005701}
Mike Stump1eb44332009-09-09 15:08:12 +00005702
Douglas Gregor43959a92009-08-20 07:17:43 +00005703template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005704StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005705TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5706 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005707 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005708 = getDerived().TransformCompoundStmt(S->getTryBlock());
5709 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005710 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005711
Douglas Gregor43959a92009-08-20 07:17:43 +00005712 // Transform the handlers.
5713 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005714 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005715 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005716 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005717 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5718 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005719 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005720
Douglas Gregor43959a92009-08-20 07:17:43 +00005721 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5722 Handlers.push_back(Handler.takeAs<Stmt>());
5723 }
Mike Stump1eb44332009-09-09 15:08:12 +00005724
Douglas Gregor43959a92009-08-20 07:17:43 +00005725 if (!getDerived().AlwaysRebuild() &&
5726 TryBlock.get() == S->getTryBlock() &&
5727 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005728 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005729
John McCall9ae2f072010-08-23 23:25:46 +00005730 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005731 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005732}
Mike Stump1eb44332009-09-09 15:08:12 +00005733
Richard Smithad762fc2011-04-14 22:09:26 +00005734template<typename Derived>
5735StmtResult
5736TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5737 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5738 if (Range.isInvalid())
5739 return StmtError();
5740
5741 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5742 if (BeginEnd.isInvalid())
5743 return StmtError();
5744
5745 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5746 if (Cond.isInvalid())
5747 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005748 if (Cond.get())
5749 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5750 if (Cond.isInvalid())
5751 return StmtError();
5752 if (Cond.get())
5753 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005754
5755 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5756 if (Inc.isInvalid())
5757 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005758 if (Inc.get())
5759 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005760
5761 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5762 if (LoopVar.isInvalid())
5763 return StmtError();
5764
5765 StmtResult NewStmt = S;
5766 if (getDerived().AlwaysRebuild() ||
5767 Range.get() != S->getRangeStmt() ||
5768 BeginEnd.get() != S->getBeginEndStmt() ||
5769 Cond.get() != S->getCond() ||
5770 Inc.get() != S->getInc() ||
5771 LoopVar.get() != S->getLoopVarStmt())
5772 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5773 S->getColonLoc(), Range.get(),
5774 BeginEnd.get(), Cond.get(),
5775 Inc.get(), LoopVar.get(),
5776 S->getRParenLoc());
5777
5778 StmtResult Body = getDerived().TransformStmt(S->getBody());
5779 if (Body.isInvalid())
5780 return StmtError();
5781
5782 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5783 // it now so we have a new statement to attach the body to.
5784 if (Body.get() != S->getBody() && NewStmt.get() == S)
5785 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5786 S->getColonLoc(), Range.get(),
5787 BeginEnd.get(), Cond.get(),
5788 Inc.get(), LoopVar.get(),
5789 S->getRParenLoc());
5790
5791 if (NewStmt.get() == S)
5792 return SemaRef.Owned(S);
5793
5794 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5795}
5796
John Wiegley28bbe4b2011-04-28 01:08:34 +00005797template<typename Derived>
5798StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005799TreeTransform<Derived>::TransformMSDependentExistsStmt(
5800 MSDependentExistsStmt *S) {
5801 // Transform the nested-name-specifier, if any.
5802 NestedNameSpecifierLoc QualifierLoc;
5803 if (S->getQualifierLoc()) {
5804 QualifierLoc
5805 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5806 if (!QualifierLoc)
5807 return StmtError();
5808 }
5809
5810 // Transform the declaration name.
5811 DeclarationNameInfo NameInfo = S->getNameInfo();
5812 if (NameInfo.getName()) {
5813 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5814 if (!NameInfo.getName())
5815 return StmtError();
5816 }
5817
5818 // Check whether anything changed.
5819 if (!getDerived().AlwaysRebuild() &&
5820 QualifierLoc == S->getQualifierLoc() &&
5821 NameInfo.getName() == S->getNameInfo().getName())
5822 return S;
5823
5824 // Determine whether this name exists, if we can.
5825 CXXScopeSpec SS;
5826 SS.Adopt(QualifierLoc);
5827 bool Dependent = false;
5828 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5829 case Sema::IER_Exists:
5830 if (S->isIfExists())
5831 break;
5832
5833 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5834
5835 case Sema::IER_DoesNotExist:
5836 if (S->isIfNotExists())
5837 break;
5838
5839 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5840
5841 case Sema::IER_Dependent:
5842 Dependent = true;
5843 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005844
5845 case Sema::IER_Error:
5846 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005847 }
5848
5849 // We need to continue with the instantiation, so do so now.
5850 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5851 if (SubStmt.isInvalid())
5852 return StmtError();
5853
5854 // If we have resolved the name, just transform to the substatement.
5855 if (!Dependent)
5856 return SubStmt;
5857
5858 // The name is still dependent, so build a dependent expression again.
5859 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5860 S->isIfExists(),
5861 QualifierLoc,
5862 NameInfo,
5863 SubStmt.get());
5864}
5865
5866template<typename Derived>
5867StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005868TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5869 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5870 if(TryBlock.isInvalid()) return StmtError();
5871
5872 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5873 if(!getDerived().AlwaysRebuild() &&
5874 TryBlock.get() == S->getTryBlock() &&
5875 Handler.get() == S->getHandler())
5876 return SemaRef.Owned(S);
5877
5878 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5879 S->getTryLoc(),
5880 TryBlock.take(),
5881 Handler.take());
5882}
5883
5884template<typename Derived>
5885StmtResult
5886TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5887 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5888 if(Block.isInvalid()) return StmtError();
5889
5890 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5891 Block.take());
5892}
5893
5894template<typename Derived>
5895StmtResult
5896TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5897 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5898 if(FilterExpr.isInvalid()) return StmtError();
5899
5900 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5901 if(Block.isInvalid()) return StmtError();
5902
5903 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5904 FilterExpr.take(),
5905 Block.take());
5906}
5907
5908template<typename Derived>
5909StmtResult
5910TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5911 if(isa<SEHFinallyStmt>(Handler))
5912 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5913 else
5914 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5915}
5916
Douglas Gregor43959a92009-08-20 07:17:43 +00005917//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005918// Expression transformation
5919//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005920template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005921ExprResult
John McCall454feb92009-12-08 09:21:05 +00005922TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005923 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005924}
Mike Stump1eb44332009-09-09 15:08:12 +00005925
5926template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005927ExprResult
John McCall454feb92009-12-08 09:21:05 +00005928TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005929 NestedNameSpecifierLoc QualifierLoc;
5930 if (E->getQualifierLoc()) {
5931 QualifierLoc
5932 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5933 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005934 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005935 }
John McCalldbd872f2009-12-08 09:08:17 +00005936
5937 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005938 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5939 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005940 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005941 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005942
John McCallec8045d2010-08-17 21:27:17 +00005943 DeclarationNameInfo NameInfo = E->getNameInfo();
5944 if (NameInfo.getName()) {
5945 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5946 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005947 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005948 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005949
5950 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005951 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005952 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005953 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005954 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005955
5956 // Mark it referenced in the new context regardless.
5957 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00005958 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00005959
John McCall3fa5cae2010-10-26 07:05:15 +00005960 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005961 }
John McCalldbd872f2009-12-08 09:08:17 +00005962
5963 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005964 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005965 TemplateArgs = &TransArgs;
5966 TransArgs.setLAngleLoc(E->getLAngleLoc());
5967 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005968 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5969 E->getNumTemplateArgs(),
5970 TransArgs))
5971 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005972 }
5973
Douglas Gregor40d96a62011-02-28 21:54:11 +00005974 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5975 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005976}
Mike Stump1eb44332009-09-09 15:08:12 +00005977
Douglas Gregorb98b1992009-08-11 05:31:07 +00005978template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005979ExprResult
John McCall454feb92009-12-08 09:21:05 +00005980TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005981 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005982}
Mike Stump1eb44332009-09-09 15:08:12 +00005983
Douglas Gregorb98b1992009-08-11 05:31:07 +00005984template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005985ExprResult
John McCall454feb92009-12-08 09:21:05 +00005986TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005987 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005988}
Mike Stump1eb44332009-09-09 15:08:12 +00005989
Douglas Gregorb98b1992009-08-11 05:31:07 +00005990template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005991ExprResult
John McCall454feb92009-12-08 09:21:05 +00005992TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005993 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005994}
Mike Stump1eb44332009-09-09 15:08:12 +00005995
Douglas Gregorb98b1992009-08-11 05:31:07 +00005996template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005997ExprResult
John McCall454feb92009-12-08 09:21:05 +00005998TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005999 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006000}
Mike Stump1eb44332009-09-09 15:08:12 +00006001
Douglas Gregorb98b1992009-08-11 05:31:07 +00006002template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006003ExprResult
John McCall454feb92009-12-08 09:21:05 +00006004TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006005 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006006}
6007
6008template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006009ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006010TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6011 ExprResult ControllingExpr =
6012 getDerived().TransformExpr(E->getControllingExpr());
6013 if (ControllingExpr.isInvalid())
6014 return ExprError();
6015
Chris Lattner686775d2011-07-20 06:58:45 +00006016 SmallVector<Expr *, 4> AssocExprs;
6017 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006018 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6019 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6020 if (TS) {
6021 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6022 if (!AssocType)
6023 return ExprError();
6024 AssocTypes.push_back(AssocType);
6025 } else {
6026 AssocTypes.push_back(0);
6027 }
6028
6029 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6030 if (AssocExpr.isInvalid())
6031 return ExprError();
6032 AssocExprs.push_back(AssocExpr.release());
6033 }
6034
6035 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6036 E->getDefaultLoc(),
6037 E->getRParenLoc(),
6038 ControllingExpr.release(),
6039 AssocTypes.data(),
6040 AssocExprs.data(),
6041 E->getNumAssocs());
6042}
6043
6044template<typename Derived>
6045ExprResult
John McCall454feb92009-12-08 09:21:05 +00006046TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006047 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006048 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006049 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006050
Douglas Gregorb98b1992009-08-11 05:31:07 +00006051 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006052 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006053
John McCall9ae2f072010-08-23 23:25:46 +00006054 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006055 E->getRParen());
6056}
6057
Mike Stump1eb44332009-09-09 15:08:12 +00006058template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006059ExprResult
John McCall454feb92009-12-08 09:21:05 +00006060TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006061 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006062 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006063 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006064
Douglas Gregorb98b1992009-08-11 05:31:07 +00006065 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006066 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006067
Douglas Gregorb98b1992009-08-11 05:31:07 +00006068 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6069 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006070 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006071}
Mike Stump1eb44332009-09-09 15:08:12 +00006072
Douglas Gregorb98b1992009-08-11 05:31:07 +00006073template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006074ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006075TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6076 // Transform the type.
6077 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6078 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006079 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006080
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006081 // Transform all of the components into components similar to what the
6082 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006083 // FIXME: It would be slightly more efficient in the non-dependent case to
6084 // just map FieldDecls, rather than requiring the rebuilder to look for
6085 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006086 // template code that we don't care.
6087 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006088 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006089 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006090 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006091 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6092 const Node &ON = E->getComponent(I);
6093 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006094 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006095 Comp.LocStart = ON.getSourceRange().getBegin();
6096 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006097 switch (ON.getKind()) {
6098 case Node::Array: {
6099 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006100 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006101 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006102 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006103
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006104 ExprChanged = ExprChanged || Index.get() != FromIndex;
6105 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006106 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006107 break;
6108 }
Sean Huntc3021132010-05-05 15:23:54 +00006109
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006110 case Node::Field:
6111 case Node::Identifier:
6112 Comp.isBrackets = false;
6113 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006114 if (!Comp.U.IdentInfo)
6115 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006116
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006117 break;
Sean Huntc3021132010-05-05 15:23:54 +00006118
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006119 case Node::Base:
6120 // Will be recomputed during the rebuild.
6121 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006122 }
Sean Huntc3021132010-05-05 15:23:54 +00006123
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006124 Components.push_back(Comp);
6125 }
Sean Huntc3021132010-05-05 15:23:54 +00006126
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006127 // If nothing changed, retain the existing expression.
6128 if (!getDerived().AlwaysRebuild() &&
6129 Type == E->getTypeSourceInfo() &&
6130 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006131 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006132
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006133 // Build a new offsetof expression.
6134 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6135 Components.data(), Components.size(),
6136 E->getRParenLoc());
6137}
6138
6139template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006140ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006141TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6142 assert(getDerived().AlreadyTransformed(E->getType()) &&
6143 "opaque value expression requires transformation");
6144 return SemaRef.Owned(E);
6145}
6146
6147template<typename Derived>
6148ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006149TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006150 // Rebuild the syntactic form. The original syntactic form has
6151 // opaque-value expressions in it, so strip those away and rebuild
6152 // the result. This is a really awful way of doing this, but the
6153 // better solution (rebuilding the semantic expressions and
6154 // rebinding OVEs as necessary) doesn't work; we'd need
6155 // TreeTransform to not strip away implicit conversions.
6156 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6157 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006158 if (result.isInvalid()) return ExprError();
6159
6160 // If that gives us a pseudo-object result back, the pseudo-object
6161 // expression must have been an lvalue-to-rvalue conversion which we
6162 // should reapply.
6163 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6164 result = SemaRef.checkPseudoObjectRValue(result.take());
6165
6166 return result;
6167}
6168
6169template<typename Derived>
6170ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006171TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6172 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006173 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006174 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006175
John McCalla93c9342009-12-07 02:54:59 +00006176 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006177 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006178 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006179
John McCall5ab75172009-11-04 07:28:41 +00006180 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006181 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006182
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006183 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6184 E->getKind(),
6185 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006186 }
Mike Stump1eb44332009-09-09 15:08:12 +00006187
John McCall60d7b3a2010-08-24 06:29:42 +00006188 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00006189 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006190 // C++0x [expr.sizeof]p1:
6191 // The operand is either an expression, which is an unevaluated operand
6192 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00006193 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006194
Douglas Gregorb98b1992009-08-11 05:31:07 +00006195 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6196 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006197 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006198
Douglas Gregorb98b1992009-08-11 05:31:07 +00006199 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006200 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006201 }
Mike Stump1eb44332009-09-09 15:08:12 +00006202
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006203 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6204 E->getOperatorLoc(),
6205 E->getKind(),
6206 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006207}
Mike Stump1eb44332009-09-09 15:08:12 +00006208
Douglas Gregorb98b1992009-08-11 05:31:07 +00006209template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006210ExprResult
John McCall454feb92009-12-08 09:21:05 +00006211TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006212 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006213 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006214 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006215
John McCall60d7b3a2010-08-24 06:29:42 +00006216 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006217 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006218 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006219
6220
Douglas Gregorb98b1992009-08-11 05:31:07 +00006221 if (!getDerived().AlwaysRebuild() &&
6222 LHS.get() == E->getLHS() &&
6223 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006224 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006225
John McCall9ae2f072010-08-23 23:25:46 +00006226 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006227 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006228 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006229 E->getRBracketLoc());
6230}
Mike Stump1eb44332009-09-09 15:08:12 +00006231
6232template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006233ExprResult
John McCall454feb92009-12-08 09:21:05 +00006234TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006235 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006236 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006237 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006238 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006239
6240 // Transform arguments.
6241 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006242 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006243 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6244 &ArgChanged))
6245 return ExprError();
6246
Douglas Gregorb98b1992009-08-11 05:31:07 +00006247 if (!getDerived().AlwaysRebuild() &&
6248 Callee.get() == E->getCallee() &&
6249 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006250 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006251
Douglas Gregorb98b1992009-08-11 05:31:07 +00006252 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006253 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006254 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006255 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006256 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006257 E->getRParenLoc());
6258}
Mike Stump1eb44332009-09-09 15:08:12 +00006259
6260template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006261ExprResult
John McCall454feb92009-12-08 09:21:05 +00006262TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006263 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006264 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006265 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006266
Douglas Gregor40d96a62011-02-28 21:54:11 +00006267 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006268 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006269 QualifierLoc
6270 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6271
6272 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006273 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006274 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006275 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006276
Eli Friedmanf595cc42009-12-04 06:40:45 +00006277 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006278 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6279 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006280 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006281 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006282
John McCall6bb80172010-03-30 21:47:33 +00006283 NamedDecl *FoundDecl = E->getFoundDecl();
6284 if (FoundDecl == E->getMemberDecl()) {
6285 FoundDecl = Member;
6286 } else {
6287 FoundDecl = cast_or_null<NamedDecl>(
6288 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6289 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006290 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006291 }
6292
Douglas Gregorb98b1992009-08-11 05:31:07 +00006293 if (!getDerived().AlwaysRebuild() &&
6294 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006295 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006296 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006297 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006298 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006299
Anders Carlsson1f240322009-12-22 05:24:09 +00006300 // Mark it referenced in the new context regardless.
6301 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006302 SemaRef.MarkMemberReferenced(E);
6303
John McCall3fa5cae2010-10-26 07:05:15 +00006304 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006305 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006306
John McCalld5532b62009-11-23 01:53:49 +00006307 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006308 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006309 TransArgs.setLAngleLoc(E->getLAngleLoc());
6310 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006311 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6312 E->getNumTemplateArgs(),
6313 TransArgs))
6314 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006315 }
Sean Huntc3021132010-05-05 15:23:54 +00006316
Douglas Gregorb98b1992009-08-11 05:31:07 +00006317 // FIXME: Bogus source location for the operator
6318 SourceLocation FakeOperatorLoc
6319 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6320
John McCallc2233c52010-01-15 08:34:02 +00006321 // FIXME: to do this check properly, we will need to preserve the
6322 // first-qualifier-in-scope here, just in case we had a dependent
6323 // base (and therefore couldn't do the check) and a
6324 // nested-name-qualifier (and therefore could do the lookup).
6325 NamedDecl *FirstQualifierInScope = 0;
6326
John McCall9ae2f072010-08-23 23:25:46 +00006327 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006328 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006329 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006330 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006331 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006332 Member,
John McCall6bb80172010-03-30 21:47:33 +00006333 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006334 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006335 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006336 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006337}
Mike Stump1eb44332009-09-09 15:08:12 +00006338
Douglas Gregorb98b1992009-08-11 05:31:07 +00006339template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006340ExprResult
John McCall454feb92009-12-08 09:21:05 +00006341TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006342 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006343 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006344 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006345
John McCall60d7b3a2010-08-24 06:29:42 +00006346 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006347 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006348 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006349
Douglas Gregorb98b1992009-08-11 05:31:07 +00006350 if (!getDerived().AlwaysRebuild() &&
6351 LHS.get() == E->getLHS() &&
6352 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006353 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006354
Douglas Gregorb98b1992009-08-11 05:31:07 +00006355 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006356 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006357}
6358
Mike Stump1eb44332009-09-09 15:08:12 +00006359template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006360ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006361TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006362 CompoundAssignOperator *E) {
6363 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006364}
Mike Stump1eb44332009-09-09 15:08:12 +00006365
Douglas Gregorb98b1992009-08-11 05:31:07 +00006366template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006367ExprResult TreeTransform<Derived>::
6368TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6369 // Just rebuild the common and RHS expressions and see whether we
6370 // get any changes.
6371
6372 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6373 if (commonExpr.isInvalid())
6374 return ExprError();
6375
6376 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6377 if (rhs.isInvalid())
6378 return ExprError();
6379
6380 if (!getDerived().AlwaysRebuild() &&
6381 commonExpr.get() == e->getCommon() &&
6382 rhs.get() == e->getFalseExpr())
6383 return SemaRef.Owned(e);
6384
6385 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6386 e->getQuestionLoc(),
6387 0,
6388 e->getColonLoc(),
6389 rhs.get());
6390}
6391
6392template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006393ExprResult
John McCall454feb92009-12-08 09:21:05 +00006394TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006395 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006396 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006397 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006398
John McCall60d7b3a2010-08-24 06:29:42 +00006399 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006400 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006401 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006402
John McCall60d7b3a2010-08-24 06:29:42 +00006403 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006404 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006405 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006406
Douglas Gregorb98b1992009-08-11 05:31:07 +00006407 if (!getDerived().AlwaysRebuild() &&
6408 Cond.get() == E->getCond() &&
6409 LHS.get() == E->getLHS() &&
6410 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006411 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006412
John McCall9ae2f072010-08-23 23:25:46 +00006413 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006414 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006415 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006416 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006417 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006418}
Mike Stump1eb44332009-09-09 15:08:12 +00006419
6420template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006421ExprResult
John McCall454feb92009-12-08 09:21:05 +00006422TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006423 // Implicit casts are eliminated during transformation, since they
6424 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006425 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006426}
Mike Stump1eb44332009-09-09 15:08:12 +00006427
Douglas Gregorb98b1992009-08-11 05:31:07 +00006428template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006429ExprResult
John McCall454feb92009-12-08 09:21:05 +00006430TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006431 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6432 if (!Type)
6433 return ExprError();
6434
John McCall60d7b3a2010-08-24 06:29:42 +00006435 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006436 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006437 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006438 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006439
Douglas Gregorb98b1992009-08-11 05:31:07 +00006440 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006441 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006442 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006443 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006444
John McCall9d125032010-01-15 18:39:57 +00006445 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006446 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006447 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006448 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006449}
Mike Stump1eb44332009-09-09 15:08:12 +00006450
Douglas Gregorb98b1992009-08-11 05:31:07 +00006451template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006452ExprResult
John McCall454feb92009-12-08 09:21:05 +00006453TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006454 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6455 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6456 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006457 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006458
John McCall60d7b3a2010-08-24 06:29:42 +00006459 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006460 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006461 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006462
Douglas Gregorb98b1992009-08-11 05:31:07 +00006463 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006464 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006465 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006466 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006467
John McCall1d7d8d62010-01-19 22:33:45 +00006468 // Note: the expression type doesn't necessarily match the
6469 // type-as-written, but that's okay, because it should always be
6470 // derivable from the initializer.
6471
John McCall42f56b52010-01-18 19:35:47 +00006472 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006473 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006474 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006475}
Mike Stump1eb44332009-09-09 15:08:12 +00006476
Douglas Gregorb98b1992009-08-11 05:31:07 +00006477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006478ExprResult
John McCall454feb92009-12-08 09:21:05 +00006479TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006480 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006481 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006482 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006483
Douglas Gregorb98b1992009-08-11 05:31:07 +00006484 if (!getDerived().AlwaysRebuild() &&
6485 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006486 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006487
Douglas Gregorb98b1992009-08-11 05:31:07 +00006488 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006489 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006490 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006491 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006492 E->getAccessorLoc(),
6493 E->getAccessor());
6494}
Mike Stump1eb44332009-09-09 15:08:12 +00006495
Douglas Gregorb98b1992009-08-11 05:31:07 +00006496template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006497ExprResult
John McCall454feb92009-12-08 09:21:05 +00006498TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006499 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006500
John McCallca0408f2010-08-23 06:44:23 +00006501 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006502 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6503 Inits, &InitChanged))
6504 return ExprError();
6505
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006507 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006508
Douglas Gregorb98b1992009-08-11 05:31:07 +00006509 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006510 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006511}
Mike Stump1eb44332009-09-09 15:08:12 +00006512
Douglas Gregorb98b1992009-08-11 05:31:07 +00006513template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006514ExprResult
John McCall454feb92009-12-08 09:21:05 +00006515TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006516 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006517
Douglas Gregor43959a92009-08-20 07:17:43 +00006518 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006519 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006520 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006521 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006522
Douglas Gregor43959a92009-08-20 07:17:43 +00006523 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006524 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006525 bool ExprChanged = false;
6526 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6527 DEnd = E->designators_end();
6528 D != DEnd; ++D) {
6529 if (D->isFieldDesignator()) {
6530 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6531 D->getDotLoc(),
6532 D->getFieldLoc()));
6533 continue;
6534 }
Mike Stump1eb44332009-09-09 15:08:12 +00006535
Douglas Gregorb98b1992009-08-11 05:31:07 +00006536 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006537 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006538 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006539 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006540
6541 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006542 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006543
Douglas Gregorb98b1992009-08-11 05:31:07 +00006544 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6545 ArrayExprs.push_back(Index.release());
6546 continue;
6547 }
Mike Stump1eb44332009-09-09 15:08:12 +00006548
Douglas Gregorb98b1992009-08-11 05:31:07 +00006549 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006550 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006551 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6552 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006553 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006554
John McCall60d7b3a2010-08-24 06:29:42 +00006555 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006556 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006557 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006558
6559 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006560 End.get(),
6561 D->getLBracketLoc(),
6562 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006563
Douglas Gregorb98b1992009-08-11 05:31:07 +00006564 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6565 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006566
Douglas Gregorb98b1992009-08-11 05:31:07 +00006567 ArrayExprs.push_back(Start.release());
6568 ArrayExprs.push_back(End.release());
6569 }
Mike Stump1eb44332009-09-09 15:08:12 +00006570
Douglas Gregorb98b1992009-08-11 05:31:07 +00006571 if (!getDerived().AlwaysRebuild() &&
6572 Init.get() == E->getInit() &&
6573 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006574 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006575
Douglas Gregorb98b1992009-08-11 05:31:07 +00006576 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6577 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006578 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006579}
Mike Stump1eb44332009-09-09 15:08:12 +00006580
Douglas Gregorb98b1992009-08-11 05:31:07 +00006581template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006582ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006583TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006584 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006585 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006586
Douglas Gregor5557b252009-10-28 00:29:27 +00006587 // FIXME: Will we ever have proper type location here? Will we actually
6588 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006589 QualType T = getDerived().TransformType(E->getType());
6590 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006591 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006592
Douglas Gregorb98b1992009-08-11 05:31:07 +00006593 if (!getDerived().AlwaysRebuild() &&
6594 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006595 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006596
Douglas Gregorb98b1992009-08-11 05:31:07 +00006597 return getDerived().RebuildImplicitValueInitExpr(T);
6598}
Mike Stump1eb44332009-09-09 15:08:12 +00006599
Douglas Gregorb98b1992009-08-11 05:31:07 +00006600template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006601ExprResult
John McCall454feb92009-12-08 09:21:05 +00006602TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006603 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6604 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006605 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006606
John McCall60d7b3a2010-08-24 06:29:42 +00006607 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006608 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006609 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006610
Douglas Gregorb98b1992009-08-11 05:31:07 +00006611 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006612 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006613 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006614 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006615
John McCall9ae2f072010-08-23 23:25:46 +00006616 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006617 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006618}
6619
6620template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006621ExprResult
John McCall454feb92009-12-08 09:21:05 +00006622TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006623 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006624 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006625 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6626 &ArgumentChanged))
6627 return ExprError();
6628
Douglas Gregorb98b1992009-08-11 05:31:07 +00006629 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6630 move_arg(Inits),
6631 E->getRParenLoc());
6632}
Mike Stump1eb44332009-09-09 15:08:12 +00006633
Douglas Gregorb98b1992009-08-11 05:31:07 +00006634/// \brief Transform an address-of-label expression.
6635///
6636/// By default, the transformation of an address-of-label expression always
6637/// rebuilds the expression, so that the label identifier can be resolved to
6638/// the corresponding label statement by semantic analysis.
6639template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006640ExprResult
John McCall454feb92009-12-08 09:21:05 +00006641TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006642 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6643 E->getLabel());
6644 if (!LD)
6645 return ExprError();
6646
Douglas Gregorb98b1992009-08-11 05:31:07 +00006647 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006648 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006649}
Mike Stump1eb44332009-09-09 15:08:12 +00006650
6651template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006652ExprResult
John McCall454feb92009-12-08 09:21:05 +00006653TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006654 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006655 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6656 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006657 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006658
Douglas Gregorb98b1992009-08-11 05:31:07 +00006659 if (!getDerived().AlwaysRebuild() &&
6660 SubStmt.get() == E->getSubStmt())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006661 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006662
6663 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006664 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 E->getRParenLoc());
6666}
Mike Stump1eb44332009-09-09 15:08:12 +00006667
Douglas Gregorb98b1992009-08-11 05:31:07 +00006668template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006669ExprResult
John McCall454feb92009-12-08 09:21:05 +00006670TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006671 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006672 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006673 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006674
John McCall60d7b3a2010-08-24 06:29:42 +00006675 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006677 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006678
John McCall60d7b3a2010-08-24 06:29:42 +00006679 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006680 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006681 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006682
Douglas Gregorb98b1992009-08-11 05:31:07 +00006683 if (!getDerived().AlwaysRebuild() &&
6684 Cond.get() == E->getCond() &&
6685 LHS.get() == E->getLHS() &&
6686 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006687 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006688
Douglas Gregorb98b1992009-08-11 05:31:07 +00006689 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006690 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006691 E->getRParenLoc());
6692}
Mike Stump1eb44332009-09-09 15:08:12 +00006693
Douglas Gregorb98b1992009-08-11 05:31:07 +00006694template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006695ExprResult
John McCall454feb92009-12-08 09:21:05 +00006696TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006697 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006698}
6699
6700template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006701ExprResult
John McCall454feb92009-12-08 09:21:05 +00006702TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006703 switch (E->getOperator()) {
6704 case OO_New:
6705 case OO_Delete:
6706 case OO_Array_New:
6707 case OO_Array_Delete:
6708 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006709 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006710
Douglas Gregor668d6d92009-12-13 20:44:55 +00006711 case OO_Call: {
6712 // This is a call to an object's operator().
6713 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6714
6715 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006716 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006717 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006718 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006719
6720 // FIXME: Poor location information
6721 SourceLocation FakeLParenLoc
6722 = SemaRef.PP.getLocForEndOfToken(
6723 static_cast<Expr *>(Object.get())->getLocEnd());
6724
6725 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006726 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006727 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6728 Args))
6729 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006730
John McCall9ae2f072010-08-23 23:25:46 +00006731 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006732 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006733 E->getLocEnd());
6734 }
6735
6736#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6737 case OO_##Name:
6738#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6739#include "clang/Basic/OperatorKinds.def"
6740 case OO_Subscript:
6741 // Handled below.
6742 break;
6743
6744 case OO_Conditional:
6745 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006746 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006747
6748 case OO_None:
6749 case NUM_OVERLOADED_OPERATORS:
6750 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006751 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006752 }
6753
John McCall60d7b3a2010-08-24 06:29:42 +00006754 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006755 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006756 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006757
John McCall60d7b3a2010-08-24 06:29:42 +00006758 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006759 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006760 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006761
John McCall60d7b3a2010-08-24 06:29:42 +00006762 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006763 if (E->getNumArgs() == 2) {
6764 Second = getDerived().TransformExpr(E->getArg(1));
6765 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006766 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006767 }
Mike Stump1eb44332009-09-09 15:08:12 +00006768
Douglas Gregorb98b1992009-08-11 05:31:07 +00006769 if (!getDerived().AlwaysRebuild() &&
6770 Callee.get() == E->getCallee() &&
6771 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006772 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006773 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006774
Douglas Gregorb98b1992009-08-11 05:31:07 +00006775 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6776 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006777 Callee.get(),
6778 First.get(),
6779 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006780}
Mike Stump1eb44332009-09-09 15:08:12 +00006781
Douglas Gregorb98b1992009-08-11 05:31:07 +00006782template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006783ExprResult
John McCall454feb92009-12-08 09:21:05 +00006784TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6785 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006786}
Mike Stump1eb44332009-09-09 15:08:12 +00006787
Douglas Gregorb98b1992009-08-11 05:31:07 +00006788template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006789ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006790TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6791 // Transform the callee.
6792 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6793 if (Callee.isInvalid())
6794 return ExprError();
6795
6796 // Transform exec config.
6797 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6798 if (EC.isInvalid())
6799 return ExprError();
6800
6801 // Transform arguments.
6802 bool ArgChanged = false;
6803 ASTOwningVector<Expr*> Args(SemaRef);
6804 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6805 &ArgChanged))
6806 return ExprError();
6807
6808 if (!getDerived().AlwaysRebuild() &&
6809 Callee.get() == E->getCallee() &&
6810 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006811 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006812
6813 // FIXME: Wrong source location information for the '('.
6814 SourceLocation FakeLParenLoc
6815 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6816 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6817 move_arg(Args),
6818 E->getRParenLoc(), EC.get());
6819}
6820
6821template<typename Derived>
6822ExprResult
John McCall454feb92009-12-08 09:21:05 +00006823TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006824 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6825 if (!Type)
6826 return ExprError();
6827
John McCall60d7b3a2010-08-24 06:29:42 +00006828 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006829 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006831 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006832
Douglas Gregorb98b1992009-08-11 05:31:07 +00006833 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006834 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006835 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006836 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006837
Douglas Gregorb98b1992009-08-11 05:31:07 +00006838 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006839 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006840 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6841 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6842 SourceLocation FakeRParenLoc
6843 = SemaRef.PP.getLocForEndOfToken(
6844 E->getSubExpr()->getSourceRange().getEnd());
6845 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006846 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006847 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006848 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006849 FakeRAngleLoc,
6850 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006851 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006852 FakeRParenLoc);
6853}
Mike Stump1eb44332009-09-09 15:08:12 +00006854
Douglas Gregorb98b1992009-08-11 05:31:07 +00006855template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006856ExprResult
John McCall454feb92009-12-08 09:21:05 +00006857TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6858 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006859}
Mike Stump1eb44332009-09-09 15:08:12 +00006860
6861template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006862ExprResult
John McCall454feb92009-12-08 09:21:05 +00006863TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6864 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006865}
6866
Douglas Gregorb98b1992009-08-11 05:31:07 +00006867template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006868ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006869TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006870 CXXReinterpretCastExpr *E) {
6871 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006872}
Mike Stump1eb44332009-09-09 15:08:12 +00006873
Douglas Gregorb98b1992009-08-11 05:31:07 +00006874template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006875ExprResult
John McCall454feb92009-12-08 09:21:05 +00006876TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6877 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006878}
Mike Stump1eb44332009-09-09 15:08:12 +00006879
Douglas Gregorb98b1992009-08-11 05:31:07 +00006880template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006881ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006882TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006883 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006884 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6885 if (!Type)
6886 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006887
John McCall60d7b3a2010-08-24 06:29:42 +00006888 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006889 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006890 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006891 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006892
Douglas Gregorb98b1992009-08-11 05:31:07 +00006893 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006894 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006895 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006896 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006897
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006898 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006899 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006900 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006901 E->getRParenLoc());
6902}
Mike Stump1eb44332009-09-09 15:08:12 +00006903
Douglas Gregorb98b1992009-08-11 05:31:07 +00006904template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006905ExprResult
John McCall454feb92009-12-08 09:21:05 +00006906TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006907 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006908 TypeSourceInfo *TInfo
6909 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6910 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006911 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006912
Douglas Gregorb98b1992009-08-11 05:31:07 +00006913 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006914 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006915 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006916
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006917 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6918 E->getLocStart(),
6919 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006920 E->getLocEnd());
6921 }
Mike Stump1eb44332009-09-09 15:08:12 +00006922
Eli Friedmanef331b72012-01-20 01:26:23 +00006923 // We don't know whether the subexpression is potentially evaluated until
6924 // after we perform semantic analysis. We speculatively assume it is
6925 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00006926 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00006927 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006928
John McCall60d7b3a2010-08-24 06:29:42 +00006929 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006930 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006931 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006932
Douglas Gregorb98b1992009-08-11 05:31:07 +00006933 if (!getDerived().AlwaysRebuild() &&
6934 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006935 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006936
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006937 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6938 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006939 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006940 E->getLocEnd());
6941}
6942
6943template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006944ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006945TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6946 if (E->isTypeOperand()) {
6947 TypeSourceInfo *TInfo
6948 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6949 if (!TInfo)
6950 return ExprError();
6951
6952 if (!getDerived().AlwaysRebuild() &&
6953 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006954 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006955
Douglas Gregor3c52a212011-03-06 17:40:41 +00006956 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006957 E->getLocStart(),
6958 TInfo,
6959 E->getLocEnd());
6960 }
6961
Francois Pichet01b7c302010-09-08 12:20:18 +00006962 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6963
6964 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6965 if (SubExpr.isInvalid())
6966 return ExprError();
6967
6968 if (!getDerived().AlwaysRebuild() &&
6969 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006970 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006971
6972 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6973 E->getLocStart(),
6974 SubExpr.get(),
6975 E->getLocEnd());
6976}
6977
6978template<typename Derived>
6979ExprResult
John McCall454feb92009-12-08 09:21:05 +00006980TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006981 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006982}
Mike Stump1eb44332009-09-09 15:08:12 +00006983
Douglas Gregorb98b1992009-08-11 05:31:07 +00006984template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006985ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006986TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006987 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006988 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006989}
Mike Stump1eb44332009-09-09 15:08:12 +00006990
Douglas Gregorb98b1992009-08-11 05:31:07 +00006991template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006992ExprResult
John McCall454feb92009-12-08 09:21:05 +00006993TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006994 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00006995 QualType T;
6996 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6997 T = MD->getThisType(getSema().Context);
6998 else
6999 T = getSema().Context.getPointerType(
7000 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007001
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007002 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00007003 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007004
Douglas Gregor828a1972010-01-07 23:12:05 +00007005 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007006}
Mike Stump1eb44332009-09-09 15:08:12 +00007007
Douglas Gregorb98b1992009-08-11 05:31:07 +00007008template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007009ExprResult
John McCall454feb92009-12-08 09:21:05 +00007010TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007011 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007012 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007013 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007014
Douglas Gregorb98b1992009-08-11 05:31:07 +00007015 if (!getDerived().AlwaysRebuild() &&
7016 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007017 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007018
Douglas Gregorbca01b42011-07-06 22:04:06 +00007019 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7020 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007021}
Mike Stump1eb44332009-09-09 15:08:12 +00007022
Douglas Gregorb98b1992009-08-11 05:31:07 +00007023template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007024ExprResult
John McCall454feb92009-12-08 09:21:05 +00007025TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007026 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007027 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7028 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007030 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007031
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007032 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007033 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007034 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007035
Douglas Gregor036aed12009-12-23 23:03:06 +00007036 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007037}
Mike Stump1eb44332009-09-09 15:08:12 +00007038
Douglas Gregorb98b1992009-08-11 05:31:07 +00007039template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007040ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007041TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7042 CXXScalarValueInitExpr *E) {
7043 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7044 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007045 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007046
Douglas Gregorb98b1992009-08-11 05:31:07 +00007047 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007048 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007049 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007050
Douglas Gregorab6677e2010-09-08 00:15:04 +00007051 return getDerived().RebuildCXXScalarValueInitExpr(T,
7052 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007053 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007054}
Mike Stump1eb44332009-09-09 15:08:12 +00007055
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007057ExprResult
John McCall454feb92009-12-08 09:21:05 +00007058TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007059 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007060 TypeSourceInfo *AllocTypeInfo
7061 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7062 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007063 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007064
Douglas Gregorb98b1992009-08-11 05:31:07 +00007065 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007066 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007067 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007068 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007069
Douglas Gregorb98b1992009-08-11 05:31:07 +00007070 // Transform the placement arguments (if any).
7071 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007072 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007073 if (getDerived().TransformExprs(E->getPlacementArgs(),
7074 E->getNumPlacementArgs(), true,
7075 PlacementArgs, &ArgumentChanged))
7076 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007077
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007078 // Transform the constructor arguments (if any).
7079 // As an annoying corner case, we may have introduced an implicit value-
7080 // initialization expression when allocating a new array, which we implicitly
7081 // drop. It will be re-created during type checking.
John McCallca0408f2010-08-23 06:44:23 +00007082 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007083 if (!(E->isArray() && E->getNumConstructorArgs() == 1 &&
7084 isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) &&
7085 TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007086 ConstructorArgs, &ArgumentChanged))
7087 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007088
Douglas Gregor1af74512010-02-26 00:38:10 +00007089 // Transform constructor, new operator, and delete operator.
7090 CXXConstructorDecl *Constructor = 0;
7091 if (E->getConstructor()) {
7092 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007093 getDerived().TransformDecl(E->getLocStart(),
7094 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007095 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007096 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007097 }
7098
7099 FunctionDecl *OperatorNew = 0;
7100 if (E->getOperatorNew()) {
7101 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007102 getDerived().TransformDecl(E->getLocStart(),
7103 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007104 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007105 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007106 }
7107
7108 FunctionDecl *OperatorDelete = 0;
7109 if (E->getOperatorDelete()) {
7110 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007111 getDerived().TransformDecl(E->getLocStart(),
7112 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007113 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007114 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007115 }
Sean Huntc3021132010-05-05 15:23:54 +00007116
Douglas Gregorb98b1992009-08-11 05:31:07 +00007117 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007118 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007119 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007120 Constructor == E->getConstructor() &&
7121 OperatorNew == E->getOperatorNew() &&
7122 OperatorDelete == E->getOperatorDelete() &&
7123 !ArgumentChanged) {
7124 // Mark any declarations we need as referenced.
7125 // FIXME: instantiation-specific.
7126 if (Constructor)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007127 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Douglas Gregor1af74512010-02-26 00:38:10 +00007128 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007129 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007130 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007131 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007132
7133 if (E->isArray() && Constructor &&
7134 !E->getAllocatedType()->isDependentType()) {
7135 QualType ElementType
7136 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7137 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7138 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7139 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007140 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007141 }
7142 }
7143 }
7144
John McCall3fa5cae2010-10-26 07:05:15 +00007145 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007146 }
Mike Stump1eb44332009-09-09 15:08:12 +00007147
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007148 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007149 if (!ArraySize.get()) {
7150 // If no array size was specified, but the new expression was
7151 // instantiated with an array type (e.g., "new T" where T is
7152 // instantiated with "int[4]"), extract the outer bound from the
7153 // array type as our array size. We do this with constant and
7154 // dependently-sized array types.
7155 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7156 if (!ArrayT) {
7157 // Do nothing
7158 } else if (const ConstantArrayType *ConsArrayT
7159 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007160 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007161 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7162 ConsArrayT->getSize(),
7163 SemaRef.Context.getSizeType(),
7164 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007165 AllocType = ConsArrayT->getElementType();
7166 } else if (const DependentSizedArrayType *DepArrayT
7167 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7168 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007169 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007170 AllocType = DepArrayT->getElementType();
7171 }
7172 }
7173 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007174
Douglas Gregorb98b1992009-08-11 05:31:07 +00007175 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7176 E->isGlobalNew(),
7177 /*FIXME:*/E->getLocStart(),
7178 move_arg(PlacementArgs),
7179 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007180 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007181 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007182 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007183 ArraySize.get(),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007184 E->getConstructorLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007185 move_arg(ConstructorArgs),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007186 E->getConstructorRParen());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007187}
Mike Stump1eb44332009-09-09 15:08:12 +00007188
Douglas Gregorb98b1992009-08-11 05:31:07 +00007189template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007190ExprResult
John McCall454feb92009-12-08 09:21:05 +00007191TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007192 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007193 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007194 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007195
Douglas Gregor1af74512010-02-26 00:38:10 +00007196 // Transform the delete operator, if known.
7197 FunctionDecl *OperatorDelete = 0;
7198 if (E->getOperatorDelete()) {
7199 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007200 getDerived().TransformDecl(E->getLocStart(),
7201 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007202 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007203 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007204 }
Sean Huntc3021132010-05-05 15:23:54 +00007205
Douglas Gregorb98b1992009-08-11 05:31:07 +00007206 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007207 Operand.get() == E->getArgument() &&
7208 OperatorDelete == E->getOperatorDelete()) {
7209 // Mark any declarations we need as referenced.
7210 // FIXME: instantiation-specific.
7211 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007212 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007213
7214 if (!E->getArgument()->isTypeDependent()) {
7215 QualType Destroyed = SemaRef.Context.getBaseElementType(
7216 E->getDestroyedType());
7217 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7218 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007219 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7220 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007221 }
7222 }
7223
John McCall3fa5cae2010-10-26 07:05:15 +00007224 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007225 }
Mike Stump1eb44332009-09-09 15:08:12 +00007226
Douglas Gregorb98b1992009-08-11 05:31:07 +00007227 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7228 E->isGlobalDelete(),
7229 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007230 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007231}
Mike Stump1eb44332009-09-09 15:08:12 +00007232
Douglas Gregorb98b1992009-08-11 05:31:07 +00007233template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007234ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007235TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007236 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007237 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007238 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007239 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007240
John McCallb3d87482010-08-24 05:47:05 +00007241 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007242 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007243 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007244 E->getOperatorLoc(),
7245 E->isArrow()? tok::arrow : tok::period,
7246 ObjectTypePtr,
7247 MayBePseudoDestructor);
7248 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007249 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007250
John McCallb3d87482010-08-24 05:47:05 +00007251 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007252 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7253 if (QualifierLoc) {
7254 QualifierLoc
7255 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7256 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007257 return ExprError();
7258 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007259 CXXScopeSpec SS;
7260 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007261
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007262 PseudoDestructorTypeStorage Destroyed;
7263 if (E->getDestroyedTypeInfo()) {
7264 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007265 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007266 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007267 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007268 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007269 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007270 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007271 // We aren't likely to be able to resolve the identifier down to a type
7272 // now anyway, so just retain the identifier.
7273 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7274 E->getDestroyedTypeLoc());
7275 } else {
7276 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007277 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007278 *E->getDestroyedTypeIdentifier(),
7279 E->getDestroyedTypeLoc(),
7280 /*Scope=*/0,
7281 SS, ObjectTypePtr,
7282 false);
7283 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007284 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007285
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007286 Destroyed
7287 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7288 E->getDestroyedTypeLoc());
7289 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007290
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007291 TypeSourceInfo *ScopeTypeInfo = 0;
7292 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007293 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007294 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007295 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007296 }
Sean Huntc3021132010-05-05 15:23:54 +00007297
John McCall9ae2f072010-08-23 23:25:46 +00007298 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007299 E->getOperatorLoc(),
7300 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007301 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007302 ScopeTypeInfo,
7303 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007304 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007305 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007306}
Mike Stump1eb44332009-09-09 15:08:12 +00007307
Douglas Gregora71d8192009-09-04 17:36:40 +00007308template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007309ExprResult
John McCallba135432009-11-21 08:51:07 +00007310TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007311 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007312 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7313 Sema::LookupOrdinaryName);
7314
7315 // Transform all the decls.
7316 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7317 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007318 NamedDecl *InstD = static_cast<NamedDecl*>(
7319 getDerived().TransformDecl(Old->getNameLoc(),
7320 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007321 if (!InstD) {
7322 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7323 // This can happen because of dependent hiding.
7324 if (isa<UsingShadowDecl>(*I))
7325 continue;
7326 else
John McCallf312b1e2010-08-26 23:41:50 +00007327 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007328 }
John McCallf7a1a742009-11-24 19:00:30 +00007329
7330 // Expand using declarations.
7331 if (isa<UsingDecl>(InstD)) {
7332 UsingDecl *UD = cast<UsingDecl>(InstD);
7333 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7334 E = UD->shadow_end(); I != E; ++I)
7335 R.addDecl(*I);
7336 continue;
7337 }
7338
7339 R.addDecl(InstD);
7340 }
7341
7342 // Resolve a kind, but don't do any further analysis. If it's
7343 // ambiguous, the callee needs to deal with it.
7344 R.resolveKind();
7345
7346 // Rebuild the nested-name qualifier, if present.
7347 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007348 if (Old->getQualifierLoc()) {
7349 NestedNameSpecifierLoc QualifierLoc
7350 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7351 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007352 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007353
Douglas Gregor4c9be892011-02-28 20:01:57 +00007354 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007355 }
7356
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007357 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007358 CXXRecordDecl *NamingClass
7359 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7360 Old->getNameLoc(),
7361 Old->getNamingClass()));
7362 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007363 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007364
Douglas Gregor66c45152010-04-27 16:10:10 +00007365 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007366 }
7367
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007368 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7369
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007370 // If we have neither explicit template arguments, nor the template keyword,
7371 // it's a normal declaration name.
7372 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007373 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7374
7375 // If we have template arguments, rebuild them, then rebuild the
7376 // templateid expression.
7377 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007378 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7379 Old->getNumTemplateArgs(),
7380 TransArgs))
7381 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007382
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007383 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007384 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007385}
Mike Stump1eb44332009-09-09 15:08:12 +00007386
Douglas Gregorb98b1992009-08-11 05:31:07 +00007387template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007388ExprResult
John McCall454feb92009-12-08 09:21:05 +00007389TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007390 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7391 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007392 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007393
Douglas Gregorb98b1992009-08-11 05:31:07 +00007394 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007395 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007396 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007397
Mike Stump1eb44332009-09-09 15:08:12 +00007398 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007399 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007400 T,
7401 E->getLocEnd());
7402}
Mike Stump1eb44332009-09-09 15:08:12 +00007403
Douglas Gregorb98b1992009-08-11 05:31:07 +00007404template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007405ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007406TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7407 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7408 if (!LhsT)
7409 return ExprError();
7410
7411 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7412 if (!RhsT)
7413 return ExprError();
7414
7415 if (!getDerived().AlwaysRebuild() &&
7416 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7417 return SemaRef.Owned(E);
7418
7419 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7420 E->getLocStart(),
7421 LhsT, RhsT,
7422 E->getLocEnd());
7423}
7424
7425template<typename Derived>
7426ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007427TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7428 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7429 if (!T)
7430 return ExprError();
7431
7432 if (!getDerived().AlwaysRebuild() &&
7433 T == E->getQueriedTypeSourceInfo())
7434 return SemaRef.Owned(E);
7435
7436 ExprResult SubExpr;
7437 {
7438 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7439 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7440 if (SubExpr.isInvalid())
7441 return ExprError();
7442
7443 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7444 return SemaRef.Owned(E);
7445 }
7446
7447 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7448 E->getLocStart(),
7449 T,
7450 SubExpr.get(),
7451 E->getLocEnd());
7452}
7453
7454template<typename Derived>
7455ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007456TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7457 ExprResult SubExpr;
7458 {
7459 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7460 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7461 if (SubExpr.isInvalid())
7462 return ExprError();
7463
7464 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7465 return SemaRef.Owned(E);
7466 }
7467
7468 return getDerived().RebuildExpressionTrait(
7469 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7470}
7471
7472template<typename Derived>
7473ExprResult
John McCall865d4472009-11-19 22:55:06 +00007474TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007475 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007476 NestedNameSpecifierLoc QualifierLoc
7477 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7478 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007479 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007480 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007481
John McCall43fed0d2010-11-12 08:19:04 +00007482 // TODO: If this is a conversion-function-id, verify that the
7483 // destination type name (if present) resolves the same way after
7484 // instantiation as it did in the local scope.
7485
Abramo Bagnara25777432010-08-11 22:01:17 +00007486 DeclarationNameInfo NameInfo
7487 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7488 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007489 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007490
John McCallf7a1a742009-11-24 19:00:30 +00007491 if (!E->hasExplicitTemplateArgs()) {
7492 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007493 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007494 // Note: it is sufficient to compare the Name component of NameInfo:
7495 // if name has not changed, DNLoc has not changed either.
7496 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007497 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007498
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007499 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007500 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007501 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007502 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007503 }
John McCalld5532b62009-11-23 01:53:49 +00007504
7505 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007506 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7507 E->getNumTemplateArgs(),
7508 TransArgs))
7509 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007510
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007511 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007512 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007513 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007514 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007515}
7516
7517template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007518ExprResult
John McCall454feb92009-12-08 09:21:05 +00007519TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007520 // CXXConstructExprs are always implicit, so when we have a
7521 // 1-argument construction we just transform that argument.
7522 if (E->getNumArgs() == 1 ||
7523 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7524 return getDerived().TransformExpr(E->getArg(0));
7525
Douglas Gregorb98b1992009-08-11 05:31:07 +00007526 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7527
7528 QualType T = getDerived().TransformType(E->getType());
7529 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007530 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007531
7532 CXXConstructorDecl *Constructor
7533 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007534 getDerived().TransformDecl(E->getLocStart(),
7535 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007536 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007537 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007538
Douglas Gregorb98b1992009-08-11 05:31:07 +00007539 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007540 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007541 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7542 &ArgumentChanged))
7543 return ExprError();
7544
Douglas Gregorb98b1992009-08-11 05:31:07 +00007545 if (!getDerived().AlwaysRebuild() &&
7546 T == E->getType() &&
7547 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007548 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007549 // Mark the constructor as referenced.
7550 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007551 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007552 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007553 }
Mike Stump1eb44332009-09-09 15:08:12 +00007554
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007555 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7556 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007557 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007558 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007559 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007560 E->getConstructionKind(),
7561 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007562}
Mike Stump1eb44332009-09-09 15:08:12 +00007563
Douglas Gregorb98b1992009-08-11 05:31:07 +00007564/// \brief Transform a C++ temporary-binding expression.
7565///
Douglas Gregor51326552009-12-24 18:51:59 +00007566/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7567/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007568template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007569ExprResult
John McCall454feb92009-12-08 09:21:05 +00007570TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007571 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007572}
Mike Stump1eb44332009-09-09 15:08:12 +00007573
John McCall4765fa02010-12-06 08:20:24 +00007574/// \brief Transform a C++ expression that contains cleanups that should
7575/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007576///
John McCall4765fa02010-12-06 08:20:24 +00007577/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007578/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007579template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007580ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007581TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007582 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007583}
Mike Stump1eb44332009-09-09 15:08:12 +00007584
Douglas Gregorb98b1992009-08-11 05:31:07 +00007585template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007586ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007587TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007588 CXXTemporaryObjectExpr *E) {
7589 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7590 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007591 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007592
Douglas Gregorb98b1992009-08-11 05:31:07 +00007593 CXXConstructorDecl *Constructor
7594 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007595 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007596 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007597 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007598 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007599
Douglas Gregorb98b1992009-08-11 05:31:07 +00007600 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007601 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007602 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007603 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7604 &ArgumentChanged))
7605 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007606
Douglas Gregorb98b1992009-08-11 05:31:07 +00007607 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007608 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007609 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007610 !ArgumentChanged) {
7611 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007612 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007613 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007614 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007615
7616 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7617 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007618 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007619 E->getLocEnd());
7620}
Mike Stump1eb44332009-09-09 15:08:12 +00007621
Douglas Gregorb98b1992009-08-11 05:31:07 +00007622template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007623ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007624TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
7625 assert(false && "Lambda expressions cannot be instantiated (yet)");
7626 return ExprError();
7627}
7628
7629template<typename Derived>
7630ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007631TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007632 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007633 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7634 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007635 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007636
Douglas Gregorb98b1992009-08-11 05:31:07 +00007637 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007638 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007639 Args.reserve(E->arg_size());
7640 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7641 &ArgumentChanged))
7642 return ExprError();
7643
Douglas Gregorb98b1992009-08-11 05:31:07 +00007644 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007645 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007646 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007647 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007648
Douglas Gregorb98b1992009-08-11 05:31:07 +00007649 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007650 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007651 E->getLParenLoc(),
7652 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007653 E->getRParenLoc());
7654}
Mike Stump1eb44332009-09-09 15:08:12 +00007655
Douglas Gregorb98b1992009-08-11 05:31:07 +00007656template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007657ExprResult
John McCall865d4472009-11-19 22:55:06 +00007658TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007659 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007660 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007661 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007662 Expr *OldBase;
7663 QualType BaseType;
7664 QualType ObjectType;
7665 if (!E->isImplicitAccess()) {
7666 OldBase = E->getBase();
7667 Base = getDerived().TransformExpr(OldBase);
7668 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007669 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007670
John McCallaa81e162009-12-01 22:10:20 +00007671 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007672 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007673 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007674 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007675 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007676 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007677 ObjectTy,
7678 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007679 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007680 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007681
John McCallb3d87482010-08-24 05:47:05 +00007682 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007683 BaseType = ((Expr*) Base.get())->getType();
7684 } else {
7685 OldBase = 0;
7686 BaseType = getDerived().TransformType(E->getBaseType());
7687 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7688 }
Mike Stump1eb44332009-09-09 15:08:12 +00007689
Douglas Gregor6cd21982009-10-20 05:58:46 +00007690 // Transform the first part of the nested-name-specifier that qualifies
7691 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007692 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007693 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007694 E->getFirstQualifierFoundInScope(),
7695 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007696
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007697 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007698 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007699 QualifierLoc
7700 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7701 ObjectType,
7702 FirstQualifierInScope);
7703 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007704 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007705 }
Mike Stump1eb44332009-09-09 15:08:12 +00007706
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007707 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
7708
John McCall43fed0d2010-11-12 08:19:04 +00007709 // TODO: If this is a conversion-function-id, verify that the
7710 // destination type name (if present) resolves the same way after
7711 // instantiation as it did in the local scope.
7712
Abramo Bagnara25777432010-08-11 22:01:17 +00007713 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007714 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007715 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007716 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007717
John McCallaa81e162009-12-01 22:10:20 +00007718 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007719 // This is a reference to a member without an explicitly-specified
7720 // template argument list. Optimize for this common case.
7721 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007722 Base.get() == OldBase &&
7723 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007724 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007725 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007726 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007727 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007728
John McCall9ae2f072010-08-23 23:25:46 +00007729 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007730 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007731 E->isArrow(),
7732 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007733 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007734 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00007735 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007736 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007737 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007738 }
7739
John McCalld5532b62009-11-23 01:53:49 +00007740 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007741 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7742 E->getNumTemplateArgs(),
7743 TransArgs))
7744 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007745
John McCall9ae2f072010-08-23 23:25:46 +00007746 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007747 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007748 E->isArrow(),
7749 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007750 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007751 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007752 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007753 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007754 &TransArgs);
7755}
7756
7757template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007758ExprResult
John McCall454feb92009-12-08 09:21:05 +00007759TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007760 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007761 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007762 QualType BaseType;
7763 if (!Old->isImplicitAccess()) {
7764 Base = getDerived().TransformExpr(Old->getBase());
7765 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007766 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00007767 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
7768 Old->isArrow());
7769 if (Base.isInvalid())
7770 return ExprError();
7771 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00007772 } else {
7773 BaseType = getDerived().TransformType(Old->getBaseType());
7774 }
John McCall129e2df2009-11-30 22:42:35 +00007775
Douglas Gregor4c9be892011-02-28 20:01:57 +00007776 NestedNameSpecifierLoc QualifierLoc;
7777 if (Old->getQualifierLoc()) {
7778 QualifierLoc
7779 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7780 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007781 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007782 }
7783
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007784 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7785
Abramo Bagnara25777432010-08-11 22:01:17 +00007786 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007787 Sema::LookupOrdinaryName);
7788
7789 // Transform all the decls.
7790 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7791 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007792 NamedDecl *InstD = static_cast<NamedDecl*>(
7793 getDerived().TransformDecl(Old->getMemberLoc(),
7794 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007795 if (!InstD) {
7796 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7797 // This can happen because of dependent hiding.
7798 if (isa<UsingShadowDecl>(*I))
7799 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007800 else {
7801 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007802 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007803 }
John McCall9f54ad42009-12-10 09:41:52 +00007804 }
John McCall129e2df2009-11-30 22:42:35 +00007805
7806 // Expand using declarations.
7807 if (isa<UsingDecl>(InstD)) {
7808 UsingDecl *UD = cast<UsingDecl>(InstD);
7809 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7810 E = UD->shadow_end(); I != E; ++I)
7811 R.addDecl(*I);
7812 continue;
7813 }
7814
7815 R.addDecl(InstD);
7816 }
7817
7818 R.resolveKind();
7819
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007820 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007821 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007822 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007823 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007824 Old->getMemberLoc(),
7825 Old->getNamingClass()));
7826 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007827 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007828
Douglas Gregor66c45152010-04-27 16:10:10 +00007829 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007830 }
Sean Huntc3021132010-05-05 15:23:54 +00007831
John McCall129e2df2009-11-30 22:42:35 +00007832 TemplateArgumentListInfo TransArgs;
7833 if (Old->hasExplicitTemplateArgs()) {
7834 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7835 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007836 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7837 Old->getNumTemplateArgs(),
7838 TransArgs))
7839 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007840 }
John McCallc2233c52010-01-15 08:34:02 +00007841
7842 // FIXME: to do this check properly, we will need to preserve the
7843 // first-qualifier-in-scope here, just in case we had a dependent
7844 // base (and therefore couldn't do the check) and a
7845 // nested-name-qualifier (and therefore could do the lookup).
7846 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007847
John McCall9ae2f072010-08-23 23:25:46 +00007848 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007849 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007850 Old->getOperatorLoc(),
7851 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007852 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007853 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00007854 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007855 R,
7856 (Old->hasExplicitTemplateArgs()
7857 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007858}
7859
7860template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007861ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007862TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00007863 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00007864 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7865 if (SubExpr.isInvalid())
7866 return ExprError();
7867
7868 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007869 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007870
7871 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7872}
7873
7874template<typename Derived>
7875ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007876TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007877 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7878 if (Pattern.isInvalid())
7879 return ExprError();
7880
7881 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7882 return SemaRef.Owned(E);
7883
Douglas Gregor67fd1252011-01-14 21:20:45 +00007884 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7885 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007886}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007887
7888template<typename Derived>
7889ExprResult
7890TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7891 // If E is not value-dependent, then nothing will change when we transform it.
7892 // Note: This is an instantiation-centric view.
7893 if (!E->isValueDependent())
7894 return SemaRef.Owned(E);
7895
7896 // Note: None of the implementations of TryExpandParameterPacks can ever
7897 // produce a diagnostic when given only a single unexpanded parameter pack,
7898 // so
7899 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7900 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007901 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007902 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007903 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00007904 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00007905 ShouldExpand, RetainExpansion,
7906 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007907 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007908
Douglas Gregor089e8932011-10-10 18:59:29 +00007909 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007910 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00007911
7912 NamedDecl *Pack = E->getPack();
7913 if (!ShouldExpand) {
7914 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
7915 Pack));
7916 if (!Pack)
7917 return ExprError();
7918 }
7919
Douglas Gregoree8aff02011-01-04 17:33:58 +00007920
7921 // We now know the length of the parameter pack, so build a new expression
7922 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00007923 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00007924 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00007925 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007926}
7927
Douglas Gregorbe230c32011-01-03 17:17:50 +00007928template<typename Derived>
7929ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007930TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7931 SubstNonTypeTemplateParmPackExpr *E) {
7932 // Default behavior is to do nothing with this transformation.
7933 return SemaRef.Owned(E);
7934}
7935
7936template<typename Derived>
7937ExprResult
John McCall91a57552011-07-15 05:09:51 +00007938TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7939 SubstNonTypeTemplateParmExpr *E) {
7940 // Default behavior is to do nothing with this transformation.
7941 return SemaRef.Owned(E);
7942}
7943
7944template<typename Derived>
7945ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00007946TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7947 MaterializeTemporaryExpr *E) {
7948 return getDerived().TransformExpr(E->GetTemporaryExpr());
7949}
7950
7951template<typename Derived>
7952ExprResult
John McCall454feb92009-12-08 09:21:05 +00007953TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007954 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007955}
7956
Mike Stump1eb44332009-09-09 15:08:12 +00007957template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007958ExprResult
John McCall454feb92009-12-08 09:21:05 +00007959TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007960 TypeSourceInfo *EncodedTypeInfo
7961 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7962 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007963 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007964
Douglas Gregorb98b1992009-08-11 05:31:07 +00007965 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007966 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007967 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007968
7969 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007970 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007971 E->getRParenLoc());
7972}
Mike Stump1eb44332009-09-09 15:08:12 +00007973
Douglas Gregorb98b1992009-08-11 05:31:07 +00007974template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00007975ExprResult TreeTransform<Derived>::
7976TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7977 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7978 if (result.isInvalid()) return ExprError();
7979 Expr *subExpr = result.take();
7980
7981 if (!getDerived().AlwaysRebuild() &&
7982 subExpr == E->getSubExpr())
7983 return SemaRef.Owned(E);
7984
7985 return SemaRef.Owned(new(SemaRef.Context)
7986 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7987}
7988
7989template<typename Derived>
7990ExprResult TreeTransform<Derived>::
7991TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7992 TypeSourceInfo *TSInfo
7993 = getDerived().TransformType(E->getTypeInfoAsWritten());
7994 if (!TSInfo)
7995 return ExprError();
7996
7997 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7998 if (Result.isInvalid())
7999 return ExprError();
8000
8001 if (!getDerived().AlwaysRebuild() &&
8002 TSInfo == E->getTypeInfoAsWritten() &&
8003 Result.get() == E->getSubExpr())
8004 return SemaRef.Owned(E);
8005
8006 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8007 E->getBridgeKeywordLoc(), TSInfo,
8008 Result.get());
8009}
8010
8011template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008012ExprResult
John McCall454feb92009-12-08 09:21:05 +00008013TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008014 // Transform arguments.
8015 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008016 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008017 Args.reserve(E->getNumArgs());
8018 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8019 &ArgChanged))
8020 return ExprError();
8021
Douglas Gregor92e986e2010-04-22 16:44:27 +00008022 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8023 // Class message: transform the receiver type.
8024 TypeSourceInfo *ReceiverTypeInfo
8025 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8026 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008027 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008028
Douglas Gregor92e986e2010-04-22 16:44:27 +00008029 // If nothing changed, just retain the existing message send.
8030 if (!getDerived().AlwaysRebuild() &&
8031 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008032 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008033
8034 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008035 SmallVector<SourceLocation, 16> SelLocs;
8036 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008037 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8038 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008039 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008040 E->getMethodDecl(),
8041 E->getLeftLoc(),
8042 move_arg(Args),
8043 E->getRightLoc());
8044 }
8045
8046 // Instance message: transform the receiver
8047 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8048 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008049 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008050 = getDerived().TransformExpr(E->getInstanceReceiver());
8051 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008052 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008053
8054 // If nothing changed, just retain the existing message send.
8055 if (!getDerived().AlwaysRebuild() &&
8056 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008057 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008058
Douglas Gregor92e986e2010-04-22 16:44:27 +00008059 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008060 SmallVector<SourceLocation, 16> SelLocs;
8061 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008062 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008063 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008064 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008065 E->getMethodDecl(),
8066 E->getLeftLoc(),
8067 move_arg(Args),
8068 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008069}
8070
Mike Stump1eb44332009-09-09 15:08:12 +00008071template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008072ExprResult
John McCall454feb92009-12-08 09:21:05 +00008073TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008074 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008075}
8076
Mike Stump1eb44332009-09-09 15:08:12 +00008077template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008078ExprResult
John McCall454feb92009-12-08 09:21:05 +00008079TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008080 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008081}
8082
Mike Stump1eb44332009-09-09 15:08:12 +00008083template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008084ExprResult
John McCall454feb92009-12-08 09:21:05 +00008085TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008086 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008087 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008088 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008089 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008090
8091 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008092
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008093 // If nothing changed, just retain the existing expression.
8094 if (!getDerived().AlwaysRebuild() &&
8095 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008096 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008097
John McCall9ae2f072010-08-23 23:25:46 +00008098 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008099 E->getLocation(),
8100 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008101}
8102
Mike Stump1eb44332009-09-09 15:08:12 +00008103template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008104ExprResult
John McCall454feb92009-12-08 09:21:05 +00008105TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008106 // 'super' and types never change. Property never changes. Just
8107 // retain the existing expression.
8108 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008109 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008110
Douglas Gregore3303542010-04-26 20:47:02 +00008111 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008112 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008113 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008114 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008115
Douglas Gregore3303542010-04-26 20:47:02 +00008116 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008117
Douglas Gregore3303542010-04-26 20:47:02 +00008118 // If nothing changed, just retain the existing expression.
8119 if (!getDerived().AlwaysRebuild() &&
8120 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008121 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008122
John McCall12f78a62010-12-02 01:19:52 +00008123 if (E->isExplicitProperty())
8124 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8125 E->getExplicitProperty(),
8126 E->getLocation());
8127
8128 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008129 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008130 E->getImplicitPropertyGetter(),
8131 E->getImplicitPropertySetter(),
8132 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008133}
8134
Mike Stump1eb44332009-09-09 15:08:12 +00008135template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008136ExprResult
John McCall454feb92009-12-08 09:21:05 +00008137TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008138 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008139 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008140 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008141 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008142
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008143 // If nothing changed, just retain the existing expression.
8144 if (!getDerived().AlwaysRebuild() &&
8145 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008146 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008147
John McCall9ae2f072010-08-23 23:25:46 +00008148 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008149 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008150}
8151
Mike Stump1eb44332009-09-09 15:08:12 +00008152template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008153ExprResult
John McCall454feb92009-12-08 09:21:05 +00008154TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008155 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008156 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008157 SubExprs.reserve(E->getNumSubExprs());
8158 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8159 SubExprs, &ArgumentChanged))
8160 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008161
Douglas Gregorb98b1992009-08-11 05:31:07 +00008162 if (!getDerived().AlwaysRebuild() &&
8163 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008164 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008165
Douglas Gregorb98b1992009-08-11 05:31:07 +00008166 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8167 move_arg(SubExprs),
8168 E->getRParenLoc());
8169}
8170
Mike Stump1eb44332009-09-09 15:08:12 +00008171template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008172ExprResult
John McCall454feb92009-12-08 09:21:05 +00008173TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008174 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008175
John McCallc6ac9c32011-02-04 18:33:18 +00008176 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8177 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8178
8179 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008180 blockScope->TheDecl->setBlockMissingReturnType(
8181 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008182
Chris Lattner686775d2011-07-20 06:58:45 +00008183 SmallVector<ParmVarDecl*, 4> params;
8184 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008185
8186 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008187 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8188 oldBlock->param_begin(),
8189 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008190 0, paramTypes, &params)) {
8191 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008192 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008193 }
John McCallc6ac9c32011-02-04 18:33:18 +00008194
8195 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008196 QualType exprResultType =
8197 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008198
8199 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008200 if (exprResultType->isObjCObjectType()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008201 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008202 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008203 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008204 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008205 return ExprError();
8206 }
John McCall711c52b2011-01-05 12:14:39 +00008207
John McCallc6ac9c32011-02-04 18:33:18 +00008208 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008209 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008210 paramTypes.data(),
8211 paramTypes.size(),
8212 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008213 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008214 exprFunctionType->getExtInfo());
8215 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008216
8217 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008218 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008219 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008220
8221 if (!oldBlock->blockMissingReturnType()) {
8222 blockScope->HasImplicitReturnType = false;
8223 blockScope->ReturnType = exprResultType;
8224 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008225
John McCall711c52b2011-01-05 12:14:39 +00008226 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008227 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008228 if (body.isInvalid()) {
8229 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008230 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008231 }
John McCall711c52b2011-01-05 12:14:39 +00008232
John McCallc6ac9c32011-02-04 18:33:18 +00008233#ifndef NDEBUG
8234 // In builds with assertions, make sure that we captured everything we
8235 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008236 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8237 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8238 e = oldBlock->capture_end(); i != e; ++i) {
8239 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008240
Douglas Gregorfc921372011-05-20 15:32:55 +00008241 // Ignore parameter packs.
8242 if (isa<ParmVarDecl>(oldCapture) &&
8243 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8244 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008245
Douglas Gregorfc921372011-05-20 15:32:55 +00008246 VarDecl *newCapture =
8247 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8248 oldCapture));
8249 assert(blockScope->CaptureMap.count(newCapture));
8250 }
John McCallc6ac9c32011-02-04 18:33:18 +00008251 }
8252#endif
8253
8254 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8255 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008256}
8257
Mike Stump1eb44332009-09-09 15:08:12 +00008258template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008259ExprResult
John McCall454feb92009-12-08 09:21:05 +00008260TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008261 ValueDecl *ND
8262 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8263 E->getDecl()));
8264 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00008265 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00008266
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008267 if (!getDerived().AlwaysRebuild() &&
8268 ND == E->getDecl()) {
8269 // Mark it referenced in the new context regardless.
8270 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00008271 SemaRef.MarkBlockDeclRefReferenced(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008272
John McCall3fa5cae2010-10-26 07:05:15 +00008273 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008274 }
8275
Abramo Bagnara25777432010-08-11 22:01:17 +00008276 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00008277 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00008278 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008279}
Mike Stump1eb44332009-09-09 15:08:12 +00008280
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008281template<typename Derived>
8282ExprResult
8283TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008284 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008285}
Eli Friedman276b0612011-10-11 02:20:01 +00008286
8287template<typename Derived>
8288ExprResult
8289TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008290 QualType RetTy = getDerived().TransformType(E->getType());
8291 bool ArgumentChanged = false;
8292 ASTOwningVector<Expr*> SubExprs(SemaRef);
8293 SubExprs.reserve(E->getNumSubExprs());
8294 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8295 SubExprs, &ArgumentChanged))
8296 return ExprError();
8297
8298 if (!getDerived().AlwaysRebuild() &&
8299 !ArgumentChanged)
8300 return SemaRef.Owned(E);
8301
8302 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8303 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008304}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008305
Douglas Gregorb98b1992009-08-11 05:31:07 +00008306//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008307// Type reconstruction
8308//===----------------------------------------------------------------------===//
8309
Mike Stump1eb44332009-09-09 15:08:12 +00008310template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008311QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8312 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008313 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008314 getDerived().getBaseEntity());
8315}
8316
Mike Stump1eb44332009-09-09 15:08:12 +00008317template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008318QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8319 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008320 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008321 getDerived().getBaseEntity());
8322}
8323
Mike Stump1eb44332009-09-09 15:08:12 +00008324template<typename Derived>
8325QualType
John McCall85737a72009-10-30 00:06:24 +00008326TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8327 bool WrittenAsLValue,
8328 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008329 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008330 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008331}
8332
8333template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008334QualType
John McCall85737a72009-10-30 00:06:24 +00008335TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8336 QualType ClassType,
8337 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008338 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008339 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008340}
8341
8342template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008343QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008344TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8345 ArrayType::ArraySizeModifier SizeMod,
8346 const llvm::APInt *Size,
8347 Expr *SizeExpr,
8348 unsigned IndexTypeQuals,
8349 SourceRange BracketsRange) {
8350 if (SizeExpr || !Size)
8351 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8352 IndexTypeQuals, BracketsRange,
8353 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008354
8355 QualType Types[] = {
8356 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8357 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8358 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008359 };
8360 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8361 QualType SizeType;
8362 for (unsigned I = 0; I != NumTypes; ++I)
8363 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8364 SizeType = Types[I];
8365 break;
8366 }
Mike Stump1eb44332009-09-09 15:08:12 +00008367
Eli Friedman01f276d2012-01-25 23:20:27 +00008368 // Note that we can return a VariableArrayType here in the case where
8369 // the element type was a dependent VariableArrayType.
8370 IntegerLiteral *ArraySize
8371 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8372 /*FIXME*/BracketsRange.getBegin());
8373 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008374 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008375 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008376}
Mike Stump1eb44332009-09-09 15:08:12 +00008377
Douglas Gregor577f75a2009-08-04 16:50:30 +00008378template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008379QualType
8380TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008381 ArrayType::ArraySizeModifier SizeMod,
8382 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008383 unsigned IndexTypeQuals,
8384 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008385 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008386 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008387}
8388
8389template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008390QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008391TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008392 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008393 unsigned IndexTypeQuals,
8394 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008395 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008396 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008397}
Mike Stump1eb44332009-09-09 15:08:12 +00008398
Douglas Gregor577f75a2009-08-04 16:50:30 +00008399template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008400QualType
8401TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008402 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008403 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008404 unsigned IndexTypeQuals,
8405 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008406 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008407 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008408 IndexTypeQuals, BracketsRange);
8409}
8410
8411template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008412QualType
8413TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008414 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008415 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008416 unsigned IndexTypeQuals,
8417 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008418 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008419 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008420 IndexTypeQuals, BracketsRange);
8421}
8422
8423template<typename Derived>
8424QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008425 unsigned NumElements,
8426 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008427 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008428 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008429}
Mike Stump1eb44332009-09-09 15:08:12 +00008430
Douglas Gregor577f75a2009-08-04 16:50:30 +00008431template<typename Derived>
8432QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8433 unsigned NumElements,
8434 SourceLocation AttributeLoc) {
8435 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8436 NumElements, true);
8437 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008438 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8439 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008440 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008441}
Mike Stump1eb44332009-09-09 15:08:12 +00008442
Douglas Gregor577f75a2009-08-04 16:50:30 +00008443template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008444QualType
8445TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008446 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008447 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008448 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008449}
Mike Stump1eb44332009-09-09 15:08:12 +00008450
Douglas Gregor577f75a2009-08-04 16:50:30 +00008451template<typename Derived>
8452QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008453 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008454 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008455 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008456 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00008457 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008458 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008459 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008460 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008461 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008462 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008463 getDerived().getBaseEntity(),
8464 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008465}
Mike Stump1eb44332009-09-09 15:08:12 +00008466
Douglas Gregor577f75a2009-08-04 16:50:30 +00008467template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008468QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8469 return SemaRef.Context.getFunctionNoProtoType(T);
8470}
8471
8472template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008473QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8474 assert(D && "no decl found");
8475 if (D->isInvalidDecl()) return QualType();
8476
Douglas Gregor92e986e2010-04-22 16:44:27 +00008477 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008478 TypeDecl *Ty;
8479 if (isa<UsingDecl>(D)) {
8480 UsingDecl *Using = cast<UsingDecl>(D);
8481 assert(Using->isTypeName() &&
8482 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8483
8484 // A valid resolved using typename decl points to exactly one type decl.
8485 assert(++Using->shadow_begin() == Using->shadow_end());
8486 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008487
John McCalled976492009-12-04 22:46:56 +00008488 } else {
8489 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8490 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8491 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8492 }
8493
8494 return SemaRef.Context.getTypeDeclType(Ty);
8495}
8496
8497template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008498QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8499 SourceLocation Loc) {
8500 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008501}
8502
8503template<typename Derived>
8504QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8505 return SemaRef.Context.getTypeOfType(Underlying);
8506}
8507
8508template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008509QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8510 SourceLocation Loc) {
8511 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008512}
8513
8514template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008515QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8516 UnaryTransformType::UTTKind UKind,
8517 SourceLocation Loc) {
8518 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8519}
8520
8521template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008522QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008523 TemplateName Template,
8524 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008525 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008526 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008527}
Mike Stump1eb44332009-09-09 15:08:12 +00008528
Douglas Gregordcee1a12009-08-06 05:28:30 +00008529template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00008530QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8531 SourceLocation KWLoc) {
8532 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8533}
8534
8535template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008536TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008537TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008538 bool TemplateKW,
8539 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008540 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008541 Template);
8542}
8543
8544template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008545TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008546TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8547 const IdentifierInfo &Name,
8548 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008549 QualType ObjectType,
8550 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008551 UnqualifiedId TemplateName;
8552 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008553 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008554 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00008555 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008556 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008557 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008558 /*EnteringContext=*/false,
8559 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008560 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008561}
Mike Stump1eb44332009-09-09 15:08:12 +00008562
Douglas Gregorb98b1992009-08-11 05:31:07 +00008563template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008564TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008565TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008566 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008567 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008568 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008569 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008570 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008571 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008572 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008573 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00008574 Sema::TemplateTy Template;
8575 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008576 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00008577 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008578 /*EnteringContext=*/false,
8579 Template);
8580 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008581}
Sean Huntc3021132010-05-05 15:23:54 +00008582
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008583template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008584ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008585TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8586 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008587 Expr *OrigCallee,
8588 Expr *First,
8589 Expr *Second) {
8590 Expr *Callee = OrigCallee->IgnoreParenCasts();
8591 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008592
Douglas Gregorb98b1992009-08-11 05:31:07 +00008593 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008594 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008595 if (!First->getType()->isOverloadableType() &&
8596 !Second->getType()->isOverloadableType())
8597 return getSema().CreateBuiltinArraySubscriptExpr(First,
8598 Callee->getLocStart(),
8599 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008600 } else if (Op == OO_Arrow) {
8601 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008602 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8603 } else if (Second == 0 || isPostIncDec) {
8604 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008605 // The argument is not of overloadable type, so try to create a
8606 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008607 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008608 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008609
John McCall9ae2f072010-08-23 23:25:46 +00008610 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008611 }
8612 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008613 if (!First->getType()->isOverloadableType() &&
8614 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008615 // Neither of the arguments is an overloadable type, so try to
8616 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008617 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008618 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008619 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008620 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008621 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008622
Douglas Gregorb98b1992009-08-11 05:31:07 +00008623 return move(Result);
8624 }
8625 }
Mike Stump1eb44332009-09-09 15:08:12 +00008626
8627 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008628 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008629 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008630
John McCall9ae2f072010-08-23 23:25:46 +00008631 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008632 assert(ULE->requiresADL());
8633
8634 // FIXME: Do we have to check
8635 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008636 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008637 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008638 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008639 }
Mike Stump1eb44332009-09-09 15:08:12 +00008640
Douglas Gregorb98b1992009-08-11 05:31:07 +00008641 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008642 Expr *Args[2] = { First, Second };
8643 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008644
Douglas Gregorb98b1992009-08-11 05:31:07 +00008645 // Create the overloaded operator invocation for unary operators.
8646 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008647 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008648 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008649 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008650 }
Mike Stump1eb44332009-09-09 15:08:12 +00008651
Douglas Gregor5b8968c2011-07-15 16:25:15 +00008652 if (Op == OO_Subscript) {
8653 SourceLocation LBrace;
8654 SourceLocation RBrace;
8655
8656 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8657 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8658 LBrace = SourceLocation::getFromRawEncoding(
8659 NameLoc.CXXOperatorName.BeginOpNameLoc);
8660 RBrace = SourceLocation::getFromRawEncoding(
8661 NameLoc.CXXOperatorName.EndOpNameLoc);
8662 } else {
8663 LBrace = Callee->getLocStart();
8664 RBrace = OpLoc;
8665 }
8666
8667 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8668 First, Second);
8669 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00008670
Douglas Gregorb98b1992009-08-11 05:31:07 +00008671 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008672 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008673 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008674 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8675 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008676 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008677
Mike Stump1eb44332009-09-09 15:08:12 +00008678 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008679}
Mike Stump1eb44332009-09-09 15:08:12 +00008680
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008681template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008682ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008683TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008684 SourceLocation OperatorLoc,
8685 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008686 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008687 TypeSourceInfo *ScopeType,
8688 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008689 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008690 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008691 QualType BaseType = Base->getType();
8692 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008693 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008694 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008695 !BaseType->getAs<PointerType>()->getPointeeType()
8696 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008697 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008698 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008699 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008700 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008701 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008702 /*FIXME?*/true);
8703 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008704
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008705 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008706 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8707 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8708 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8709 NameInfo.setNamedTypeInfo(DestroyedType);
8710
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008711 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008712
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008713 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00008714 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008715 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008716 SS, TemplateKWLoc,
8717 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008718 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008719 /*TemplateArgs*/ 0);
8720}
8721
Douglas Gregor577f75a2009-08-04 16:50:30 +00008722} // end namespace clang
8723
8724#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H