blob: 4742bbfc96b022ebbd0c5cdfa777fccb13503dcd [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,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001649 MultiExprArg SubExprs,
1650 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001651 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001652 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001653 }
Mike Stump1eb44332009-09-09 15:08:12 +00001654
Douglas Gregorb98b1992009-08-11 05:31:07 +00001655 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001656 ///
1657 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001658 /// rather than attempting to map the label statement itself.
1659 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001660 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001661 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001662 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001663 }
Mike Stump1eb44332009-09-09 15:08:12 +00001664
Douglas Gregorb98b1992009-08-11 05:31:07 +00001665 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001666 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 /// By default, performs semantic analysis to build the new expression.
1668 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001669 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001670 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001671 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001672 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 }
Mike Stump1eb44332009-09-09 15:08:12 +00001674
Douglas Gregorb98b1992009-08-11 05:31:07 +00001675 /// \brief Build a new __builtin_choose_expr expression.
1676 ///
1677 /// By default, performs semantic analysis to build the new expression.
1678 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001679 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001680 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001681 SourceLocation RParenLoc) {
1682 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001683 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001684 RParenLoc);
1685 }
Mike Stump1eb44332009-09-09 15:08:12 +00001686
Peter Collingbournef111d932011-04-15 00:35:48 +00001687 /// \brief Build a new generic selection expression.
1688 ///
1689 /// By default, performs semantic analysis to build the new expression.
1690 /// Subclasses may override this routine to provide different behavior.
1691 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1692 SourceLocation DefaultLoc,
1693 SourceLocation RParenLoc,
1694 Expr *ControllingExpr,
1695 TypeSourceInfo **Types,
1696 Expr **Exprs,
1697 unsigned NumAssocs) {
1698 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1699 ControllingExpr, Types, Exprs,
1700 NumAssocs);
1701 }
1702
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 /// \brief Build a new overloaded operator call expression.
1704 ///
1705 /// By default, performs semantic analysis to build the new expression.
1706 /// The semantic analysis provides the behavior of template instantiation,
1707 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001708 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001709 /// argument-dependent lookup, etc. Subclasses may override this routine to
1710 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001711 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001712 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001713 Expr *Callee,
1714 Expr *First,
1715 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001716
1717 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001718 /// reinterpret_cast.
1719 ///
1720 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001721 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001723 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001724 Stmt::StmtClass Class,
1725 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001726 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001727 SourceLocation RAngleLoc,
1728 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001729 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001730 SourceLocation RParenLoc) {
1731 switch (Class) {
1732 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001733 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001734 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001735 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001736
1737 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001738 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001739 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001740 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001741
Douglas Gregorb98b1992009-08-11 05:31:07 +00001742 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001743 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001744 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001745 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001747
Douglas Gregorb98b1992009-08-11 05:31:07 +00001748 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001749 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001750 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001751 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001752
Douglas Gregorb98b1992009-08-11 05:31:07 +00001753 default:
David Blaikieb219cfc2011-09-23 05:06:16 +00001754 llvm_unreachable("Invalid C++ named cast");
Douglas Gregorb98b1992009-08-11 05:31:07 +00001755 }
Mike Stump1eb44332009-09-09 15:08:12 +00001756
John McCallf312b1e2010-08-26 23:41:50 +00001757 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001758 }
Mike Stump1eb44332009-09-09 15:08:12 +00001759
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 /// \brief Build a new C++ static_cast expression.
1761 ///
1762 /// By default, performs semantic analysis to build the new expression.
1763 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001764 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001765 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001766 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001767 SourceLocation RAngleLoc,
1768 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001769 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001770 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001771 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001772 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001773 SourceRange(LAngleLoc, RAngleLoc),
1774 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001775 }
1776
1777 /// \brief Build a new C++ dynamic_cast expression.
1778 ///
1779 /// By default, performs semantic analysis to build the new expression.
1780 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001781 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001782 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001783 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784 SourceLocation RAngleLoc,
1785 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001786 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001787 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001788 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001789 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001790 SourceRange(LAngleLoc, RAngleLoc),
1791 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001792 }
1793
1794 /// \brief Build a new C++ reinterpret_cast expression.
1795 ///
1796 /// By default, performs semantic analysis to build the new expression.
1797 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001798 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001800 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 SourceLocation RAngleLoc,
1802 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001803 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001804 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001805 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001806 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001807 SourceRange(LAngleLoc, RAngleLoc),
1808 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001809 }
1810
1811 /// \brief Build a new C++ const_cast expression.
1812 ///
1813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001815 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001817 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001818 SourceLocation RAngleLoc,
1819 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001820 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001821 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001822 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001823 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001824 SourceRange(LAngleLoc, RAngleLoc),
1825 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001826 }
Mike Stump1eb44332009-09-09 15:08:12 +00001827
Douglas Gregorb98b1992009-08-11 05:31:07 +00001828 /// \brief Build a new C++ functional-style cast expression.
1829 ///
1830 /// By default, performs semantic analysis to build the new expression.
1831 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001832 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1833 SourceLocation LParenLoc,
1834 Expr *Sub,
1835 SourceLocation RParenLoc) {
1836 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001837 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001838 RParenLoc);
1839 }
Mike Stump1eb44332009-09-09 15:08:12 +00001840
Douglas Gregorb98b1992009-08-11 05:31:07 +00001841 /// \brief Build a new C++ typeid(type) expression.
1842 ///
1843 /// By default, performs semantic analysis to build the new expression.
1844 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001845 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001846 SourceLocation TypeidLoc,
1847 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001848 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001849 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001850 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001851 }
Mike Stump1eb44332009-09-09 15:08:12 +00001852
Francois Pichet01b7c302010-09-08 12:20:18 +00001853
Douglas Gregorb98b1992009-08-11 05:31:07 +00001854 /// \brief Build a new C++ typeid(expr) expression.
1855 ///
1856 /// By default, performs semantic analysis to build the new expression.
1857 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001858 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001859 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001860 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001861 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001862 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001863 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001864 }
1865
Francois Pichet01b7c302010-09-08 12:20:18 +00001866 /// \brief Build a new C++ __uuidof(type) expression.
1867 ///
1868 /// By default, performs semantic analysis to build the new expression.
1869 /// Subclasses may override this routine to provide different behavior.
1870 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1871 SourceLocation TypeidLoc,
1872 TypeSourceInfo *Operand,
1873 SourceLocation RParenLoc) {
1874 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1875 RParenLoc);
1876 }
1877
1878 /// \brief Build a new C++ __uuidof(expr) expression.
1879 ///
1880 /// By default, performs semantic analysis to build the new expression.
1881 /// Subclasses may override this routine to provide different behavior.
1882 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1883 SourceLocation TypeidLoc,
1884 Expr *Operand,
1885 SourceLocation RParenLoc) {
1886 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1887 RParenLoc);
1888 }
1889
Douglas Gregorb98b1992009-08-11 05:31:07 +00001890 /// \brief Build a new C++ "this" expression.
1891 ///
1892 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001893 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001894 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001895 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001896 QualType ThisType,
1897 bool isImplicit) {
Eli Friedmanb69b42c2012-01-11 02:36:31 +00001898 getSema().CheckCXXThisCapture(ThisLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001899 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001900 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1901 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001902 }
1903
1904 /// \brief Build a new C++ throw expression.
1905 ///
1906 /// By default, performs semantic analysis to build the new expression.
1907 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorbca01b42011-07-06 22:04:06 +00001908 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1909 bool IsThrownVariableInScope) {
1910 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001911 }
1912
1913 /// \brief Build a new C++ default-argument expression.
1914 ///
1915 /// By default, builds a new default-argument expression, which does not
1916 /// require any semantic analysis. Subclasses may override this routine to
1917 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001918 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001919 ParmVarDecl *Param) {
1920 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1921 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001922 }
1923
1924 /// \brief Build a new C++ zero-initialization expression.
1925 ///
1926 /// By default, performs semantic analysis to build the new expression.
1927 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001928 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1929 SourceLocation LParenLoc,
1930 SourceLocation RParenLoc) {
1931 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001932 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001933 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001934 }
Mike Stump1eb44332009-09-09 15:08:12 +00001935
Douglas Gregorb98b1992009-08-11 05:31:07 +00001936 /// \brief Build a new C++ "new" expression.
1937 ///
1938 /// By default, performs semantic analysis to build the new expression.
1939 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001940 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001941 bool UseGlobal,
1942 SourceLocation PlacementLParen,
1943 MultiExprArg PlacementArgs,
1944 SourceLocation PlacementRParen,
1945 SourceRange TypeIdParens,
1946 QualType AllocatedType,
1947 TypeSourceInfo *AllocatedTypeInfo,
1948 Expr *ArraySize,
1949 SourceLocation ConstructorLParen,
1950 MultiExprArg ConstructorArgs,
1951 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001952 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001953 PlacementLParen,
1954 move(PlacementArgs),
1955 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001956 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001957 AllocatedType,
1958 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001959 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001960 ConstructorLParen,
1961 move(ConstructorArgs),
1962 ConstructorRParen);
1963 }
Mike Stump1eb44332009-09-09 15:08:12 +00001964
Douglas Gregorb98b1992009-08-11 05:31:07 +00001965 /// \brief Build a new C++ "delete" expression.
1966 ///
1967 /// By default, performs semantic analysis to build the new expression.
1968 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001969 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001970 bool IsGlobalDelete,
1971 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001972 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001973 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001974 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001975 }
Mike Stump1eb44332009-09-09 15:08:12 +00001976
Douglas Gregorb98b1992009-08-11 05:31:07 +00001977 /// \brief Build a new unary type trait expression.
1978 ///
1979 /// By default, performs semantic analysis to build the new expression.
1980 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001981 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001982 SourceLocation StartLoc,
1983 TypeSourceInfo *T,
1984 SourceLocation RParenLoc) {
1985 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001986 }
1987
Francois Pichet6ad6f282010-12-07 00:08:36 +00001988 /// \brief Build a new binary type trait expression.
1989 ///
1990 /// By default, performs semantic analysis to build the new expression.
1991 /// Subclasses may override this routine to provide different behavior.
1992 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1993 SourceLocation StartLoc,
1994 TypeSourceInfo *LhsT,
1995 TypeSourceInfo *RhsT,
1996 SourceLocation RParenLoc) {
1997 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1998 }
1999
John Wiegley21ff2e52011-04-28 00:16:57 +00002000 /// \brief Build a new array type trait expression.
2001 ///
2002 /// By default, performs semantic analysis to build the new expression.
2003 /// Subclasses may override this routine to provide different behavior.
2004 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2005 SourceLocation StartLoc,
2006 TypeSourceInfo *TSInfo,
2007 Expr *DimExpr,
2008 SourceLocation RParenLoc) {
2009 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2010 }
2011
John Wiegley55262202011-04-25 06:54:41 +00002012 /// \brief Build a new expression trait expression.
2013 ///
2014 /// By default, performs semantic analysis to build the new expression.
2015 /// Subclasses may override this routine to provide different behavior.
2016 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2017 SourceLocation StartLoc,
2018 Expr *Queried,
2019 SourceLocation RParenLoc) {
2020 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2021 }
2022
Mike Stump1eb44332009-09-09 15:08:12 +00002023 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00002024 /// expression.
2025 ///
2026 /// By default, performs semantic analysis to build the new expression.
2027 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002028 ExprResult RebuildDependentScopeDeclRefExpr(
2029 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002030 SourceLocation TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00002031 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00002032 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002033 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00002034 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00002035
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002036 if (TemplateArgs || TemplateKWLoc.isValid())
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002037 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002038 NameInfo, TemplateArgs);
John McCallf7a1a742009-11-24 19:00:30 +00002039
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002040 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002041 }
2042
2043 /// \brief Build a new template-id expression.
2044 ///
2045 /// By default, performs semantic analysis to build the new expression.
2046 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002047 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002048 SourceLocation TemplateKWLoc,
2049 LookupResult &R,
2050 bool RequiresADL,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00002051 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002052 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2053 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002054 }
2055
2056 /// \brief Build a new object-construction expression.
2057 ///
2058 /// By default, performs semantic analysis to build the new expression.
2059 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002060 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002061 SourceLocation Loc,
2062 CXXConstructorDecl *Constructor,
2063 bool IsElidable,
2064 MultiExprArg Args,
2065 bool HadMultipleCandidates,
2066 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002067 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002068 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002069 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002070 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002071 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002072 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002073
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002074 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002075 move_arg(ConvertedArgs),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00002076 HadMultipleCandidates,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002077 RequiresZeroInit, ConstructKind,
2078 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002079 }
2080
2081 /// \brief Build a new object-construction expression.
2082 ///
2083 /// By default, performs semantic analysis to build the new expression.
2084 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002085 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2086 SourceLocation LParenLoc,
2087 MultiExprArg Args,
2088 SourceLocation RParenLoc) {
2089 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002090 LParenLoc,
2091 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002092 RParenLoc);
2093 }
2094
2095 /// \brief Build a new object-construction expression.
2096 ///
2097 /// By default, performs semantic analysis to build the new expression.
2098 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002099 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2100 SourceLocation LParenLoc,
2101 MultiExprArg Args,
2102 SourceLocation RParenLoc) {
2103 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002104 LParenLoc,
2105 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002106 RParenLoc);
2107 }
Mike Stump1eb44332009-09-09 15:08:12 +00002108
Douglas Gregorb98b1992009-08-11 05:31:07 +00002109 /// \brief Build a new member reference expression.
2110 ///
2111 /// By default, performs semantic analysis to build the new expression.
2112 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002113 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002114 QualType BaseType,
2115 bool IsArrow,
2116 SourceLocation OperatorLoc,
2117 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002118 SourceLocation TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00002119 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002120 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002121 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002122 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002123 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002124
John McCall9ae2f072010-08-23 23:25:46 +00002125 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002126 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002127 SS, TemplateKWLoc,
2128 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002129 MemberNameInfo,
2130 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002131 }
2132
John McCall129e2df2009-11-30 22:42:35 +00002133 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002134 ///
2135 /// By default, performs semantic analysis to build the new expression.
2136 /// Subclasses may override this routine to provide different behavior.
Richard Smith9138b4e2011-10-26 19:06:56 +00002137 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2138 SourceLocation OperatorLoc,
2139 bool IsArrow,
2140 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002141 SourceLocation TemplateKWLoc,
Richard Smith9138b4e2011-10-26 19:06:56 +00002142 NamedDecl *FirstQualifierInScope,
2143 LookupResult &R,
John McCall129e2df2009-11-30 22:42:35 +00002144 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002145 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002146 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002147
John McCall9ae2f072010-08-23 23:25:46 +00002148 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002149 OperatorLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002150 SS, TemplateKWLoc,
2151 FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00002152 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002153 }
Mike Stump1eb44332009-09-09 15:08:12 +00002154
Sebastian Redl2e156222010-09-10 20:55:43 +00002155 /// \brief Build a new noexcept expression.
2156 ///
2157 /// By default, performs semantic analysis to build the new expression.
2158 /// Subclasses may override this routine to provide different behavior.
2159 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2160 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2161 }
2162
Douglas Gregoree8aff02011-01-04 17:33:58 +00002163 /// \brief Build a new expression to compute the length of a parameter pack.
2164 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2165 SourceLocation PackLoc,
2166 SourceLocation RParenLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002167 llvm::Optional<unsigned> Length) {
2168 if (Length)
2169 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2170 OperatorLoc, Pack, PackLoc,
2171 RParenLoc, *Length);
2172
Douglas Gregoree8aff02011-01-04 17:33:58 +00002173 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2174 OperatorLoc, Pack, PackLoc,
Douglas Gregor089e8932011-10-10 18:59:29 +00002175 RParenLoc);
Douglas Gregoree8aff02011-01-04 17:33:58 +00002176 }
2177
Douglas Gregorb98b1992009-08-11 05:31:07 +00002178 /// \brief Build a new Objective-C @encode expression.
2179 ///
2180 /// By default, performs semantic analysis to build the new expression.
2181 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002182 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002183 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002184 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002185 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002186 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002187 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002188
Douglas Gregor92e986e2010-04-22 16:44:27 +00002189 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002190 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002191 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002192 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002193 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002194 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002195 MultiExprArg Args,
2196 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002197 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2198 ReceiverTypeInfo->getType(),
2199 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002200 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002201 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002202 }
2203
2204 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002205 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002206 Selector Sel,
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002207 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002208 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002209 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002210 MultiExprArg Args,
2211 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002212 return SemaRef.BuildInstanceMessage(Receiver,
2213 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002214 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00002215 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002216 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002217 }
2218
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002219 /// \brief Build a new Objective-C ivar reference expression.
2220 ///
2221 /// By default, performs semantic analysis to build the new expression.
2222 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002223 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002224 SourceLocation IvarLoc,
2225 bool IsArrow, bool IsFreeIvar) {
2226 // FIXME: We lose track of the IsFreeIvar bit.
2227 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002228 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002229 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2230 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002231 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002232 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002233 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002234 false);
John Wiegley429bb272011-04-08 18:41:53 +00002235 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002236 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002237
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002238 if (Result.get())
2239 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002240
John Wiegley429bb272011-04-08 18:41:53 +00002241 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002242 /*FIXME:*/IvarLoc, IsArrow,
2243 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002244 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002245 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002246 /*TemplateArgs=*/0);
2247 }
Douglas Gregore3303542010-04-26 20:47:02 +00002248
2249 /// \brief Build a new Objective-C property reference expression.
2250 ///
2251 /// By default, performs semantic analysis to build the new expression.
2252 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002253 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall3c3b7f92011-10-25 17:37:35 +00002254 ObjCPropertyDecl *Property,
2255 SourceLocation PropertyLoc) {
Douglas Gregore3303542010-04-26 20:47:02 +00002256 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002257 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002258 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2259 Sema::LookupMemberName);
2260 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002261 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002262 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002263 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002264 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002265 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002266
Douglas Gregore3303542010-04-26 20:47:02 +00002267 if (Result.get())
2268 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002269
John Wiegley429bb272011-04-08 18:41:53 +00002270 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002271 /*FIXME:*/PropertyLoc, IsArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002272 SS, SourceLocation(),
Douglas Gregore3303542010-04-26 20:47:02 +00002273 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002274 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002275 /*TemplateArgs=*/0);
2276 }
Sean Huntc3021132010-05-05 15:23:54 +00002277
John McCall12f78a62010-12-02 01:19:52 +00002278 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002279 ///
2280 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002281 /// Subclasses may override this routine to provide different behavior.
2282 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2283 ObjCMethodDecl *Getter,
2284 ObjCMethodDecl *Setter,
2285 SourceLocation PropertyLoc) {
2286 // Since these expressions can only be value-dependent, we do not
2287 // need to perform semantic analysis again.
2288 return Owned(
2289 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2290 VK_LValue, OK_ObjCProperty,
2291 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002292 }
2293
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002294 /// \brief Build a new Objective-C "isa" expression.
2295 ///
2296 /// By default, performs semantic analysis to build the new expression.
2297 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002298 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002299 bool IsArrow) {
2300 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002301 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002302 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2303 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002304 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002305 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002306 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002307 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002308 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002309
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002310 if (Result.get())
2311 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002312
John Wiegley429bb272011-04-08 18:41:53 +00002313 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Abramo Bagnarae4b92762012-01-27 09:46:47 +00002314 /*FIXME:*/IsaLoc, IsArrow,
2315 SS, SourceLocation(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002316 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002317 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002318 /*TemplateArgs=*/0);
2319 }
Sean Huntc3021132010-05-05 15:23:54 +00002320
Douglas Gregorb98b1992009-08-11 05:31:07 +00002321 /// \brief Build a new shuffle vector expression.
2322 ///
2323 /// By default, performs semantic analysis to build the new expression.
2324 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002325 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002326 MultiExprArg SubExprs,
2327 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002328 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002329 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002330 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2331 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2332 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2333 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002334
Douglas Gregorb98b1992009-08-11 05:31:07 +00002335 // Build a reference to the __builtin_shufflevector builtin
2336 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002337 ExprResult Callee
2338 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2339 VK_LValue, BuiltinLoc));
2340 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2341 if (Callee.isInvalid())
2342 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002343
2344 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002345 unsigned NumSubExprs = SubExprs.size();
2346 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002347 ExprResult TheCall = SemaRef.Owned(
2348 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002349 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002350 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002351 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002352 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002353
Douglas Gregorb98b1992009-08-11 05:31:07 +00002354 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002355 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002356 }
John McCall43fed0d2010-11-12 08:19:04 +00002357
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002358 /// \brief Build a new template argument pack expansion.
2359 ///
2360 /// By default, performs semantic analysis to build a new pack expansion
2361 /// for a template argument. Subclasses may override this routine to provide
2362 /// different behavior.
2363 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002364 SourceLocation EllipsisLoc,
2365 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002366 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002367 case TemplateArgument::Expression: {
2368 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002369 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2370 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002371 if (Result.isInvalid())
2372 return TemplateArgumentLoc();
2373
2374 return TemplateArgumentLoc(Result.get(), Result.get());
2375 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002376
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002377 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002378 return TemplateArgumentLoc(TemplateArgument(
2379 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002380 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002381 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002382 Pattern.getTemplateNameLoc(),
2383 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002384
2385 case TemplateArgument::Null:
2386 case TemplateArgument::Integral:
2387 case TemplateArgument::Declaration:
2388 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002389 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002390 llvm_unreachable("Pack expansion pattern has no parameter packs");
2391
2392 case TemplateArgument::Type:
2393 if (TypeSourceInfo *Expansion
2394 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002395 EllipsisLoc,
2396 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002397 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2398 Expansion);
2399 break;
2400 }
2401
2402 return TemplateArgumentLoc();
2403 }
2404
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002405 /// \brief Build a new expression pack expansion.
2406 ///
2407 /// By default, performs semantic analysis to build a new pack expansion
2408 /// for an expression. Subclasses may override this routine to provide
2409 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002410 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2411 llvm::Optional<unsigned> NumExpansions) {
2412 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002413 }
Eli Friedmandfa64ba2011-10-14 22:48:56 +00002414
2415 /// \brief Build a new atomic operation expression.
2416 ///
2417 /// By default, performs semantic analysis to build the new expression.
2418 /// Subclasses may override this routine to provide different behavior.
2419 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2420 MultiExprArg SubExprs,
2421 QualType RetTy,
2422 AtomicExpr::AtomicOp Op,
2423 SourceLocation RParenLoc) {
2424 // Just create the expression; there is not any interesting semantic
2425 // analysis here because we can't actually build an AtomicExpr until
2426 // we are sure it is semantically sound.
2427 unsigned NumSubExprs = SubExprs.size();
2428 Expr **Subs = (Expr **)SubExprs.release();
2429 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs,
2430 NumSubExprs, RetTy, Op,
2431 RParenLoc);
2432 }
2433
John McCall43fed0d2010-11-12 08:19:04 +00002434private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002435 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2436 QualType ObjectType,
2437 NamedDecl *FirstQualifierInScope,
2438 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002439
2440 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2441 QualType ObjectType,
2442 NamedDecl *FirstQualifierInScope,
2443 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002444};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002445
Douglas Gregor43959a92009-08-20 07:17:43 +00002446template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002447StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002448 if (!S)
2449 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002450
Douglas Gregor43959a92009-08-20 07:17:43 +00002451 switch (S->getStmtClass()) {
2452 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002453
Douglas Gregor43959a92009-08-20 07:17:43 +00002454 // Transform individual statement nodes
2455#define STMT(Node, Parent) \
2456 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002457#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002458#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002459#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002460
Douglas Gregor43959a92009-08-20 07:17:43 +00002461 // Transform expressions by calling TransformExpr.
2462#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002463#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002464#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002465#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002466 {
John McCall60d7b3a2010-08-24 06:29:42 +00002467 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002468 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002469 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002470
John McCall9ae2f072010-08-23 23:25:46 +00002471 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002472 }
Mike Stump1eb44332009-09-09 15:08:12 +00002473 }
2474
John McCall3fa5cae2010-10-26 07:05:15 +00002475 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002476}
Mike Stump1eb44332009-09-09 15:08:12 +00002477
2478
Douglas Gregor670444e2009-08-04 22:27:00 +00002479template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002480ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002481 if (!E)
2482 return SemaRef.Owned(E);
2483
2484 switch (E->getStmtClass()) {
2485 case Stmt::NoStmtClass: break;
2486#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002487#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002488#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002489 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002490#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002491 }
2492
John McCall3fa5cae2010-10-26 07:05:15 +00002493 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002494}
2495
2496template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002497bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2498 unsigned NumInputs,
2499 bool IsCall,
Chris Lattner686775d2011-07-20 06:58:45 +00002500 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregoraa165f82011-01-03 19:04:46 +00002501 bool *ArgChanged) {
2502 for (unsigned I = 0; I != NumInputs; ++I) {
2503 // If requested, drop call arguments that need to be dropped.
2504 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2505 if (ArgChanged)
2506 *ArgChanged = true;
2507
2508 break;
2509 }
2510
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002511 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2512 Expr *Pattern = Expansion->getPattern();
2513
Chris Lattner686775d2011-07-20 06:58:45 +00002514 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002515 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2516 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2517
2518 // Determine whether the set of unexpanded parameter packs can and should
2519 // be expanded.
2520 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002521 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002522 llvm::Optional<unsigned> OrigNumExpansions
2523 = Expansion->getNumExpansions();
2524 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002525 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2526 Pattern->getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00002527 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00002528 Expand, RetainExpansion,
2529 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002530 return true;
2531
2532 if (!Expand) {
2533 // The transform has determined that we should perform a simple
2534 // transformation on the pack expansion, producing another pack
2535 // expansion.
2536 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2537 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2538 if (OutPattern.isInvalid())
2539 return true;
2540
2541 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002542 Expansion->getEllipsisLoc(),
2543 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002544 if (Out.isInvalid())
2545 return true;
2546
2547 if (ArgChanged)
2548 *ArgChanged = true;
2549 Outputs.push_back(Out.get());
2550 continue;
2551 }
John McCallc8fc90a2011-07-06 07:30:07 +00002552
2553 // Record right away that the argument was changed. This needs
2554 // to happen even if the array expands to nothing.
2555 if (ArgChanged) *ArgChanged = true;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002556
2557 // The transform has determined that we should perform an elementwise
2558 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002559 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002560 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2561 ExprResult Out = getDerived().TransformExpr(Pattern);
2562 if (Out.isInvalid())
2563 return true;
2564
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002565 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002566 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2567 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002568 if (Out.isInvalid())
2569 return true;
2570 }
2571
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002572 Outputs.push_back(Out.get());
2573 }
2574
2575 continue;
2576 }
2577
Douglas Gregoraa165f82011-01-03 19:04:46 +00002578 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2579 if (Result.isInvalid())
2580 return true;
2581
2582 if (Result.get() != Inputs[I] && ArgChanged)
2583 *ArgChanged = true;
2584
2585 Outputs.push_back(Result.get());
2586 }
2587
2588 return false;
2589}
2590
2591template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002592NestedNameSpecifierLoc
2593TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2594 NestedNameSpecifierLoc NNS,
2595 QualType ObjectType,
2596 NamedDecl *FirstQualifierInScope) {
Chris Lattner686775d2011-07-20 06:58:45 +00002597 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002598 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2599 Qualifier = Qualifier.getPrefix())
2600 Qualifiers.push_back(Qualifier);
2601
2602 CXXScopeSpec SS;
2603 while (!Qualifiers.empty()) {
2604 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2605 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2606
2607 switch (QNNS->getKind()) {
2608 case NestedNameSpecifier::Identifier:
2609 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2610 *QNNS->getAsIdentifier(),
2611 Q.getLocalBeginLoc(),
2612 Q.getLocalEndLoc(),
2613 ObjectType, false, SS,
2614 FirstQualifierInScope, false))
2615 return NestedNameSpecifierLoc();
2616
2617 break;
2618
2619 case NestedNameSpecifier::Namespace: {
2620 NamespaceDecl *NS
2621 = cast_or_null<NamespaceDecl>(
2622 getDerived().TransformDecl(
2623 Q.getLocalBeginLoc(),
2624 QNNS->getAsNamespace()));
2625 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2626 break;
2627 }
2628
2629 case NestedNameSpecifier::NamespaceAlias: {
2630 NamespaceAliasDecl *Alias
2631 = cast_or_null<NamespaceAliasDecl>(
2632 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2633 QNNS->getAsNamespaceAlias()));
2634 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2635 Q.getLocalEndLoc());
2636 break;
2637 }
2638
2639 case NestedNameSpecifier::Global:
2640 // There is no meaningful transformation that one could perform on the
2641 // global scope.
2642 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2643 break;
2644
2645 case NestedNameSpecifier::TypeSpecWithTemplate:
2646 case NestedNameSpecifier::TypeSpec: {
2647 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2648 FirstQualifierInScope, SS);
2649
2650 if (!TL)
2651 return NestedNameSpecifierLoc();
2652
2653 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2654 (SemaRef.getLangOptions().CPlusPlus0x &&
2655 TL.getType()->isEnumeralType())) {
2656 assert(!TL.getType().hasLocalQualifiers() &&
2657 "Can't get cv-qualifiers here");
Richard Smith95aafb22011-10-20 03:28:47 +00002658 if (TL.getType()->isEnumeralType())
2659 SemaRef.Diag(TL.getBeginLoc(),
2660 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002661 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2662 Q.getLocalEndLoc());
2663 break;
2664 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002665 // If the nested-name-specifier is an invalid type def, don't emit an
2666 // error because a previous error should have already been emitted.
2667 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2668 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2669 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2670 << TL.getType() << SS.getRange();
2671 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002672 return NestedNameSpecifierLoc();
2673 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002674 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002675
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002676 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002677 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002678 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002679 }
2680
2681 // Don't rebuild the nested-name-specifier if we don't have to.
2682 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2683 !getDerived().AlwaysRebuild())
2684 return NNS;
2685
2686 // If we can re-use the source-location data from the original
2687 // nested-name-specifier, do so.
2688 if (SS.location_size() == NNS.getDataLength() &&
2689 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2690 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2691
2692 // Allocate new nested-name-specifier location information.
2693 return SS.getWithLocInContext(SemaRef.Context);
2694}
2695
2696template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002697DeclarationNameInfo
2698TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002699::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002700 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002701 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002702 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002703
2704 switch (Name.getNameKind()) {
2705 case DeclarationName::Identifier:
2706 case DeclarationName::ObjCZeroArgSelector:
2707 case DeclarationName::ObjCOneArgSelector:
2708 case DeclarationName::ObjCMultiArgSelector:
2709 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002710 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002711 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002712 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002713
Douglas Gregor81499bb2009-09-03 22:13:48 +00002714 case DeclarationName::CXXConstructorName:
2715 case DeclarationName::CXXDestructorName:
2716 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002717 TypeSourceInfo *NewTInfo;
2718 CanQualType NewCanTy;
2719 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002720 NewTInfo = getDerived().TransformType(OldTInfo);
2721 if (!NewTInfo)
2722 return DeclarationNameInfo();
2723 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002724 }
2725 else {
2726 NewTInfo = 0;
2727 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002728 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002729 if (NewT.isNull())
2730 return DeclarationNameInfo();
2731 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2732 }
Mike Stump1eb44332009-09-09 15:08:12 +00002733
Abramo Bagnara25777432010-08-11 22:01:17 +00002734 DeclarationName NewName
2735 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2736 NewCanTy);
2737 DeclarationNameInfo NewNameInfo(NameInfo);
2738 NewNameInfo.setName(NewName);
2739 NewNameInfo.setNamedTypeInfo(NewTInfo);
2740 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002741 }
Mike Stump1eb44332009-09-09 15:08:12 +00002742 }
2743
David Blaikieb219cfc2011-09-23 05:06:16 +00002744 llvm_unreachable("Unknown name kind.");
Douglas Gregor81499bb2009-09-03 22:13:48 +00002745}
2746
2747template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002748TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002749TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2750 TemplateName Name,
2751 SourceLocation NameLoc,
2752 QualType ObjectType,
2753 NamedDecl *FirstQualifierInScope) {
2754 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2755 TemplateDecl *Template = QTN->getTemplateDecl();
2756 assert(Template && "qualified template name must refer to a template");
2757
2758 TemplateDecl *TransTemplate
2759 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2760 Template));
2761 if (!TransTemplate)
2762 return TemplateName();
2763
2764 if (!getDerived().AlwaysRebuild() &&
2765 SS.getScopeRep() == QTN->getQualifier() &&
2766 TransTemplate == Template)
2767 return Name;
2768
2769 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2770 TransTemplate);
2771 }
2772
2773 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2774 if (SS.getScopeRep()) {
2775 // These apply to the scope specifier, not the template.
2776 ObjectType = QualType();
2777 FirstQualifierInScope = 0;
2778 }
2779
2780 if (!getDerived().AlwaysRebuild() &&
2781 SS.getScopeRep() == DTN->getQualifier() &&
2782 ObjectType.isNull())
2783 return Name;
2784
2785 if (DTN->isIdentifier()) {
2786 return getDerived().RebuildTemplateName(SS,
2787 *DTN->getIdentifier(),
2788 NameLoc,
2789 ObjectType,
2790 FirstQualifierInScope);
2791 }
2792
2793 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2794 ObjectType);
2795 }
2796
2797 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2798 TemplateDecl *TransTemplate
2799 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2800 Template));
2801 if (!TransTemplate)
2802 return TemplateName();
2803
2804 if (!getDerived().AlwaysRebuild() &&
2805 TransTemplate == Template)
2806 return Name;
2807
2808 return TemplateName(TransTemplate);
2809 }
2810
2811 if (SubstTemplateTemplateParmPackStorage *SubstPack
2812 = Name.getAsSubstTemplateTemplateParmPack()) {
2813 TemplateTemplateParmDecl *TransParam
2814 = cast_or_null<TemplateTemplateParmDecl>(
2815 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2816 if (!TransParam)
2817 return TemplateName();
2818
2819 if (!getDerived().AlwaysRebuild() &&
2820 TransParam == SubstPack->getParameterPack())
2821 return Name;
2822
2823 return getDerived().RebuildTemplateName(TransParam,
2824 SubstPack->getArgumentPack());
2825 }
2826
2827 // These should be getting filtered out before they reach the AST.
2828 llvm_unreachable("overloaded function decl survived to here");
2829 return TemplateName();
2830}
2831
2832template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002833void TreeTransform<Derived>::InventTemplateArgumentLoc(
2834 const TemplateArgument &Arg,
2835 TemplateArgumentLoc &Output) {
2836 SourceLocation Loc = getDerived().getBaseLocation();
2837 switch (Arg.getKind()) {
2838 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002839 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002840 break;
2841
2842 case TemplateArgument::Type:
2843 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002844 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002845
John McCall833ca992009-10-29 08:12:44 +00002846 break;
2847
Douglas Gregor788cd062009-11-11 01:00:40 +00002848 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002849 case TemplateArgument::TemplateExpansion: {
2850 NestedNameSpecifierLocBuilder Builder;
2851 TemplateName Template = Arg.getAsTemplate();
2852 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2853 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2854 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2855 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2856
2857 if (Arg.getKind() == TemplateArgument::Template)
2858 Output = TemplateArgumentLoc(Arg,
2859 Builder.getWithLocInContext(SemaRef.Context),
2860 Loc);
2861 else
2862 Output = TemplateArgumentLoc(Arg,
2863 Builder.getWithLocInContext(SemaRef.Context),
2864 Loc, Loc);
2865
Douglas Gregor788cd062009-11-11 01:00:40 +00002866 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002867 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002868
John McCall833ca992009-10-29 08:12:44 +00002869 case TemplateArgument::Expression:
2870 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2871 break;
2872
2873 case TemplateArgument::Declaration:
2874 case TemplateArgument::Integral:
2875 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002876 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002877 break;
2878 }
2879}
2880
2881template<typename Derived>
2882bool TreeTransform<Derived>::TransformTemplateArgument(
2883 const TemplateArgumentLoc &Input,
2884 TemplateArgumentLoc &Output) {
2885 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002886 switch (Arg.getKind()) {
2887 case TemplateArgument::Null:
2888 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002889 Output = Input;
2890 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002891
Douglas Gregor670444e2009-08-04 22:27:00 +00002892 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002893 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002894 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002895 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002896
2897 DI = getDerived().TransformType(DI);
2898 if (!DI) return true;
2899
2900 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2901 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002902 }
Mike Stump1eb44332009-09-09 15:08:12 +00002903
Douglas Gregor670444e2009-08-04 22:27:00 +00002904 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002905 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002906 DeclarationName Name;
2907 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2908 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002909 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002910 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002911 if (!D) return true;
2912
John McCall828bff22009-10-29 18:45:58 +00002913 Expr *SourceExpr = Input.getSourceDeclExpression();
2914 if (SourceExpr) {
2915 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002916 Sema::ConstantEvaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002917 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002918 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002919 }
2920
2921 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002922 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002923 }
Mike Stump1eb44332009-09-09 15:08:12 +00002924
Douglas Gregor788cd062009-11-11 01:00:40 +00002925 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002926 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2927 if (QualifierLoc) {
2928 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2929 if (!QualifierLoc)
2930 return true;
2931 }
2932
Douglas Gregor1d752d72011-03-02 18:46:51 +00002933 CXXScopeSpec SS;
2934 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002935 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002936 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2937 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002938 if (Template.isNull())
2939 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002940
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002941 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002942 Input.getTemplateNameLoc());
2943 return false;
2944 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002945
2946 case TemplateArgument::TemplateExpansion:
2947 llvm_unreachable("Caller should expand pack expansions");
2948
Douglas Gregor670444e2009-08-04 22:27:00 +00002949 case TemplateArgument::Expression: {
Richard Smithf6702a32011-12-20 02:08:33 +00002950 // Template argument expressions are constant expressions.
Mike Stump1eb44332009-09-09 15:08:12 +00002951 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smithf6702a32011-12-20 02:08:33 +00002952 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002953
John McCall833ca992009-10-29 08:12:44 +00002954 Expr *InputExpr = Input.getSourceExpression();
2955 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2956
Chris Lattner223de242011-04-25 20:37:58 +00002957 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall833ca992009-10-29 08:12:44 +00002958 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002959 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002960 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002961 }
Mike Stump1eb44332009-09-09 15:08:12 +00002962
Douglas Gregor670444e2009-08-04 22:27:00 +00002963 case TemplateArgument::Pack: {
Chris Lattner686775d2011-07-20 06:58:45 +00002964 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregor670444e2009-08-04 22:27:00 +00002965 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002966 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002967 AEnd = Arg.pack_end();
2968 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002969
John McCall833ca992009-10-29 08:12:44 +00002970 // FIXME: preserve source information here when we start
2971 // caring about parameter packs.
2972
John McCall828bff22009-10-29 18:45:58 +00002973 TemplateArgumentLoc InputArg;
2974 TemplateArgumentLoc OutputArg;
2975 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2976 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002977 return true;
2978
John McCall828bff22009-10-29 18:45:58 +00002979 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002980 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002981
2982 TemplateArgument *TransformedArgsPtr
2983 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2984 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2985 TransformedArgsPtr);
2986 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2987 TransformedArgs.size()),
2988 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002989 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002990 }
2991 }
Mike Stump1eb44332009-09-09 15:08:12 +00002992
Douglas Gregor670444e2009-08-04 22:27:00 +00002993 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002994 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002995}
2996
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002997/// \brief Iterator adaptor that invents template argument location information
2998/// for each of the template arguments in its underlying iterator.
2999template<typename Derived, typename InputIterator>
3000class TemplateArgumentLocInventIterator {
3001 TreeTransform<Derived> &Self;
3002 InputIterator Iter;
3003
3004public:
3005 typedef TemplateArgumentLoc value_type;
3006 typedef TemplateArgumentLoc reference;
3007 typedef typename std::iterator_traits<InputIterator>::difference_type
3008 difference_type;
3009 typedef std::input_iterator_tag iterator_category;
3010
3011 class pointer {
3012 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003013
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003014 public:
3015 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3016
3017 const TemplateArgumentLoc *operator->() const { return &Arg; }
3018 };
3019
3020 TemplateArgumentLocInventIterator() { }
3021
3022 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3023 InputIterator Iter)
3024 : Self(Self), Iter(Iter) { }
3025
3026 TemplateArgumentLocInventIterator &operator++() {
3027 ++Iter;
3028 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00003029 }
3030
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003031 TemplateArgumentLocInventIterator operator++(int) {
3032 TemplateArgumentLocInventIterator Old(*this);
3033 ++(*this);
3034 return Old;
3035 }
3036
3037 reference operator*() const {
3038 TemplateArgumentLoc Result;
3039 Self.InventTemplateArgumentLoc(*Iter, Result);
3040 return Result;
3041 }
3042
3043 pointer operator->() const { return pointer(**this); }
3044
3045 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3046 const TemplateArgumentLocInventIterator &Y) {
3047 return X.Iter == Y.Iter;
3048 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00003049
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003050 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3051 const TemplateArgumentLocInventIterator &Y) {
3052 return X.Iter != Y.Iter;
3053 }
3054};
3055
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003056template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003057template<typename InputIterator>
3058bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3059 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003060 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003061 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003062 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003063 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003064
3065 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3066 // Unpack argument packs, which we translate them into separate
3067 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003068 // FIXME: We could do much better if we could guarantee that the
3069 // TemplateArgumentLocInfo for the pack expansion would be usable for
3070 // all of the template arguments in the argument pack.
3071 typedef TemplateArgumentLocInventIterator<Derived,
3072 TemplateArgument::pack_iterator>
3073 PackLocIterator;
3074 if (TransformTemplateArguments(PackLocIterator(*this,
3075 In.getArgument().pack_begin()),
3076 PackLocIterator(*this,
3077 In.getArgument().pack_end()),
3078 Outputs))
3079 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003080
3081 continue;
3082 }
3083
3084 if (In.getArgument().isPackExpansion()) {
3085 // We have a pack expansion, for which we will be substituting into
3086 // the pattern.
3087 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003088 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003089 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003090 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3091 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003092
Chris Lattner686775d2011-07-20 06:58:45 +00003093 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003094 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3095 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3096
3097 // Determine whether the set of unexpanded parameter packs can and should
3098 // be expanded.
3099 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003100 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003101 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003102 if (getDerived().TryExpandParameterPacks(Ellipsis,
3103 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003104 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003105 Expand,
3106 RetainExpansion,
3107 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003108 return true;
3109
3110 if (!Expand) {
3111 // The transform has determined that we should perform a simple
3112 // transformation on the pack expansion, producing another pack
3113 // expansion.
3114 TemplateArgumentLoc OutPattern;
3115 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3116 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3117 return true;
3118
Douglas Gregorcded4f62011-01-14 17:04:44 +00003119 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3120 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003121 if (Out.getArgument().isNull())
3122 return true;
3123
3124 Outputs.addArgument(Out);
3125 continue;
3126 }
3127
3128 // The transform has determined that we should perform an elementwise
3129 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003130 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003131 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3132
3133 if (getDerived().TransformTemplateArgument(Pattern, Out))
3134 return true;
3135
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003136 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003137 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3138 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003139 if (Out.getArgument().isNull())
3140 return true;
3141 }
3142
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003143 Outputs.addArgument(Out);
3144 }
3145
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003146 // If we're supposed to retain a pack expansion, do so by temporarily
3147 // forgetting the partially-substituted parameter pack.
3148 if (RetainExpansion) {
3149 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3150
3151 if (getDerived().TransformTemplateArgument(Pattern, Out))
3152 return true;
3153
Douglas Gregorcded4f62011-01-14 17:04:44 +00003154 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3155 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003156 if (Out.getArgument().isNull())
3157 return true;
3158
3159 Outputs.addArgument(Out);
3160 }
Douglas Gregord3731192011-01-10 07:32:04 +00003161
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003162 continue;
3163 }
3164
3165 // The simple case:
3166 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003167 return true;
3168
3169 Outputs.addArgument(Out);
3170 }
3171
3172 return false;
3173
3174}
3175
Douglas Gregor577f75a2009-08-04 16:50:30 +00003176//===----------------------------------------------------------------------===//
3177// Type transformation
3178//===----------------------------------------------------------------------===//
3179
3180template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003181QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003182 if (getDerived().AlreadyTransformed(T))
3183 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003184
John McCalla2becad2009-10-21 00:40:46 +00003185 // Temporary workaround. All of these transformations should
3186 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003187 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3188 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003189
John McCall43fed0d2010-11-12 08:19:04 +00003190 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003191
John McCalla2becad2009-10-21 00:40:46 +00003192 if (!NewDI)
3193 return QualType();
3194
3195 return NewDI->getType();
3196}
3197
3198template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003199TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smithf6702a32011-12-20 02:08:33 +00003200 // Refine the base location to the type's location.
3201 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3202 getDerived().getBaseEntity());
John McCalla2becad2009-10-21 00:40:46 +00003203 if (getDerived().AlreadyTransformed(DI->getType()))
3204 return DI;
3205
3206 TypeLocBuilder TLB;
3207
3208 TypeLoc TL = DI->getTypeLoc();
3209 TLB.reserve(TL.getFullDataSize());
3210
John McCall43fed0d2010-11-12 08:19:04 +00003211 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003212 if (Result.isNull())
3213 return 0;
3214
John McCalla93c9342009-12-07 02:54:59 +00003215 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003216}
3217
3218template<typename Derived>
3219QualType
John McCall43fed0d2010-11-12 08:19:04 +00003220TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003221 switch (T.getTypeLocClass()) {
3222#define ABSTRACT_TYPELOC(CLASS, PARENT)
3223#define TYPELOC(CLASS, PARENT) \
3224 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003225 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003226#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003227 }
Mike Stump1eb44332009-09-09 15:08:12 +00003228
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003229 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003230 return QualType();
3231}
3232
3233/// FIXME: By default, this routine adds type qualifiers only to types
3234/// that can have qualifiers, and silently suppresses those qualifiers
3235/// that are not permitted (e.g., qualifiers on reference or function
3236/// types). This is the right thing for template instantiation, but
3237/// probably not for other clients.
3238template<typename Derived>
3239QualType
3240TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003241 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003242 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003243
John McCall43fed0d2010-11-12 08:19:04 +00003244 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003245 if (Result.isNull())
3246 return QualType();
3247
3248 // Silently suppress qualifiers if the result type can't be qualified.
3249 // FIXME: this is the right thing for template instantiation, but
3250 // probably not for other clients.
3251 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003252 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003253
John McCallf85e1932011-06-15 23:02:42 +00003254 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003255 // resulting type.
3256 if (Quals.hasObjCLifetime()) {
3257 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3258 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003259 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003260 // Objective-C ARC:
3261 // A lifetime qualifier applied to a substituted template parameter
3262 // overrides the lifetime qualifier from the template argument.
3263 if (const SubstTemplateTypeParmType *SubstTypeParam
3264 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3265 QualType Replacement = SubstTypeParam->getReplacementType();
3266 Qualifiers Qs = Replacement.getQualifiers();
3267 Qs.removeObjCLifetime();
3268 Replacement
3269 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3270 Qs);
3271 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3272 SubstTypeParam->getReplacedParameter(),
3273 Replacement);
3274 TLB.TypeWasModifiedSafely(Result);
3275 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003276 // Otherwise, complain about the addition of a qualifier to an
3277 // already-qualified type.
3278 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003279 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003280 << Result << R;
3281
Douglas Gregore559ca12011-06-17 22:11:49 +00003282 Quals.removeObjCLifetime();
3283 }
3284 }
3285 }
John McCall28654742010-06-05 06:41:15 +00003286 if (!Quals.empty()) {
3287 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3288 TLB.push<QualifiedTypeLoc>(Result);
3289 // No location information to preserve.
3290 }
John McCalla2becad2009-10-21 00:40:46 +00003291
3292 return Result;
3293}
3294
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003295template<typename Derived>
3296TypeLoc
3297TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3298 QualType ObjectType,
3299 NamedDecl *UnqualLookup,
3300 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003301 QualType T = TL.getType();
3302 if (getDerived().AlreadyTransformed(T))
3303 return TL;
3304
3305 TypeLocBuilder TLB;
3306 QualType Result;
3307
3308 if (isa<TemplateSpecializationType>(T)) {
3309 TemplateSpecializationTypeLoc SpecTL
3310 = cast<TemplateSpecializationTypeLoc>(TL);
3311
3312 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003313 getDerived().TransformTemplateName(SS,
3314 SpecTL.getTypePtr()->getTemplateName(),
3315 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003316 ObjectType, UnqualLookup);
3317 if (Template.isNull())
3318 return TypeLoc();
3319
3320 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3321 Template);
3322 } else if (isa<DependentTemplateSpecializationType>(T)) {
3323 DependentTemplateSpecializationTypeLoc SpecTL
3324 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3325
Douglas Gregora88f09f2011-02-28 17:23:35 +00003326 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003327 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003328 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003329 SpecTL.getTemplateNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003330 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003331 if (Template.isNull())
3332 return TypeLoc();
3333
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003334 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003335 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003336 Template,
3337 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003338 } else {
3339 // Nothing special needs to be done for these.
3340 Result = getDerived().TransformType(TLB, TL);
3341 }
3342
3343 if (Result.isNull())
3344 return TypeLoc();
3345
3346 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3347}
3348
Douglas Gregorb71d8212011-03-02 18:32:08 +00003349template<typename Derived>
3350TypeSourceInfo *
3351TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3352 QualType ObjectType,
3353 NamedDecl *UnqualLookup,
3354 CXXScopeSpec &SS) {
3355 // FIXME: Painfully copy-paste from the above!
3356
3357 QualType T = TSInfo->getType();
3358 if (getDerived().AlreadyTransformed(T))
3359 return TSInfo;
3360
3361 TypeLocBuilder TLB;
3362 QualType Result;
3363
3364 TypeLoc TL = TSInfo->getTypeLoc();
3365 if (isa<TemplateSpecializationType>(T)) {
3366 TemplateSpecializationTypeLoc SpecTL
3367 = cast<TemplateSpecializationTypeLoc>(TL);
3368
3369 TemplateName Template
3370 = getDerived().TransformTemplateName(SS,
3371 SpecTL.getTypePtr()->getTemplateName(),
3372 SpecTL.getTemplateNameLoc(),
3373 ObjectType, UnqualLookup);
3374 if (Template.isNull())
3375 return 0;
3376
3377 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3378 Template);
3379 } else if (isa<DependentTemplateSpecializationType>(T)) {
3380 DependentTemplateSpecializationTypeLoc SpecTL
3381 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3382
3383 TemplateName Template
3384 = getDerived().RebuildTemplateName(SS,
3385 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00003386 SpecTL.getTemplateNameLoc(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00003387 ObjectType, UnqualLookup);
3388 if (Template.isNull())
3389 return 0;
3390
3391 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3392 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003393 Template,
3394 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003395 } else {
3396 // Nothing special needs to be done for these.
3397 Result = getDerived().TransformType(TLB, TL);
3398 }
3399
3400 if (Result.isNull())
3401 return 0;
3402
3403 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3404}
3405
John McCalla2becad2009-10-21 00:40:46 +00003406template <class TyLoc> static inline
3407QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3408 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3409 NewT.setNameLoc(T.getNameLoc());
3410 return T.getType();
3411}
3412
John McCalla2becad2009-10-21 00:40:46 +00003413template<typename Derived>
3414QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003415 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003416 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3417 NewT.setBuiltinLoc(T.getBuiltinLoc());
3418 if (T.needsExtraLocalData())
3419 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3420 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003421}
Mike Stump1eb44332009-09-09 15:08:12 +00003422
Douglas Gregor577f75a2009-08-04 16:50:30 +00003423template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003424QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003425 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003426 // FIXME: recurse?
3427 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003428}
Mike Stump1eb44332009-09-09 15:08:12 +00003429
Douglas Gregor577f75a2009-08-04 16:50:30 +00003430template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003431QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003432 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003433 QualType PointeeType
3434 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003435 if (PointeeType.isNull())
3436 return QualType();
3437
3438 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003439 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003440 // A dependent pointer type 'T *' has is being transformed such
3441 // that an Objective-C class type is being replaced for 'T'. The
3442 // resulting pointer type is an ObjCObjectPointerType, not a
3443 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003444 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003445
John McCallc12c5bb2010-05-15 11:32:37 +00003446 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3447 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003448 return Result;
3449 }
John McCall43fed0d2010-11-12 08:19:04 +00003450
Douglas Gregor92e986e2010-04-22 16:44:27 +00003451 if (getDerived().AlwaysRebuild() ||
3452 PointeeType != TL.getPointeeLoc().getType()) {
3453 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3454 if (Result.isNull())
3455 return QualType();
3456 }
John McCallf85e1932011-06-15 23:02:42 +00003457
3458 // Objective-C ARC can add lifetime qualifiers to the type that we're
3459 // pointing to.
3460 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3461
Douglas Gregor92e986e2010-04-22 16:44:27 +00003462 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3463 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003464 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003465}
Mike Stump1eb44332009-09-09 15:08:12 +00003466
3467template<typename Derived>
3468QualType
John McCalla2becad2009-10-21 00:40:46 +00003469TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003470 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003471 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003472 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3473 if (PointeeType.isNull())
3474 return QualType();
3475
3476 QualType Result = TL.getType();
3477 if (getDerived().AlwaysRebuild() ||
3478 PointeeType != TL.getPointeeLoc().getType()) {
3479 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003480 TL.getSigilLoc());
3481 if (Result.isNull())
3482 return QualType();
3483 }
3484
Douglas Gregor39968ad2010-04-22 16:50:51 +00003485 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003486 NewT.setSigilLoc(TL.getSigilLoc());
3487 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003488}
3489
John McCall85737a72009-10-30 00:06:24 +00003490/// Transforms a reference type. Note that somewhat paradoxically we
3491/// don't care whether the type itself is an l-value type or an r-value
3492/// type; we only care if the type was *written* as an l-value type
3493/// or an r-value type.
3494template<typename Derived>
3495QualType
3496TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003497 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003498 const ReferenceType *T = TL.getTypePtr();
3499
3500 // Note that this works with the pointee-as-written.
3501 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3502 if (PointeeType.isNull())
3503 return QualType();
3504
3505 QualType Result = TL.getType();
3506 if (getDerived().AlwaysRebuild() ||
3507 PointeeType != T->getPointeeTypeAsWritten()) {
3508 Result = getDerived().RebuildReferenceType(PointeeType,
3509 T->isSpelledAsLValue(),
3510 TL.getSigilLoc());
3511 if (Result.isNull())
3512 return QualType();
3513 }
3514
John McCallf85e1932011-06-15 23:02:42 +00003515 // Objective-C ARC can add lifetime qualifiers to the type that we're
3516 // referring to.
3517 TLB.TypeWasModifiedSafely(
3518 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3519
John McCall85737a72009-10-30 00:06:24 +00003520 // r-value references can be rebuilt as l-value references.
3521 ReferenceTypeLoc NewTL;
3522 if (isa<LValueReferenceType>(Result))
3523 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3524 else
3525 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3526 NewTL.setSigilLoc(TL.getSigilLoc());
3527
3528 return Result;
3529}
3530
Mike Stump1eb44332009-09-09 15:08:12 +00003531template<typename Derived>
3532QualType
John McCalla2becad2009-10-21 00:40:46 +00003533TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003534 LValueReferenceTypeLoc TL) {
3535 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003536}
3537
Mike Stump1eb44332009-09-09 15:08:12 +00003538template<typename Derived>
3539QualType
John McCalla2becad2009-10-21 00:40:46 +00003540TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003541 RValueReferenceTypeLoc TL) {
3542 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003543}
Mike Stump1eb44332009-09-09 15:08:12 +00003544
Douglas Gregor577f75a2009-08-04 16:50:30 +00003545template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003546QualType
John McCalla2becad2009-10-21 00:40:46 +00003547TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003548 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003549 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003550 if (PointeeType.isNull())
3551 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003552
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003553 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3554 TypeSourceInfo* NewClsTInfo = 0;
3555 if (OldClsTInfo) {
3556 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3557 if (!NewClsTInfo)
3558 return QualType();
3559 }
3560
3561 const MemberPointerType *T = TL.getTypePtr();
3562 QualType OldClsType = QualType(T->getClass(), 0);
3563 QualType NewClsType;
3564 if (NewClsTInfo)
3565 NewClsType = NewClsTInfo->getType();
3566 else {
3567 NewClsType = getDerived().TransformType(OldClsType);
3568 if (NewClsType.isNull())
3569 return QualType();
3570 }
Mike Stump1eb44332009-09-09 15:08:12 +00003571
John McCalla2becad2009-10-21 00:40:46 +00003572 QualType Result = TL.getType();
3573 if (getDerived().AlwaysRebuild() ||
3574 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003575 NewClsType != OldClsType) {
3576 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003577 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003578 if (Result.isNull())
3579 return QualType();
3580 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003581
John McCalla2becad2009-10-21 00:40:46 +00003582 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3583 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003584 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003585
3586 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003587}
3588
Mike Stump1eb44332009-09-09 15:08:12 +00003589template<typename Derived>
3590QualType
John McCalla2becad2009-10-21 00:40:46 +00003591TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003592 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003593 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003594 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003595 if (ElementType.isNull())
3596 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003597
John McCalla2becad2009-10-21 00:40:46 +00003598 QualType Result = TL.getType();
3599 if (getDerived().AlwaysRebuild() ||
3600 ElementType != T->getElementType()) {
3601 Result = getDerived().RebuildConstantArrayType(ElementType,
3602 T->getSizeModifier(),
3603 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003604 T->getIndexTypeCVRQualifiers(),
3605 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003606 if (Result.isNull())
3607 return QualType();
3608 }
Eli Friedman457a3772012-01-25 22:19:07 +00003609
3610 // We might have either a ConstantArrayType or a VariableArrayType now:
3611 // a ConstantArrayType is allowed to have an element type which is a
3612 // VariableArrayType if the type is dependent. Fortunately, all array
3613 // types have the same location layout.
3614 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCalla2becad2009-10-21 00:40:46 +00003615 NewTL.setLBracketLoc(TL.getLBracketLoc());
3616 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003617
John McCalla2becad2009-10-21 00:40:46 +00003618 Expr *Size = TL.getSizeExpr();
3619 if (Size) {
Richard Smithf6702a32011-12-20 02:08:33 +00003620 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3621 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003622 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3623 }
3624 NewTL.setSizeExpr(Size);
3625
3626 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003627}
Mike Stump1eb44332009-09-09 15:08:12 +00003628
Douglas Gregor577f75a2009-08-04 16:50:30 +00003629template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003630QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003631 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003632 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003633 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003634 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003635 if (ElementType.isNull())
3636 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003637
John McCalla2becad2009-10-21 00:40:46 +00003638 QualType Result = TL.getType();
3639 if (getDerived().AlwaysRebuild() ||
3640 ElementType != T->getElementType()) {
3641 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003642 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003643 T->getIndexTypeCVRQualifiers(),
3644 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003645 if (Result.isNull())
3646 return QualType();
3647 }
Sean Huntc3021132010-05-05 15:23:54 +00003648
John McCalla2becad2009-10-21 00:40:46 +00003649 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3650 NewTL.setLBracketLoc(TL.getLBracketLoc());
3651 NewTL.setRBracketLoc(TL.getRBracketLoc());
3652 NewTL.setSizeExpr(0);
3653
3654 return Result;
3655}
3656
3657template<typename Derived>
3658QualType
3659TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003660 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003661 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003662 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3663 if (ElementType.isNull())
3664 return QualType();
3665
John McCall60d7b3a2010-08-24 06:29:42 +00003666 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003667 = getDerived().TransformExpr(T->getSizeExpr());
3668 if (SizeResult.isInvalid())
3669 return QualType();
3670
John McCall9ae2f072010-08-23 23:25:46 +00003671 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003672
3673 QualType Result = TL.getType();
3674 if (getDerived().AlwaysRebuild() ||
3675 ElementType != T->getElementType() ||
3676 Size != T->getSizeExpr()) {
3677 Result = getDerived().RebuildVariableArrayType(ElementType,
3678 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003679 Size,
John McCalla2becad2009-10-21 00:40:46 +00003680 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003681 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003682 if (Result.isNull())
3683 return QualType();
3684 }
Sean Huntc3021132010-05-05 15:23:54 +00003685
John McCalla2becad2009-10-21 00:40:46 +00003686 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3687 NewTL.setLBracketLoc(TL.getLBracketLoc());
3688 NewTL.setRBracketLoc(TL.getRBracketLoc());
3689 NewTL.setSizeExpr(Size);
3690
3691 return Result;
3692}
3693
3694template<typename Derived>
3695QualType
3696TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003697 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003698 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003699 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3700 if (ElementType.isNull())
3701 return QualType();
3702
Richard Smithf6702a32011-12-20 02:08:33 +00003703 // Array bounds are constant expressions.
3704 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3705 Sema::ConstantEvaluated);
John McCalla2becad2009-10-21 00:40:46 +00003706
John McCall3b657512011-01-19 10:06:00 +00003707 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3708 Expr *origSize = TL.getSizeExpr();
3709 if (!origSize) origSize = T->getSizeExpr();
3710
3711 ExprResult sizeResult
3712 = getDerived().TransformExpr(origSize);
3713 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003714 return QualType();
3715
John McCall3b657512011-01-19 10:06:00 +00003716 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003717
3718 QualType Result = TL.getType();
3719 if (getDerived().AlwaysRebuild() ||
3720 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003721 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003722 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3723 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003724 size,
John McCalla2becad2009-10-21 00:40:46 +00003725 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003726 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003727 if (Result.isNull())
3728 return QualType();
3729 }
John McCalla2becad2009-10-21 00:40:46 +00003730
3731 // We might have any sort of array type now, but fortunately they
3732 // all have the same location layout.
3733 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3734 NewTL.setLBracketLoc(TL.getLBracketLoc());
3735 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003736 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003737
3738 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003739}
Mike Stump1eb44332009-09-09 15:08:12 +00003740
3741template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003742QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003743 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003744 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003745 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003746
3747 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003748 QualType ElementType = getDerived().TransformType(T->getElementType());
3749 if (ElementType.isNull())
3750 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003751
Richard Smithf6702a32011-12-20 02:08:33 +00003752 // Vector sizes are constant expressions.
3753 EnterExpressionEvaluationContext Unevaluated(SemaRef,
3754 Sema::ConstantEvaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003755
John McCall60d7b3a2010-08-24 06:29:42 +00003756 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003757 if (Size.isInvalid())
3758 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003759
John McCalla2becad2009-10-21 00:40:46 +00003760 QualType Result = TL.getType();
3761 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003762 ElementType != T->getElementType() ||
3763 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003764 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003765 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003766 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003767 if (Result.isNull())
3768 return QualType();
3769 }
John McCalla2becad2009-10-21 00:40:46 +00003770
3771 // Result might be dependent or not.
3772 if (isa<DependentSizedExtVectorType>(Result)) {
3773 DependentSizedExtVectorTypeLoc NewTL
3774 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3775 NewTL.setNameLoc(TL.getNameLoc());
3776 } else {
3777 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3778 NewTL.setNameLoc(TL.getNameLoc());
3779 }
3780
3781 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003782}
Mike Stump1eb44332009-09-09 15:08:12 +00003783
3784template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003785QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003786 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003787 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003788 QualType ElementType = getDerived().TransformType(T->getElementType());
3789 if (ElementType.isNull())
3790 return QualType();
3791
John McCalla2becad2009-10-21 00:40:46 +00003792 QualType Result = TL.getType();
3793 if (getDerived().AlwaysRebuild() ||
3794 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003795 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003796 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003797 if (Result.isNull())
3798 return QualType();
3799 }
Sean Huntc3021132010-05-05 15:23:54 +00003800
John McCalla2becad2009-10-21 00:40:46 +00003801 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3802 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003803
John McCalla2becad2009-10-21 00:40:46 +00003804 return Result;
3805}
3806
3807template<typename Derived>
3808QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003809 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003810 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003811 QualType ElementType = getDerived().TransformType(T->getElementType());
3812 if (ElementType.isNull())
3813 return QualType();
3814
3815 QualType Result = TL.getType();
3816 if (getDerived().AlwaysRebuild() ||
3817 ElementType != T->getElementType()) {
3818 Result = getDerived().RebuildExtVectorType(ElementType,
3819 T->getNumElements(),
3820 /*FIXME*/ SourceLocation());
3821 if (Result.isNull())
3822 return QualType();
3823 }
Sean Huntc3021132010-05-05 15:23:54 +00003824
John McCalla2becad2009-10-21 00:40:46 +00003825 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3826 NewTL.setNameLoc(TL.getNameLoc());
3827
3828 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003829}
Mike Stump1eb44332009-09-09 15:08:12 +00003830
3831template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003832ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003833TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003834 int indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003835 llvm::Optional<unsigned> NumExpansions,
3836 bool ExpectParameterPack) {
John McCall21ef0fa2010-03-11 09:03:00 +00003837 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003838 TypeSourceInfo *NewDI = 0;
3839
3840 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3841 // If we're substituting into a pack expansion type and we know the
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003842 // length we want to expand to, just substitute for the pattern.
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003843 TypeLoc OldTL = OldDI->getTypeLoc();
3844 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3845
3846 TypeLocBuilder TLB;
3847 TypeLoc NewTL = OldDI->getTypeLoc();
3848 TLB.reserve(NewTL.getFullDataSize());
3849
3850 QualType Result = getDerived().TransformType(TLB,
3851 OldExpansionTL.getPatternLoc());
3852 if (Result.isNull())
3853 return 0;
3854
3855 Result = RebuildPackExpansionType(Result,
3856 OldExpansionTL.getPatternLoc().getSourceRange(),
3857 OldExpansionTL.getEllipsisLoc(),
3858 NumExpansions);
3859 if (Result.isNull())
3860 return 0;
3861
3862 PackExpansionTypeLoc NewExpansionTL
3863 = TLB.push<PackExpansionTypeLoc>(Result);
3864 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3865 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3866 } else
3867 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003868 if (!NewDI)
3869 return 0;
3870
John McCallfb44de92011-05-01 22:35:37 +00003871 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003872 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003873
3874 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3875 OldParm->getDeclContext(),
3876 OldParm->getInnerLocStart(),
3877 OldParm->getLocation(),
3878 OldParm->getIdentifier(),
3879 NewDI->getType(),
3880 NewDI,
3881 OldParm->getStorageClass(),
3882 OldParm->getStorageClassAsWritten(),
3883 /* DefArg */ NULL);
3884 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3885 OldParm->getFunctionScopeIndex() + indexAdjustment);
3886 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003887}
3888
3889template<typename Derived>
3890bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003891 TransformFunctionTypeParams(SourceLocation Loc,
3892 ParmVarDecl **Params, unsigned NumParams,
3893 const QualType *ParamTypes,
Chris Lattner686775d2011-07-20 06:58:45 +00003894 SmallVectorImpl<QualType> &OutParamTypes,
3895 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003896 int indexAdjustment = 0;
3897
Douglas Gregora009b592011-01-07 00:20:55 +00003898 for (unsigned i = 0; i != NumParams; ++i) {
3899 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003900 assert(OldParm->getFunctionScopeIndex() == i);
3901
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003902 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003903 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003904 if (OldParm->isParameterPack()) {
3905 // We have a function parameter pack that may need to be expanded.
Chris Lattner686775d2011-07-20 06:58:45 +00003906 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003907
Douglas Gregor603cfb42011-01-05 23:12:31 +00003908 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003909 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3910 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3911 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3912 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003913 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3914
Douglas Gregor603cfb42011-01-05 23:12:31 +00003915 // Determine whether we should expand the parameter packs.
3916 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003917 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003918 llvm::Optional<unsigned> OrigNumExpansions
3919 = ExpansionTL.getTypePtr()->getNumExpansions();
3920 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003921 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3922 Pattern.getSourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00003923 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00003924 ShouldExpand,
3925 RetainExpansion,
3926 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003927 return true;
3928 }
3929
3930 if (ShouldExpand) {
3931 // Expand the function parameter pack into multiple, separate
3932 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003933 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003934 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003935 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3936 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003937 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003938 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003939 OrigNumExpansions,
3940 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003941 if (!NewParm)
3942 return true;
3943
Douglas Gregora009b592011-01-07 00:20:55 +00003944 OutParamTypes.push_back(NewParm->getType());
3945 if (PVars)
3946 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003947 }
Douglas Gregord3731192011-01-10 07:32:04 +00003948
3949 // If we're supposed to retain a pack expansion, do so by temporarily
3950 // forgetting the partially-substituted parameter pack.
3951 if (RetainExpansion) {
3952 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3953 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003954 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003955 indexAdjustment++,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003956 OrigNumExpansions,
3957 /*ExpectParameterPack=*/false);
Douglas Gregord3731192011-01-10 07:32:04 +00003958 if (!NewParm)
3959 return true;
3960
3961 OutParamTypes.push_back(NewParm->getType());
3962 if (PVars)
3963 PVars->push_back(NewParm);
3964 }
3965
John McCallfb44de92011-05-01 22:35:37 +00003966 // The next parameter should have the same adjustment as the
3967 // last thing we pushed, but we post-incremented indexAdjustment
3968 // on every push. Also, if we push nothing, the adjustment should
3969 // go down by one.
3970 indexAdjustment--;
3971
Douglas Gregor603cfb42011-01-05 23:12:31 +00003972 // We're done with the pack expansion.
3973 continue;
3974 }
3975
3976 // We'll substitute the parameter now without expanding the pack
3977 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003978 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3979 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003980 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003981 NumExpansions,
3982 /*ExpectParameterPack=*/true);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003983 } else {
3984 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003985 indexAdjustment,
Douglas Gregord1bb4ae2012-01-25 16:15:54 +00003986 llvm::Optional<unsigned>(),
3987 /*ExpectParameterPack=*/false);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003988 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003989
John McCall21ef0fa2010-03-11 09:03:00 +00003990 if (!NewParm)
3991 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003992
Douglas Gregora009b592011-01-07 00:20:55 +00003993 OutParamTypes.push_back(NewParm->getType());
3994 if (PVars)
3995 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003996 continue;
3997 }
John McCall21ef0fa2010-03-11 09:03:00 +00003998
3999 // Deal with the possibility that we don't have a parameter
4000 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00004001 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00004002 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00004003 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004004 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004005 if (const PackExpansionType *Expansion
4006 = dyn_cast<PackExpansionType>(OldType)) {
4007 // We have a function parameter pack that may need to be expanded.
4008 QualType Pattern = Expansion->getPattern();
Chris Lattner686775d2011-07-20 06:58:45 +00004009 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004010 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
4011
4012 // Determine whether we should expand the parameter packs.
4013 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00004014 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00004015 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikiea71f9d02011-09-22 02:34:54 +00004016 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00004017 ShouldExpand,
4018 RetainExpansion,
4019 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00004020 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00004021 }
4022
4023 if (ShouldExpand) {
4024 // Expand the function parameter pack into multiple, separate
4025 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00004026 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00004027 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4028 QualType NewType = getDerived().TransformType(Pattern);
4029 if (NewType.isNull())
4030 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00004031
Douglas Gregora009b592011-01-07 00:20:55 +00004032 OutParamTypes.push_back(NewType);
4033 if (PVars)
4034 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004035 }
4036
4037 // We're done with the pack expansion.
4038 continue;
4039 }
4040
Douglas Gregor3cae5c92011-01-10 20:53:55 +00004041 // If we're supposed to retain a pack expansion, do so by temporarily
4042 // forgetting the partially-substituted parameter pack.
4043 if (RetainExpansion) {
4044 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4045 QualType NewType = getDerived().TransformType(Pattern);
4046 if (NewType.isNull())
4047 return true;
4048
4049 OutParamTypes.push_back(NewType);
4050 if (PVars)
4051 PVars->push_back(0);
4052 }
Douglas Gregord3731192011-01-10 07:32:04 +00004053
Douglas Gregor603cfb42011-01-05 23:12:31 +00004054 // We'll substitute the parameter now without expanding the pack
4055 // expansion.
4056 OldType = Expansion->getPattern();
4057 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00004058 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4059 NewType = getDerived().TransformType(OldType);
4060 } else {
4061 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004062 }
4063
Douglas Gregor603cfb42011-01-05 23:12:31 +00004064 if (NewType.isNull())
4065 return true;
4066
4067 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00004068 NewType = getSema().Context.getPackExpansionType(NewType,
4069 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004070
Douglas Gregora009b592011-01-07 00:20:55 +00004071 OutParamTypes.push_back(NewType);
4072 if (PVars)
4073 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00004074 }
4075
John McCallfb44de92011-05-01 22:35:37 +00004076#ifndef NDEBUG
4077 if (PVars) {
4078 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4079 if (ParmVarDecl *parm = (*PVars)[i])
4080 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00004081 }
John McCallfb44de92011-05-01 22:35:37 +00004082#endif
4083
4084 return false;
4085}
John McCall21ef0fa2010-03-11 09:03:00 +00004086
4087template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004088QualType
John McCalla2becad2009-10-21 00:40:46 +00004089TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004090 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004091 // Transform the parameters and return type.
4092 //
4093 // We instantiate in source order, with the return type first followed by
4094 // the parameters, because users tend to expect this (even if they shouldn't
4095 // rely on it!).
4096 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004097 // When the function has a trailing return type, we instantiate the
4098 // parameters before the return type, since the return type can then refer
4099 // to the parameters themselves (via decltype, sizeof, etc.).
4100 //
Chris Lattner686775d2011-07-20 06:58:45 +00004101 SmallVector<QualType, 4> ParamTypes;
4102 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004103 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004104
Douglas Gregordab60ad2010-10-01 18:44:50 +00004105 QualType ResultType;
4106
4107 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004108 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4109 TL.getParmArray(),
4110 TL.getNumArgs(),
4111 TL.getTypePtr()->arg_type_begin(),
4112 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004113 return QualType();
4114
4115 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4116 if (ResultType.isNull())
4117 return QualType();
4118 }
4119 else {
4120 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4121 if (ResultType.isNull())
4122 return QualType();
4123
Douglas Gregora009b592011-01-07 00:20:55 +00004124 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4125 TL.getParmArray(),
4126 TL.getNumArgs(),
4127 TL.getTypePtr()->arg_type_begin(),
4128 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004129 return QualType();
4130 }
4131
John McCalla2becad2009-10-21 00:40:46 +00004132 QualType Result = TL.getType();
4133 if (getDerived().AlwaysRebuild() ||
4134 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004135 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004136 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4137 Result = getDerived().RebuildFunctionProtoType(ResultType,
4138 ParamTypes.data(),
4139 ParamTypes.size(),
4140 T->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00004141 T->hasTrailingReturn(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004142 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004143 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004144 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004145 if (Result.isNull())
4146 return QualType();
4147 }
Mike Stump1eb44332009-09-09 15:08:12 +00004148
John McCalla2becad2009-10-21 00:40:46 +00004149 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004150 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4151 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004152 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004153 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4154 NewTL.setArg(i, ParamDecls[i]);
4155
4156 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004157}
Mike Stump1eb44332009-09-09 15:08:12 +00004158
Douglas Gregor577f75a2009-08-04 16:50:30 +00004159template<typename Derived>
4160QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004161 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004162 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004163 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004164 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4165 if (ResultType.isNull())
4166 return QualType();
4167
4168 QualType Result = TL.getType();
4169 if (getDerived().AlwaysRebuild() ||
4170 ResultType != T->getResultType())
4171 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4172
4173 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004174 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4175 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004176 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004177
4178 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004179}
Mike Stump1eb44332009-09-09 15:08:12 +00004180
John McCalled976492009-12-04 22:46:56 +00004181template<typename Derived> QualType
4182TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004183 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004184 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004185 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004186 if (!D)
4187 return QualType();
4188
4189 QualType Result = TL.getType();
4190 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4191 Result = getDerived().RebuildUnresolvedUsingType(D);
4192 if (Result.isNull())
4193 return QualType();
4194 }
4195
4196 // We might get an arbitrary type spec type back. We should at
4197 // least always get a type spec type, though.
4198 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4199 NewTL.setNameLoc(TL.getNameLoc());
4200
4201 return Result;
4202}
4203
Douglas Gregor577f75a2009-08-04 16:50:30 +00004204template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004205QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004206 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004207 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004208 TypedefNameDecl *Typedef
4209 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4210 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004211 if (!Typedef)
4212 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004213
John McCalla2becad2009-10-21 00:40:46 +00004214 QualType Result = TL.getType();
4215 if (getDerived().AlwaysRebuild() ||
4216 Typedef != T->getDecl()) {
4217 Result = getDerived().RebuildTypedefType(Typedef);
4218 if (Result.isNull())
4219 return QualType();
4220 }
Mike Stump1eb44332009-09-09 15:08:12 +00004221
John McCalla2becad2009-10-21 00:40:46 +00004222 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4223 NewTL.setNameLoc(TL.getNameLoc());
4224
4225 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004226}
Mike Stump1eb44332009-09-09 15:08:12 +00004227
Douglas Gregor577f75a2009-08-04 16:50:30 +00004228template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004229QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004230 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004231 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004232 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004233
John McCall60d7b3a2010-08-24 06:29:42 +00004234 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004235 if (E.isInvalid())
4236 return QualType();
4237
John McCalla2becad2009-10-21 00:40:46 +00004238 QualType Result = TL.getType();
4239 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004240 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004241 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004242 if (Result.isNull())
4243 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004244 }
John McCalla2becad2009-10-21 00:40:46 +00004245 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004246
John McCalla2becad2009-10-21 00:40:46 +00004247 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004248 NewTL.setTypeofLoc(TL.getTypeofLoc());
4249 NewTL.setLParenLoc(TL.getLParenLoc());
4250 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004251
4252 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004253}
Mike Stump1eb44332009-09-09 15:08:12 +00004254
4255template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004256QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004257 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004258 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4259 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4260 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004261 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004262
John McCalla2becad2009-10-21 00:40:46 +00004263 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004264 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4265 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004266 if (Result.isNull())
4267 return QualType();
4268 }
Mike Stump1eb44332009-09-09 15:08:12 +00004269
John McCalla2becad2009-10-21 00:40:46 +00004270 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004271 NewTL.setTypeofLoc(TL.getTypeofLoc());
4272 NewTL.setLParenLoc(TL.getLParenLoc());
4273 NewTL.setRParenLoc(TL.getRParenLoc());
4274 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004275
4276 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004277}
Mike Stump1eb44332009-09-09 15:08:12 +00004278
4279template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004280QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004281 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004282 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004283
Douglas Gregor670444e2009-08-04 22:27:00 +00004284 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004285 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004286
John McCall60d7b3a2010-08-24 06:29:42 +00004287 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004288 if (E.isInvalid())
4289 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004290
John McCalla2becad2009-10-21 00:40:46 +00004291 QualType Result = TL.getType();
4292 if (getDerived().AlwaysRebuild() ||
4293 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004294 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004295 if (Result.isNull())
4296 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004297 }
John McCalla2becad2009-10-21 00:40:46 +00004298 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004299
John McCalla2becad2009-10-21 00:40:46 +00004300 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4301 NewTL.setNameLoc(TL.getNameLoc());
4302
4303 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004304}
4305
4306template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004307QualType TreeTransform<Derived>::TransformUnaryTransformType(
4308 TypeLocBuilder &TLB,
4309 UnaryTransformTypeLoc TL) {
4310 QualType Result = TL.getType();
4311 if (Result->isDependentType()) {
4312 const UnaryTransformType *T = TL.getTypePtr();
4313 QualType NewBase =
4314 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4315 Result = getDerived().RebuildUnaryTransformType(NewBase,
4316 T->getUTTKind(),
4317 TL.getKWLoc());
4318 if (Result.isNull())
4319 return QualType();
4320 }
4321
4322 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4323 NewTL.setKWLoc(TL.getKWLoc());
4324 NewTL.setParensRange(TL.getParensRange());
4325 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4326 return Result;
4327}
4328
4329template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004330QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4331 AutoTypeLoc TL) {
4332 const AutoType *T = TL.getTypePtr();
4333 QualType OldDeduced = T->getDeducedType();
4334 QualType NewDeduced;
4335 if (!OldDeduced.isNull()) {
4336 NewDeduced = getDerived().TransformType(OldDeduced);
4337 if (NewDeduced.isNull())
4338 return QualType();
4339 }
4340
4341 QualType Result = TL.getType();
4342 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4343 Result = getDerived().RebuildAutoType(NewDeduced);
4344 if (Result.isNull())
4345 return QualType();
4346 }
4347
4348 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4349 NewTL.setNameLoc(TL.getNameLoc());
4350
4351 return Result;
4352}
4353
4354template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004355QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004356 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004357 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004358 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004359 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4360 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004361 if (!Record)
4362 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004363
John McCalla2becad2009-10-21 00:40:46 +00004364 QualType Result = TL.getType();
4365 if (getDerived().AlwaysRebuild() ||
4366 Record != T->getDecl()) {
4367 Result = getDerived().RebuildRecordType(Record);
4368 if (Result.isNull())
4369 return QualType();
4370 }
Mike Stump1eb44332009-09-09 15:08:12 +00004371
John McCalla2becad2009-10-21 00:40:46 +00004372 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4373 NewTL.setNameLoc(TL.getNameLoc());
4374
4375 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004376}
Mike Stump1eb44332009-09-09 15:08:12 +00004377
4378template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004379QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004380 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004381 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004382 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004383 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4384 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004385 if (!Enum)
4386 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004387
John McCalla2becad2009-10-21 00:40:46 +00004388 QualType Result = TL.getType();
4389 if (getDerived().AlwaysRebuild() ||
4390 Enum != T->getDecl()) {
4391 Result = getDerived().RebuildEnumType(Enum);
4392 if (Result.isNull())
4393 return QualType();
4394 }
Mike Stump1eb44332009-09-09 15:08:12 +00004395
John McCalla2becad2009-10-21 00:40:46 +00004396 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4397 NewTL.setNameLoc(TL.getNameLoc());
4398
4399 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004400}
John McCall7da24312009-09-05 00:15:47 +00004401
John McCall3cb0ebd2010-03-10 03:28:59 +00004402template<typename Derived>
4403QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4404 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004405 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004406 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4407 TL.getTypePtr()->getDecl());
4408 if (!D) return QualType();
4409
4410 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4411 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4412 return T;
4413}
4414
Douglas Gregor577f75a2009-08-04 16:50:30 +00004415template<typename Derived>
4416QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004417 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004418 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004419 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004420}
4421
Mike Stump1eb44332009-09-09 15:08:12 +00004422template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004423QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004424 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004425 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004426 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4427
4428 // Substitute into the replacement type, which itself might involve something
4429 // that needs to be transformed. This only tends to occur with default
4430 // template arguments of template template parameters.
4431 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4432 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4433 if (Replacement.isNull())
4434 return QualType();
4435
4436 // Always canonicalize the replacement type.
4437 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4438 QualType Result
4439 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4440 Replacement);
4441
4442 // Propagate type-source information.
4443 SubstTemplateTypeParmTypeLoc NewTL
4444 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4445 NewTL.setNameLoc(TL.getNameLoc());
4446 return Result;
4447
John McCall49a832b2009-10-18 09:09:24 +00004448}
4449
4450template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004451QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4452 TypeLocBuilder &TLB,
4453 SubstTemplateTypeParmPackTypeLoc TL) {
4454 return TransformTypeSpecType(TLB, TL);
4455}
4456
4457template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004458QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004459 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004460 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004461 const TemplateSpecializationType *T = TL.getTypePtr();
4462
Douglas Gregor1d752d72011-03-02 18:46:51 +00004463 // The nested-name-specifier never matters in a TemplateSpecializationType,
4464 // because we can't have a dependent nested-name-specifier anyway.
4465 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004466 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004467 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4468 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004469 if (Template.isNull())
4470 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004471
John McCall43fed0d2010-11-12 08:19:04 +00004472 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4473}
4474
Eli Friedmanb001de72011-10-06 23:00:33 +00004475template<typename Derived>
4476QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
4477 AtomicTypeLoc TL) {
4478 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
4479 if (ValueType.isNull())
4480 return QualType();
4481
4482 QualType Result = TL.getType();
4483 if (getDerived().AlwaysRebuild() ||
4484 ValueType != TL.getValueLoc().getType()) {
4485 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
4486 if (Result.isNull())
4487 return QualType();
4488 }
4489
4490 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
4491 NewTL.setKWLoc(TL.getKWLoc());
4492 NewTL.setLParenLoc(TL.getLParenLoc());
4493 NewTL.setRParenLoc(TL.getRParenLoc());
4494
4495 return Result;
4496}
4497
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004498namespace {
4499 /// \brief Simple iterator that traverses the template arguments in a
4500 /// container that provides a \c getArgLoc() member function.
4501 ///
4502 /// This iterator is intended to be used with the iterator form of
4503 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4504 template<typename ArgLocContainer>
4505 class TemplateArgumentLocContainerIterator {
4506 ArgLocContainer *Container;
4507 unsigned Index;
4508
4509 public:
4510 typedef TemplateArgumentLoc value_type;
4511 typedef TemplateArgumentLoc reference;
4512 typedef int difference_type;
4513 typedef std::input_iterator_tag iterator_category;
4514
4515 class pointer {
4516 TemplateArgumentLoc Arg;
4517
4518 public:
4519 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4520
4521 const TemplateArgumentLoc *operator->() const {
4522 return &Arg;
4523 }
4524 };
4525
4526
4527 TemplateArgumentLocContainerIterator() {}
4528
4529 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4530 unsigned Index)
4531 : Container(&Container), Index(Index) { }
4532
4533 TemplateArgumentLocContainerIterator &operator++() {
4534 ++Index;
4535 return *this;
4536 }
4537
4538 TemplateArgumentLocContainerIterator operator++(int) {
4539 TemplateArgumentLocContainerIterator Old(*this);
4540 ++(*this);
4541 return Old;
4542 }
4543
4544 TemplateArgumentLoc operator*() const {
4545 return Container->getArgLoc(Index);
4546 }
4547
4548 pointer operator->() const {
4549 return pointer(Container->getArgLoc(Index));
4550 }
4551
4552 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004553 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004554 return X.Container == Y.Container && X.Index == Y.Index;
4555 }
4556
4557 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004558 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004559 return !(X == Y);
4560 }
4561 };
4562}
4563
4564
John McCall43fed0d2010-11-12 08:19:04 +00004565template <typename Derived>
4566QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4567 TypeLocBuilder &TLB,
4568 TemplateSpecializationTypeLoc TL,
4569 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004570 TemplateArgumentListInfo NewTemplateArgs;
4571 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4572 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004573 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4574 ArgIterator;
4575 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4576 ArgIterator(TL, TL.getNumArgs()),
4577 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004578 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004579
John McCall833ca992009-10-29 08:12:44 +00004580 // FIXME: maybe don't rebuild if all the template arguments are the same.
4581
4582 QualType Result =
4583 getDerived().RebuildTemplateSpecializationType(Template,
4584 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004585 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004586
4587 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004588 // Specializations of template template parameters are represented as
4589 // TemplateSpecializationTypes, and substitution of type alias templates
4590 // within a dependent context can transform them into
4591 // DependentTemplateSpecializationTypes.
4592 if (isa<DependentTemplateSpecializationType>(Result)) {
4593 DependentTemplateSpecializationTypeLoc NewTL
4594 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004595 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004596 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnara66581d42012-02-06 22:45:07 +00004597 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004598 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3e4c6c42011-05-05 21:57:07 +00004599 NewTL.setLAngleLoc(TL.getLAngleLoc());
4600 NewTL.setRAngleLoc(TL.getRAngleLoc());
4601 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4602 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4603 return Result;
4604 }
4605
John McCall833ca992009-10-29 08:12:44 +00004606 TemplateSpecializationTypeLoc NewTL
4607 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004608 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall833ca992009-10-29 08:12:44 +00004609 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4610 NewTL.setLAngleLoc(TL.getLAngleLoc());
4611 NewTL.setRAngleLoc(TL.getRAngleLoc());
4612 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4613 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004614 }
Mike Stump1eb44332009-09-09 15:08:12 +00004615
John McCall833ca992009-10-29 08:12:44 +00004616 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004617}
Mike Stump1eb44332009-09-09 15:08:12 +00004618
Douglas Gregora88f09f2011-02-28 17:23:35 +00004619template <typename Derived>
4620QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4621 TypeLocBuilder &TLB,
4622 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004623 TemplateName Template,
4624 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004625 TemplateArgumentListInfo NewTemplateArgs;
4626 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4627 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4628 typedef TemplateArgumentLocContainerIterator<
4629 DependentTemplateSpecializationTypeLoc> ArgIterator;
4630 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4631 ArgIterator(TL, TL.getNumArgs()),
4632 NewTemplateArgs))
4633 return QualType();
4634
4635 // FIXME: maybe don't rebuild if all the template arguments are the same.
4636
4637 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4638 QualType Result
4639 = getSema().Context.getDependentTemplateSpecializationType(
4640 TL.getTypePtr()->getKeyword(),
4641 DTN->getQualifier(),
4642 DTN->getIdentifier(),
4643 NewTemplateArgs);
4644
4645 DependentTemplateSpecializationTypeLoc NewTL
4646 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004647 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004648 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnara66581d42012-02-06 22:45:07 +00004649 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004650 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004651 NewTL.setLAngleLoc(TL.getLAngleLoc());
4652 NewTL.setRAngleLoc(TL.getRAngleLoc());
4653 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4654 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4655 return Result;
4656 }
4657
4658 QualType Result
4659 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004660 TL.getTemplateNameLoc(),
Douglas Gregora88f09f2011-02-28 17:23:35 +00004661 NewTemplateArgs);
4662
4663 if (!Result.isNull()) {
4664 /// FIXME: Wrap this in an elaborated-type-specifier?
4665 TemplateSpecializationTypeLoc NewTL
4666 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004667 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004668 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora88f09f2011-02-28 17:23:35 +00004669 NewTL.setLAngleLoc(TL.getLAngleLoc());
4670 NewTL.setRAngleLoc(TL.getRAngleLoc());
4671 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4672 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4673 }
4674
4675 return Result;
4676}
4677
Mike Stump1eb44332009-09-09 15:08:12 +00004678template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004679QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004680TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004681 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004682 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004683
Douglas Gregor9e876872011-03-01 18:12:44 +00004684 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004685 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004686 if (TL.getQualifierLoc()) {
4687 QualifierLoc
4688 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4689 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004690 return QualType();
4691 }
Mike Stump1eb44332009-09-09 15:08:12 +00004692
John McCall43fed0d2010-11-12 08:19:04 +00004693 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4694 if (NamedT.isNull())
4695 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004696
Richard Smith3e4c6c42011-05-05 21:57:07 +00004697 // C++0x [dcl.type.elab]p2:
4698 // If the identifier resolves to a typedef-name or the simple-template-id
4699 // resolves to an alias template specialization, the
4700 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004701 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4702 if (const TemplateSpecializationType *TST =
4703 NamedT->getAs<TemplateSpecializationType>()) {
4704 TemplateName Template = TST->getTemplateName();
4705 if (TypeAliasTemplateDecl *TAT =
4706 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4707 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4708 diag::err_tag_reference_non_tag) << 4;
4709 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4710 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004711 }
4712 }
4713
John McCalla2becad2009-10-21 00:40:46 +00004714 QualType Result = TL.getType();
4715 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004716 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004717 NamedT != T->getNamedType()) {
Abramo Bagnara38a42912012-02-06 19:09:27 +00004718 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004719 T->getKeyword(),
4720 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004721 if (Result.isNull())
4722 return QualType();
4723 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004724
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004725 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004726 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004727 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004728 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004729}
Mike Stump1eb44332009-09-09 15:08:12 +00004730
4731template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004732QualType TreeTransform<Derived>::TransformAttributedType(
4733 TypeLocBuilder &TLB,
4734 AttributedTypeLoc TL) {
4735 const AttributedType *oldType = TL.getTypePtr();
4736 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4737 if (modifiedType.isNull())
4738 return QualType();
4739
4740 QualType result = TL.getType();
4741
4742 // FIXME: dependent operand expressions?
4743 if (getDerived().AlwaysRebuild() ||
4744 modifiedType != oldType->getModifiedType()) {
4745 // TODO: this is really lame; we should really be rebuilding the
4746 // equivalent type from first principles.
4747 QualType equivalentType
4748 = getDerived().TransformType(oldType->getEquivalentType());
4749 if (equivalentType.isNull())
4750 return QualType();
4751 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4752 modifiedType,
4753 equivalentType);
4754 }
4755
4756 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4757 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4758 if (TL.hasAttrOperand())
4759 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4760 if (TL.hasAttrExprOperand())
4761 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4762 else if (TL.hasAttrEnumOperand())
4763 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4764
4765 return result;
4766}
4767
4768template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004769QualType
4770TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4771 ParenTypeLoc TL) {
4772 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4773 if (Inner.isNull())
4774 return QualType();
4775
4776 QualType Result = TL.getType();
4777 if (getDerived().AlwaysRebuild() ||
4778 Inner != TL.getInnerLoc().getType()) {
4779 Result = getDerived().RebuildParenType(Inner);
4780 if (Result.isNull())
4781 return QualType();
4782 }
4783
4784 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4785 NewTL.setLParenLoc(TL.getLParenLoc());
4786 NewTL.setRParenLoc(TL.getRParenLoc());
4787 return Result;
4788}
4789
4790template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004791QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004792 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004793 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004794
Douglas Gregor2494dd02011-03-01 01:34:45 +00004795 NestedNameSpecifierLoc QualifierLoc
4796 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4797 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004798 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004799
John McCall33500952010-06-11 00:33:02 +00004800 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004801 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara38a42912012-02-06 19:09:27 +00004802 TL.getElaboratedKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004803 QualifierLoc,
4804 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004805 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004806 if (Result.isNull())
4807 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004808
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004809 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4810 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004811 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4812
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004813 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004814 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004815 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004816 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004817 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004818 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004819 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004820 NewTL.setNameLoc(TL.getNameLoc());
4821 }
John McCalla2becad2009-10-21 00:40:46 +00004822 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004823}
Mike Stump1eb44332009-09-09 15:08:12 +00004824
Douglas Gregor577f75a2009-08-04 16:50:30 +00004825template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004826QualType TreeTransform<Derived>::
4827 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004828 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004829 NestedNameSpecifierLoc QualifierLoc;
4830 if (TL.getQualifierLoc()) {
4831 QualifierLoc
4832 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4833 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004834 return QualType();
4835 }
4836
John McCall43fed0d2010-11-12 08:19:04 +00004837 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004838 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004839}
4840
4841template<typename Derived>
4842QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004843TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4844 DependentTemplateSpecializationTypeLoc TL,
4845 NestedNameSpecifierLoc QualifierLoc) {
4846 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4847
4848 TemplateArgumentListInfo NewTemplateArgs;
4849 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4850 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4851
4852 typedef TemplateArgumentLocContainerIterator<
4853 DependentTemplateSpecializationTypeLoc> ArgIterator;
4854 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4855 ArgIterator(TL, TL.getNumArgs()),
4856 NewTemplateArgs))
4857 return QualType();
4858
4859 QualType Result
4860 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4861 QualifierLoc,
4862 T->getIdentifier(),
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004863 TL.getTemplateNameLoc(),
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004864 NewTemplateArgs);
4865 if (Result.isNull())
4866 return QualType();
4867
4868 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4869 QualType NamedT = ElabT->getNamedType();
4870
4871 // Copy information relevant to the template specialization.
4872 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004873 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004874 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004875 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004876 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4877 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004878 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004879 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004880
4881 // Copy information relevant to the elaborated type.
4882 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara38a42912012-02-06 19:09:27 +00004883 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004884 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004885 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4886 DependentTemplateSpecializationTypeLoc SpecTL
4887 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004888 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004889 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004890 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004891 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004892 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4893 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004894 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004895 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004896 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004897 TemplateSpecializationTypeLoc SpecTL
4898 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara66581d42012-02-06 22:45:07 +00004899 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara55d23c92012-02-06 14:41:24 +00004900 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004901 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4902 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004903 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004904 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004905 }
4906 return Result;
4907}
4908
4909template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004910QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4911 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004912 QualType Pattern
4913 = getDerived().TransformType(TLB, TL.getPatternLoc());
4914 if (Pattern.isNull())
4915 return QualType();
4916
4917 QualType Result = TL.getType();
4918 if (getDerived().AlwaysRebuild() ||
4919 Pattern != TL.getPatternLoc().getType()) {
4920 Result = getDerived().RebuildPackExpansionType(Pattern,
4921 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004922 TL.getEllipsisLoc(),
4923 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004924 if (Result.isNull())
4925 return QualType();
4926 }
4927
4928 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4929 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4930 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004931}
4932
4933template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004934QualType
4935TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004936 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004937 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004938 TLB.pushFullCopy(TL);
4939 return TL.getType();
4940}
4941
4942template<typename Derived>
4943QualType
4944TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004945 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004946 // ObjCObjectType is never dependent.
4947 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004948 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004949}
Mike Stump1eb44332009-09-09 15:08:12 +00004950
4951template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004952QualType
4953TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004954 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004955 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004956 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004957 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004958}
4959
Douglas Gregor577f75a2009-08-04 16:50:30 +00004960//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004961// Statement transformation
4962//===----------------------------------------------------------------------===//
4963template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004964StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004965TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004966 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004967}
4968
4969template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004970StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004971TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4972 return getDerived().TransformCompoundStmt(S, false);
4973}
4974
4975template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004976StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004977TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004978 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004979 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004980 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004981 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004982 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4983 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004984 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004985 if (Result.isInvalid()) {
4986 // Immediately fail if this was a DeclStmt, since it's very
4987 // likely that this will cause problems for future statements.
4988 if (isa<DeclStmt>(*B))
4989 return StmtError();
4990
4991 // Otherwise, just keep processing substatements and fail later.
4992 SubStmtInvalid = true;
4993 continue;
4994 }
Mike Stump1eb44332009-09-09 15:08:12 +00004995
Douglas Gregor43959a92009-08-20 07:17:43 +00004996 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4997 Statements.push_back(Result.takeAs<Stmt>());
4998 }
Mike Stump1eb44332009-09-09 15:08:12 +00004999
John McCall7114cba2010-08-27 19:56:05 +00005000 if (SubStmtInvalid)
5001 return StmtError();
5002
Douglas Gregor43959a92009-08-20 07:17:43 +00005003 if (!getDerived().AlwaysRebuild() &&
5004 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005005 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005006
5007 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
5008 move_arg(Statements),
5009 S->getRBracLoc(),
5010 IsStmtExpr);
5011}
Mike Stump1eb44332009-09-09 15:08:12 +00005012
Douglas Gregor43959a92009-08-20 07:17:43 +00005013template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005014StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005015TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005016 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00005017 {
Eli Friedman6b3014b2012-01-18 02:54:10 +00005018 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5019 Sema::ConstantEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005020
Eli Friedman264c1f82009-11-19 03:14:00 +00005021 // Transform the left-hand case value.
5022 LHS = getDerived().TransformExpr(S->getLHS());
5023 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005024 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005025
Eli Friedman264c1f82009-11-19 03:14:00 +00005026 // Transform the right-hand case value (for the GNU case-range extension).
5027 RHS = getDerived().TransformExpr(S->getRHS());
5028 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005029 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00005030 }
Mike Stump1eb44332009-09-09 15:08:12 +00005031
Douglas Gregor43959a92009-08-20 07:17:43 +00005032 // Build the case statement.
5033 // Case statements are always rebuilt so that they will attached to their
5034 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005035 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005036 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005037 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005038 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005039 S->getColonLoc());
5040 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005041 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005042
Douglas Gregor43959a92009-08-20 07:17:43 +00005043 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00005044 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005045 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005046 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005047
Douglas Gregor43959a92009-08-20 07:17:43 +00005048 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00005049 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005050}
5051
5052template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005053StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005054TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005055 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00005056 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005057 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005058 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005059
Douglas Gregor43959a92009-08-20 07:17:43 +00005060 // Default statements are always rebuilt
5061 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005062 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005063}
Mike Stump1eb44332009-09-09 15:08:12 +00005064
Douglas Gregor43959a92009-08-20 07:17:43 +00005065template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005066StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005067TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005068 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00005069 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005070 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005071
Chris Lattner57ad3782011-02-17 20:34:02 +00005072 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5073 S->getDecl());
5074 if (!LD)
5075 return StmtError();
5076
5077
Douglas Gregor43959a92009-08-20 07:17:43 +00005078 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00005079 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005080 cast<LabelDecl>(LD), SourceLocation(),
5081 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005082}
Mike Stump1eb44332009-09-09 15:08:12 +00005083
Douglas Gregor43959a92009-08-20 07:17:43 +00005084template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005085StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005086TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005087 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005088 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005089 VarDecl *ConditionVar = 0;
5090 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005091 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005092 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005093 getDerived().TransformDefinition(
5094 S->getConditionVariable()->getLocation(),
5095 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005096 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005097 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005098 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00005099 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005100
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005101 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005102 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005103
5104 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005105 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005106 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5107 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005108 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005109 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005110
John McCall9ae2f072010-08-23 23:25:46 +00005111 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005112 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005113 }
Sean Huntc3021132010-05-05 15:23:54 +00005114
John McCall9ae2f072010-08-23 23:25:46 +00005115 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5116 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005117 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005118
Douglas Gregor43959a92009-08-20 07:17:43 +00005119 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005120 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005121 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005122 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005123
Douglas Gregor43959a92009-08-20 07:17:43 +00005124 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005125 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005126 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005127 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005128
Douglas Gregor43959a92009-08-20 07:17:43 +00005129 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005130 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005131 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005132 Then.get() == S->getThen() &&
5133 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005134 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005135
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005136 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005137 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005138 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005139}
5140
5141template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005142StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005143TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005144 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005145 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005146 VarDecl *ConditionVar = 0;
5147 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005148 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005149 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005150 getDerived().TransformDefinition(
5151 S->getConditionVariable()->getLocation(),
5152 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005153 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005154 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005155 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005156 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005157
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005158 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005159 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005160 }
Mike Stump1eb44332009-09-09 15:08:12 +00005161
Douglas Gregor43959a92009-08-20 07:17:43 +00005162 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005163 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005164 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005165 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005166 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005167 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005168
Douglas Gregor43959a92009-08-20 07:17:43 +00005169 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005170 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005171 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005172 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005173
Douglas Gregor43959a92009-08-20 07:17:43 +00005174 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005175 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5176 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005177}
Mike Stump1eb44332009-09-09 15:08:12 +00005178
Douglas Gregor43959a92009-08-20 07:17:43 +00005179template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005180StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005181TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005182 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005183 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005184 VarDecl *ConditionVar = 0;
5185 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005186 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005187 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005188 getDerived().TransformDefinition(
5189 S->getConditionVariable()->getLocation(),
5190 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005191 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005192 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005193 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005194 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005195
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005196 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005197 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005198
5199 if (S->getCond()) {
5200 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005201 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5202 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005203 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005204 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005205 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005206 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005207 }
Mike Stump1eb44332009-09-09 15:08:12 +00005208
John McCall9ae2f072010-08-23 23:25:46 +00005209 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5210 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005211 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005212
Douglas Gregor43959a92009-08-20 07:17:43 +00005213 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005214 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005215 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005216 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005217
Douglas Gregor43959a92009-08-20 07:17:43 +00005218 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005219 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005220 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005221 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005222 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005223
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005224 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005225 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005226}
Mike Stump1eb44332009-09-09 15:08:12 +00005227
Douglas Gregor43959a92009-08-20 07:17:43 +00005228template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005229StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005230TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005231 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005232 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005233 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005234 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005235
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005236 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005237 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005238 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005239 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005240
Douglas Gregor43959a92009-08-20 07:17:43 +00005241 if (!getDerived().AlwaysRebuild() &&
5242 Cond.get() == S->getCond() &&
5243 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005244 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005245
John McCall9ae2f072010-08-23 23:25:46 +00005246 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5247 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005248 S->getRParenLoc());
5249}
Mike Stump1eb44332009-09-09 15:08:12 +00005250
Douglas Gregor43959a92009-08-20 07:17:43 +00005251template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005252StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005253TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005254 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005255 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005256 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005257 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005258
Douglas Gregor43959a92009-08-20 07:17:43 +00005259 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005260 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005261 VarDecl *ConditionVar = 0;
5262 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005263 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005264 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005265 getDerived().TransformDefinition(
5266 S->getConditionVariable()->getLocation(),
5267 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005268 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005269 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005270 } else {
5271 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005272
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005273 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005274 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005275
5276 if (S->getCond()) {
5277 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005278 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5279 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005280 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005281 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005282
John McCall9ae2f072010-08-23 23:25:46 +00005283 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005284 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005285 }
Mike Stump1eb44332009-09-09 15:08:12 +00005286
John McCall9ae2f072010-08-23 23:25:46 +00005287 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5288 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005289 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005290
Douglas Gregor43959a92009-08-20 07:17:43 +00005291 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005292 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005293 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005294 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005295
John McCall9ae2f072010-08-23 23:25:46 +00005296 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5297 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005298 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005299
Douglas Gregor43959a92009-08-20 07:17:43 +00005300 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005301 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005302 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005303 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005304
Douglas Gregor43959a92009-08-20 07:17:43 +00005305 if (!getDerived().AlwaysRebuild() &&
5306 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005307 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005308 Inc.get() == S->getInc() &&
5309 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005310 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005311
Douglas Gregor43959a92009-08-20 07:17:43 +00005312 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005313 Init.get(), FullCond, ConditionVar,
5314 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005315}
5316
5317template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005318StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005319TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005320 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5321 S->getLabel());
5322 if (!LD)
5323 return StmtError();
5324
Douglas Gregor43959a92009-08-20 07:17:43 +00005325 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005326 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005327 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005328}
5329
5330template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005331StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005332TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005333 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005334 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005335 return StmtError();
Eli Friedmand29975f2012-01-31 22:47:07 +00005336 Target = SemaRef.MaybeCreateExprWithCleanups(Target.take());
Mike Stump1eb44332009-09-09 15:08:12 +00005337
Douglas Gregor43959a92009-08-20 07:17:43 +00005338 if (!getDerived().AlwaysRebuild() &&
5339 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005340 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005341
5342 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005343 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005344}
5345
5346template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005347StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005348TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005349 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005350}
Mike Stump1eb44332009-09-09 15:08:12 +00005351
Douglas Gregor43959a92009-08-20 07:17:43 +00005352template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005353StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005354TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005355 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005356}
Mike Stump1eb44332009-09-09 15:08:12 +00005357
Douglas Gregor43959a92009-08-20 07:17:43 +00005358template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005359StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005360TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005361 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005362 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005363 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005364
Mike Stump1eb44332009-09-09 15:08:12 +00005365 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005366 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005367 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005368}
Mike Stump1eb44332009-09-09 15:08:12 +00005369
Douglas Gregor43959a92009-08-20 07:17:43 +00005370template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005371StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005372TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005373 bool DeclChanged = false;
Chris Lattner686775d2011-07-20 06:58:45 +00005374 SmallVector<Decl *, 4> Decls;
Douglas Gregor43959a92009-08-20 07:17:43 +00005375 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5376 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005377 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5378 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005379 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005380 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005381
Douglas Gregor43959a92009-08-20 07:17:43 +00005382 if (Transformed != *D)
5383 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005384
Douglas Gregor43959a92009-08-20 07:17:43 +00005385 Decls.push_back(Transformed);
5386 }
Mike Stump1eb44332009-09-09 15:08:12 +00005387
Douglas Gregor43959a92009-08-20 07:17:43 +00005388 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005389 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005390
5391 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005392 S->getStartLoc(), S->getEndLoc());
5393}
Mike Stump1eb44332009-09-09 15:08:12 +00005394
Douglas Gregor43959a92009-08-20 07:17:43 +00005395template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005396StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005397TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005398
John McCallca0408f2010-08-23 06:44:23 +00005399 ASTOwningVector<Expr*> Constraints(getSema());
5400 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner686775d2011-07-20 06:58:45 +00005401 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005402
John McCall60d7b3a2010-08-24 06:29:42 +00005403 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005404 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005405
5406 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005407
Anders Carlsson703e3942010-01-24 05:50:09 +00005408 // Go through the outputs.
5409 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005410 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005411
Anders Carlsson703e3942010-01-24 05:50:09 +00005412 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005413 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005414
Anders Carlsson703e3942010-01-24 05:50:09 +00005415 // Transform the output expr.
5416 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005417 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005418 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005419 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005420
Anders Carlsson703e3942010-01-24 05:50:09 +00005421 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005422
John McCall9ae2f072010-08-23 23:25:46 +00005423 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005424 }
Sean Huntc3021132010-05-05 15:23:54 +00005425
Anders Carlsson703e3942010-01-24 05:50:09 +00005426 // Go through the inputs.
5427 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005428 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005429
Anders Carlsson703e3942010-01-24 05:50:09 +00005430 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005431 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005432
Anders Carlsson703e3942010-01-24 05:50:09 +00005433 // Transform the input expr.
5434 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005435 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005436 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005437 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005438
Anders Carlsson703e3942010-01-24 05:50:09 +00005439 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005440
John McCall9ae2f072010-08-23 23:25:46 +00005441 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005442 }
Sean Huntc3021132010-05-05 15:23:54 +00005443
Anders Carlsson703e3942010-01-24 05:50:09 +00005444 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005445 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005446
5447 // Go through the clobbers.
5448 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005449 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005450
5451 // No need to transform the asm string literal.
5452 AsmString = SemaRef.Owned(S->getAsmString());
5453
5454 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5455 S->isSimple(),
5456 S->isVolatile(),
5457 S->getNumOutputs(),
5458 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005459 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005460 move_arg(Constraints),
5461 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005462 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005463 move_arg(Clobbers),
5464 S->getRParenLoc(),
5465 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005466}
5467
5468
5469template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005470StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005471TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005472 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005473 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005474 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005475 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005476
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005477 // Transform the @catch statements (if present).
5478 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005479 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005480 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005481 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005482 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005483 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005484 if (Catch.get() != S->getCatchStmt(I))
5485 AnyCatchChanged = true;
5486 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005487 }
Sean Huntc3021132010-05-05 15:23:54 +00005488
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005489 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005490 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005491 if (S->getFinallyStmt()) {
5492 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5493 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005494 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005495 }
5496
5497 // If nothing changed, just retain this statement.
5498 if (!getDerived().AlwaysRebuild() &&
5499 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005500 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005501 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005502 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005503
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005504 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005505 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5506 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005507}
Mike Stump1eb44332009-09-09 15:08:12 +00005508
Douglas Gregor43959a92009-08-20 07:17:43 +00005509template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005510StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005511TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005512 // Transform the @catch parameter, if there is one.
5513 VarDecl *Var = 0;
5514 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5515 TypeSourceInfo *TSInfo = 0;
5516 if (FromVar->getTypeSourceInfo()) {
5517 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5518 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005519 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005520 }
Sean Huntc3021132010-05-05 15:23:54 +00005521
Douglas Gregorbe270a02010-04-26 17:57:08 +00005522 QualType T;
5523 if (TSInfo)
5524 T = TSInfo->getType();
5525 else {
5526 T = getDerived().TransformType(FromVar->getType());
5527 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005528 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005529 }
Sean Huntc3021132010-05-05 15:23:54 +00005530
Douglas Gregorbe270a02010-04-26 17:57:08 +00005531 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5532 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005533 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005534 }
Sean Huntc3021132010-05-05 15:23:54 +00005535
John McCall60d7b3a2010-08-24 06:29:42 +00005536 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005537 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005538 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005539
5540 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005541 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005542 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005543}
Mike Stump1eb44332009-09-09 15:08:12 +00005544
Douglas Gregor43959a92009-08-20 07:17:43 +00005545template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005546StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005547TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005548 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005549 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005550 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005551 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005552
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005553 // If nothing changed, just retain this statement.
5554 if (!getDerived().AlwaysRebuild() &&
5555 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005556 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005557
5558 // Build a new statement.
5559 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005560 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005561}
Mike Stump1eb44332009-09-09 15:08:12 +00005562
Douglas Gregor43959a92009-08-20 07:17:43 +00005563template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005564StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005565TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005566 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005567 if (S->getThrowExpr()) {
5568 Operand = getDerived().TransformExpr(S->getThrowExpr());
5569 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005570 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005571 }
Sean Huntc3021132010-05-05 15:23:54 +00005572
Douglas Gregord1377b22010-04-22 21:44:01 +00005573 if (!getDerived().AlwaysRebuild() &&
5574 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005575 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005576
John McCall9ae2f072010-08-23 23:25:46 +00005577 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005578}
Mike Stump1eb44332009-09-09 15:08:12 +00005579
Douglas Gregor43959a92009-08-20 07:17:43 +00005580template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005581StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005582TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005583 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005584 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005585 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005586 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005587 return StmtError();
John McCall07524032011-07-27 21:50:02 +00005588 Object =
5589 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5590 Object.get());
5591 if (Object.isInvalid())
5592 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005593
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005594 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005595 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005596 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005597 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005598
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005599 // If nothing change, just retain the current statement.
5600 if (!getDerived().AlwaysRebuild() &&
5601 Object.get() == S->getSynchExpr() &&
5602 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005603 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005604
5605 // Build a new statement.
5606 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005607 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005608}
5609
5610template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005611StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005612TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5613 ObjCAutoreleasePoolStmt *S) {
5614 // Transform the body.
5615 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5616 if (Body.isInvalid())
5617 return StmtError();
5618
5619 // If nothing changed, just retain this statement.
5620 if (!getDerived().AlwaysRebuild() &&
5621 Body.get() == S->getSubStmt())
5622 return SemaRef.Owned(S);
5623
5624 // Build a new statement.
5625 return getDerived().RebuildObjCAutoreleasePoolStmt(
5626 S->getAtLoc(), Body.get());
5627}
5628
5629template<typename Derived>
5630StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005631TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005632 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005633 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005634 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005635 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005636 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005637
Douglas Gregorc3203e72010-04-22 23:10:45 +00005638 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005639 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005640 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005641 return StmtError();
John McCall990567c2011-07-27 01:07:15 +00005642 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5643 Collection.take());
5644 if (Collection.isInvalid())
5645 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005646
Douglas Gregorc3203e72010-04-22 23:10:45 +00005647 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005648 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005649 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005650 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005651
Douglas Gregorc3203e72010-04-22 23:10:45 +00005652 // If nothing changed, just retain this statement.
5653 if (!getDerived().AlwaysRebuild() &&
5654 Element.get() == S->getElement() &&
5655 Collection.get() == S->getCollection() &&
5656 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005657 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005658
Douglas Gregorc3203e72010-04-22 23:10:45 +00005659 // Build a new statement.
5660 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5661 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005662 Element.get(),
5663 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005664 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005665 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005666}
5667
5668
5669template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005670StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005671TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5672 // Transform the exception declaration, if any.
5673 VarDecl *Var = 0;
5674 if (S->getExceptionDecl()) {
5675 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005676 TypeSourceInfo *T = getDerived().TransformType(
5677 ExceptionDecl->getTypeSourceInfo());
5678 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005679 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005680
Douglas Gregor83cb9422010-09-09 17:09:21 +00005681 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005682 ExceptionDecl->getInnerLocStart(),
5683 ExceptionDecl->getLocation(),
5684 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005685 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005686 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005687 }
Mike Stump1eb44332009-09-09 15:08:12 +00005688
Douglas Gregor43959a92009-08-20 07:17:43 +00005689 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005690 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005691 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005692 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005693
Douglas Gregor43959a92009-08-20 07:17:43 +00005694 if (!getDerived().AlwaysRebuild() &&
5695 !Var &&
5696 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005697 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005698
5699 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5700 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005701 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005702}
Mike Stump1eb44332009-09-09 15:08:12 +00005703
Douglas Gregor43959a92009-08-20 07:17:43 +00005704template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005705StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005706TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5707 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005708 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005709 = getDerived().TransformCompoundStmt(S->getTryBlock());
5710 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005711 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005712
Douglas Gregor43959a92009-08-20 07:17:43 +00005713 // Transform the handlers.
5714 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005715 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005716 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005717 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005718 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5719 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005720 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005721
Douglas Gregor43959a92009-08-20 07:17:43 +00005722 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5723 Handlers.push_back(Handler.takeAs<Stmt>());
5724 }
Mike Stump1eb44332009-09-09 15:08:12 +00005725
Douglas Gregor43959a92009-08-20 07:17:43 +00005726 if (!getDerived().AlwaysRebuild() &&
5727 TryBlock.get() == S->getTryBlock() &&
5728 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005729 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005730
John McCall9ae2f072010-08-23 23:25:46 +00005731 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005732 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005733}
Mike Stump1eb44332009-09-09 15:08:12 +00005734
Richard Smithad762fc2011-04-14 22:09:26 +00005735template<typename Derived>
5736StmtResult
5737TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5738 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5739 if (Range.isInvalid())
5740 return StmtError();
5741
5742 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5743 if (BeginEnd.isInvalid())
5744 return StmtError();
5745
5746 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5747 if (Cond.isInvalid())
5748 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005749 if (Cond.get())
5750 Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc());
5751 if (Cond.isInvalid())
5752 return StmtError();
5753 if (Cond.get())
5754 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005755
5756 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5757 if (Inc.isInvalid())
5758 return StmtError();
Eli Friedmanc6c14e52012-01-31 22:45:40 +00005759 if (Inc.get())
5760 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take());
Richard Smithad762fc2011-04-14 22:09:26 +00005761
5762 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5763 if (LoopVar.isInvalid())
5764 return StmtError();
5765
5766 StmtResult NewStmt = S;
5767 if (getDerived().AlwaysRebuild() ||
5768 Range.get() != S->getRangeStmt() ||
5769 BeginEnd.get() != S->getBeginEndStmt() ||
5770 Cond.get() != S->getCond() ||
5771 Inc.get() != S->getInc() ||
5772 LoopVar.get() != S->getLoopVarStmt())
5773 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5774 S->getColonLoc(), Range.get(),
5775 BeginEnd.get(), Cond.get(),
5776 Inc.get(), LoopVar.get(),
5777 S->getRParenLoc());
5778
5779 StmtResult Body = getDerived().TransformStmt(S->getBody());
5780 if (Body.isInvalid())
5781 return StmtError();
5782
5783 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5784 // it now so we have a new statement to attach the body to.
5785 if (Body.get() != S->getBody() && NewStmt.get() == S)
5786 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5787 S->getColonLoc(), Range.get(),
5788 BeginEnd.get(), Cond.get(),
5789 Inc.get(), LoopVar.get(),
5790 S->getRParenLoc());
5791
5792 if (NewStmt.get() == S)
5793 return SemaRef.Owned(S);
5794
5795 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5796}
5797
John Wiegley28bbe4b2011-04-28 01:08:34 +00005798template<typename Derived>
5799StmtResult
Douglas Gregorba0513d2011-10-25 01:33:02 +00005800TreeTransform<Derived>::TransformMSDependentExistsStmt(
5801 MSDependentExistsStmt *S) {
5802 // Transform the nested-name-specifier, if any.
5803 NestedNameSpecifierLoc QualifierLoc;
5804 if (S->getQualifierLoc()) {
5805 QualifierLoc
5806 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
5807 if (!QualifierLoc)
5808 return StmtError();
5809 }
5810
5811 // Transform the declaration name.
5812 DeclarationNameInfo NameInfo = S->getNameInfo();
5813 if (NameInfo.getName()) {
5814 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5815 if (!NameInfo.getName())
5816 return StmtError();
5817 }
5818
5819 // Check whether anything changed.
5820 if (!getDerived().AlwaysRebuild() &&
5821 QualifierLoc == S->getQualifierLoc() &&
5822 NameInfo.getName() == S->getNameInfo().getName())
5823 return S;
5824
5825 // Determine whether this name exists, if we can.
5826 CXXScopeSpec SS;
5827 SS.Adopt(QualifierLoc);
5828 bool Dependent = false;
5829 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) {
5830 case Sema::IER_Exists:
5831 if (S->isIfExists())
5832 break;
5833
5834 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5835
5836 case Sema::IER_DoesNotExist:
5837 if (S->isIfNotExists())
5838 break;
5839
5840 return new (getSema().Context) NullStmt(S->getKeywordLoc());
5841
5842 case Sema::IER_Dependent:
5843 Dependent = true;
5844 break;
Douglas Gregor65019ac2011-10-25 03:44:56 +00005845
5846 case Sema::IER_Error:
5847 return StmtError();
Douglas Gregorba0513d2011-10-25 01:33:02 +00005848 }
5849
5850 // We need to continue with the instantiation, so do so now.
5851 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
5852 if (SubStmt.isInvalid())
5853 return StmtError();
5854
5855 // If we have resolved the name, just transform to the substatement.
5856 if (!Dependent)
5857 return SubStmt;
5858
5859 // The name is still dependent, so build a dependent expression again.
5860 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
5861 S->isIfExists(),
5862 QualifierLoc,
5863 NameInfo,
5864 SubStmt.get());
5865}
5866
5867template<typename Derived>
5868StmtResult
John Wiegley28bbe4b2011-04-28 01:08:34 +00005869TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5870 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5871 if(TryBlock.isInvalid()) return StmtError();
5872
5873 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5874 if(!getDerived().AlwaysRebuild() &&
5875 TryBlock.get() == S->getTryBlock() &&
5876 Handler.get() == S->getHandler())
5877 return SemaRef.Owned(S);
5878
5879 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5880 S->getTryLoc(),
5881 TryBlock.take(),
5882 Handler.take());
5883}
5884
5885template<typename Derived>
5886StmtResult
5887TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5888 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5889 if(Block.isInvalid()) return StmtError();
5890
5891 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5892 Block.take());
5893}
5894
5895template<typename Derived>
5896StmtResult
5897TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5898 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5899 if(FilterExpr.isInvalid()) return StmtError();
5900
5901 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5902 if(Block.isInvalid()) return StmtError();
5903
5904 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5905 FilterExpr.take(),
5906 Block.take());
5907}
5908
5909template<typename Derived>
5910StmtResult
5911TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5912 if(isa<SEHFinallyStmt>(Handler))
5913 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5914 else
5915 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5916}
5917
Douglas Gregor43959a92009-08-20 07:17:43 +00005918//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005919// Expression transformation
5920//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005921template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005922ExprResult
John McCall454feb92009-12-08 09:21:05 +00005923TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005924 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005925}
Mike Stump1eb44332009-09-09 15:08:12 +00005926
5927template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005928ExprResult
John McCall454feb92009-12-08 09:21:05 +00005929TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005930 NestedNameSpecifierLoc QualifierLoc;
5931 if (E->getQualifierLoc()) {
5932 QualifierLoc
5933 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5934 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005935 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005936 }
John McCalldbd872f2009-12-08 09:08:17 +00005937
5938 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005939 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5940 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005941 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005942 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005943
John McCallec8045d2010-08-17 21:27:17 +00005944 DeclarationNameInfo NameInfo = E->getNameInfo();
5945 if (NameInfo.getName()) {
5946 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5947 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005948 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005949 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005950
5951 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005952 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005953 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005954 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005955 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005956
5957 // Mark it referenced in the new context regardless.
5958 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00005959 SemaRef.MarkDeclRefReferenced(E);
John McCalldbd872f2009-12-08 09:08:17 +00005960
John McCall3fa5cae2010-10-26 07:05:15 +00005961 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005962 }
John McCalldbd872f2009-12-08 09:08:17 +00005963
5964 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005965 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005966 TemplateArgs = &TransArgs;
5967 TransArgs.setLAngleLoc(E->getLAngleLoc());
5968 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005969 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5970 E->getNumTemplateArgs(),
5971 TransArgs))
5972 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005973 }
5974
Douglas Gregor40d96a62011-02-28 21:54:11 +00005975 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5976 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005977}
Mike Stump1eb44332009-09-09 15:08:12 +00005978
Douglas Gregorb98b1992009-08-11 05:31:07 +00005979template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005980ExprResult
John McCall454feb92009-12-08 09:21:05 +00005981TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005982 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005983}
Mike Stump1eb44332009-09-09 15:08:12 +00005984
Douglas Gregorb98b1992009-08-11 05:31:07 +00005985template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005986ExprResult
John McCall454feb92009-12-08 09:21:05 +00005987TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005988 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005989}
Mike Stump1eb44332009-09-09 15:08:12 +00005990
Douglas Gregorb98b1992009-08-11 05:31:07 +00005991template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005992ExprResult
John McCall454feb92009-12-08 09:21:05 +00005993TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005994 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005995}
Mike Stump1eb44332009-09-09 15:08:12 +00005996
Douglas Gregorb98b1992009-08-11 05:31:07 +00005997template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005998ExprResult
John McCall454feb92009-12-08 09:21:05 +00005999TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006000 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006001}
Mike Stump1eb44332009-09-09 15:08:12 +00006002
Douglas Gregorb98b1992009-08-11 05:31:07 +00006003template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006004ExprResult
John McCall454feb92009-12-08 09:21:05 +00006005TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006006 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006007}
6008
6009template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006010ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00006011TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
6012 ExprResult ControllingExpr =
6013 getDerived().TransformExpr(E->getControllingExpr());
6014 if (ControllingExpr.isInvalid())
6015 return ExprError();
6016
Chris Lattner686775d2011-07-20 06:58:45 +00006017 SmallVector<Expr *, 4> AssocExprs;
6018 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbournef111d932011-04-15 00:35:48 +00006019 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
6020 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
6021 if (TS) {
6022 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
6023 if (!AssocType)
6024 return ExprError();
6025 AssocTypes.push_back(AssocType);
6026 } else {
6027 AssocTypes.push_back(0);
6028 }
6029
6030 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
6031 if (AssocExpr.isInvalid())
6032 return ExprError();
6033 AssocExprs.push_back(AssocExpr.release());
6034 }
6035
6036 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
6037 E->getDefaultLoc(),
6038 E->getRParenLoc(),
6039 ControllingExpr.release(),
6040 AssocTypes.data(),
6041 AssocExprs.data(),
6042 E->getNumAssocs());
6043}
6044
6045template<typename Derived>
6046ExprResult
John McCall454feb92009-12-08 09:21:05 +00006047TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006048 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006049 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006050 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006051
Douglas Gregorb98b1992009-08-11 05:31:07 +00006052 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006053 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006054
John McCall9ae2f072010-08-23 23:25:46 +00006055 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006056 E->getRParen());
6057}
6058
Mike Stump1eb44332009-09-09 15:08:12 +00006059template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006060ExprResult
John McCall454feb92009-12-08 09:21:05 +00006061TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006062 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006063 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006064 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006065
Douglas Gregorb98b1992009-08-11 05:31:07 +00006066 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006067 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006068
Douglas Gregorb98b1992009-08-11 05:31:07 +00006069 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
6070 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006071 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006072}
Mike Stump1eb44332009-09-09 15:08:12 +00006073
Douglas Gregorb98b1992009-08-11 05:31:07 +00006074template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006075ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006076TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
6077 // Transform the type.
6078 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
6079 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00006080 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006081
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006082 // Transform all of the components into components similar to what the
6083 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00006084 // FIXME: It would be slightly more efficient in the non-dependent case to
6085 // just map FieldDecls, rather than requiring the rebuilder to look for
6086 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006087 // template code that we don't care.
6088 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00006089 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006090 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner686775d2011-07-20 06:58:45 +00006091 SmallVector<Component, 4> Components;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006092 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
6093 const Node &ON = E->getComponent(I);
6094 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00006095 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00006096 Comp.LocStart = ON.getSourceRange().getBegin();
6097 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006098 switch (ON.getKind()) {
6099 case Node::Array: {
6100 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00006101 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006102 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006103 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006104
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006105 ExprChanged = ExprChanged || Index.get() != FromIndex;
6106 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00006107 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006108 break;
6109 }
Sean Huntc3021132010-05-05 15:23:54 +00006110
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006111 case Node::Field:
6112 case Node::Identifier:
6113 Comp.isBrackets = false;
6114 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00006115 if (!Comp.U.IdentInfo)
6116 continue;
Sean Huntc3021132010-05-05 15:23:54 +00006117
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006118 break;
Sean Huntc3021132010-05-05 15:23:54 +00006119
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00006120 case Node::Base:
6121 // Will be recomputed during the rebuild.
6122 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006123 }
Sean Huntc3021132010-05-05 15:23:54 +00006124
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006125 Components.push_back(Comp);
6126 }
Sean Huntc3021132010-05-05 15:23:54 +00006127
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006128 // If nothing changed, retain the existing expression.
6129 if (!getDerived().AlwaysRebuild() &&
6130 Type == E->getTypeSourceInfo() &&
6131 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006132 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006133
Douglas Gregor8ecdb652010-04-28 22:16:22 +00006134 // Build a new offsetof expression.
6135 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
6136 Components.data(), Components.size(),
6137 E->getRParenLoc());
6138}
6139
6140template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006141ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00006142TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
6143 assert(getDerived().AlreadyTransformed(E->getType()) &&
6144 "opaque value expression requires transformation");
6145 return SemaRef.Owned(E);
6146}
6147
6148template<typename Derived>
6149ExprResult
John McCall4b9c2d22011-11-06 09:01:30 +00006150TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCall01e19be2011-11-30 04:42:31 +00006151 // Rebuild the syntactic form. The original syntactic form has
6152 // opaque-value expressions in it, so strip those away and rebuild
6153 // the result. This is a really awful way of doing this, but the
6154 // better solution (rebuilding the semantic expressions and
6155 // rebinding OVEs as necessary) doesn't work; we'd need
6156 // TreeTransform to not strip away implicit conversions.
6157 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
6158 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCall4b9c2d22011-11-06 09:01:30 +00006159 if (result.isInvalid()) return ExprError();
6160
6161 // If that gives us a pseudo-object result back, the pseudo-object
6162 // expression must have been an lvalue-to-rvalue conversion which we
6163 // should reapply.
6164 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
6165 result = SemaRef.checkPseudoObjectRValue(result.take());
6166
6167 return result;
6168}
6169
6170template<typename Derived>
6171ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006172TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
6173 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006174 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00006175 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00006176
John McCalla93c9342009-12-07 02:54:59 +00006177 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00006178 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006179 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006180
John McCall5ab75172009-11-04 07:28:41 +00006181 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00006182 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006183
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006184 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
6185 E->getKind(),
6186 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006187 }
Mike Stump1eb44332009-09-09 15:08:12 +00006188
John McCall60d7b3a2010-08-24 06:29:42 +00006189 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00006190 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006191 // C++0x [expr.sizeof]p1:
6192 // The operand is either an expression, which is an unevaluated operand
6193 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00006194 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006195
Douglas Gregorb98b1992009-08-11 05:31:07 +00006196 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
6197 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006198 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006199
Douglas Gregorb98b1992009-08-11 05:31:07 +00006200 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006201 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006202 }
Mike Stump1eb44332009-09-09 15:08:12 +00006203
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00006204 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6205 E->getOperatorLoc(),
6206 E->getKind(),
6207 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006208}
Mike Stump1eb44332009-09-09 15:08:12 +00006209
Douglas Gregorb98b1992009-08-11 05:31:07 +00006210template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006211ExprResult
John McCall454feb92009-12-08 09:21:05 +00006212TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006213 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006214 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006215 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006216
John McCall60d7b3a2010-08-24 06:29:42 +00006217 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006218 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006219 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006220
6221
Douglas Gregorb98b1992009-08-11 05:31:07 +00006222 if (!getDerived().AlwaysRebuild() &&
6223 LHS.get() == E->getLHS() &&
6224 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006225 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006226
John McCall9ae2f072010-08-23 23:25:46 +00006227 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006228 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006229 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006230 E->getRBracketLoc());
6231}
Mike Stump1eb44332009-09-09 15:08:12 +00006232
6233template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006234ExprResult
John McCall454feb92009-12-08 09:21:05 +00006235TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006236 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006237 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006238 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006239 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006240
6241 // Transform arguments.
6242 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006243 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006244 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6245 &ArgChanged))
6246 return ExprError();
6247
Douglas Gregorb98b1992009-08-11 05:31:07 +00006248 if (!getDerived().AlwaysRebuild() &&
6249 Callee.get() == E->getCallee() &&
6250 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006251 return SemaRef.MaybeBindToTemporary(E);;
Mike Stump1eb44332009-09-09 15:08:12 +00006252
Douglas Gregorb98b1992009-08-11 05:31:07 +00006253 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006254 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006255 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006256 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006257 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006258 E->getRParenLoc());
6259}
Mike Stump1eb44332009-09-09 15:08:12 +00006260
6261template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006262ExprResult
John McCall454feb92009-12-08 09:21:05 +00006263TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006264 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006265 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006266 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006267
Douglas Gregor40d96a62011-02-28 21:54:11 +00006268 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006269 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006270 QualifierLoc
6271 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6272
6273 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006274 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006275 }
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006276 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00006277
Eli Friedmanf595cc42009-12-04 06:40:45 +00006278 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006279 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6280 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006281 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006282 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006283
John McCall6bb80172010-03-30 21:47:33 +00006284 NamedDecl *FoundDecl = E->getFoundDecl();
6285 if (FoundDecl == E->getMemberDecl()) {
6286 FoundDecl = Member;
6287 } else {
6288 FoundDecl = cast_or_null<NamedDecl>(
6289 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6290 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006291 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006292 }
6293
Douglas Gregorb98b1992009-08-11 05:31:07 +00006294 if (!getDerived().AlwaysRebuild() &&
6295 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006296 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006297 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006298 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006299 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006300
Anders Carlsson1f240322009-12-22 05:24:09 +00006301 // Mark it referenced in the new context regardless.
6302 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00006303 SemaRef.MarkMemberReferenced(E);
6304
John McCall3fa5cae2010-10-26 07:05:15 +00006305 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006306 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006307
John McCalld5532b62009-11-23 01:53:49 +00006308 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006309 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006310 TransArgs.setLAngleLoc(E->getLAngleLoc());
6311 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006312 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6313 E->getNumTemplateArgs(),
6314 TransArgs))
6315 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006316 }
Sean Huntc3021132010-05-05 15:23:54 +00006317
Douglas Gregorb98b1992009-08-11 05:31:07 +00006318 // FIXME: Bogus source location for the operator
6319 SourceLocation FakeOperatorLoc
6320 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6321
John McCallc2233c52010-01-15 08:34:02 +00006322 // FIXME: to do this check properly, we will need to preserve the
6323 // first-qualifier-in-scope here, just in case we had a dependent
6324 // base (and therefore couldn't do the check) and a
6325 // nested-name-qualifier (and therefore could do the lookup).
6326 NamedDecl *FirstQualifierInScope = 0;
6327
John McCall9ae2f072010-08-23 23:25:46 +00006328 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006329 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006330 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00006331 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006332 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006333 Member,
John McCall6bb80172010-03-30 21:47:33 +00006334 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006335 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006336 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006337 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006338}
Mike Stump1eb44332009-09-09 15:08:12 +00006339
Douglas Gregorb98b1992009-08-11 05:31:07 +00006340template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006341ExprResult
John McCall454feb92009-12-08 09:21:05 +00006342TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006343 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006344 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006345 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006346
John McCall60d7b3a2010-08-24 06:29:42 +00006347 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006348 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006349 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006350
Douglas Gregorb98b1992009-08-11 05:31:07 +00006351 if (!getDerived().AlwaysRebuild() &&
6352 LHS.get() == E->getLHS() &&
6353 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006354 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006355
Douglas Gregorb98b1992009-08-11 05:31:07 +00006356 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006357 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006358}
6359
Mike Stump1eb44332009-09-09 15:08:12 +00006360template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006361ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006362TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006363 CompoundAssignOperator *E) {
6364 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006365}
Mike Stump1eb44332009-09-09 15:08:12 +00006366
Douglas Gregorb98b1992009-08-11 05:31:07 +00006367template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006368ExprResult TreeTransform<Derived>::
6369TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6370 // Just rebuild the common and RHS expressions and see whether we
6371 // get any changes.
6372
6373 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6374 if (commonExpr.isInvalid())
6375 return ExprError();
6376
6377 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6378 if (rhs.isInvalid())
6379 return ExprError();
6380
6381 if (!getDerived().AlwaysRebuild() &&
6382 commonExpr.get() == e->getCommon() &&
6383 rhs.get() == e->getFalseExpr())
6384 return SemaRef.Owned(e);
6385
6386 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6387 e->getQuestionLoc(),
6388 0,
6389 e->getColonLoc(),
6390 rhs.get());
6391}
6392
6393template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006394ExprResult
John McCall454feb92009-12-08 09:21:05 +00006395TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006396 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006397 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006398 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006399
John McCall60d7b3a2010-08-24 06:29:42 +00006400 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006401 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006402 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006403
John McCall60d7b3a2010-08-24 06:29:42 +00006404 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006405 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006406 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006407
Douglas Gregorb98b1992009-08-11 05:31:07 +00006408 if (!getDerived().AlwaysRebuild() &&
6409 Cond.get() == E->getCond() &&
6410 LHS.get() == E->getLHS() &&
6411 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006412 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006413
John McCall9ae2f072010-08-23 23:25:46 +00006414 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006415 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006416 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006417 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006418 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006419}
Mike Stump1eb44332009-09-09 15:08:12 +00006420
6421template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006422ExprResult
John McCall454feb92009-12-08 09:21:05 +00006423TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006424 // Implicit casts are eliminated during transformation, since they
6425 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006426 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006427}
Mike Stump1eb44332009-09-09 15:08:12 +00006428
Douglas Gregorb98b1992009-08-11 05:31:07 +00006429template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006430ExprResult
John McCall454feb92009-12-08 09:21:05 +00006431TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006432 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6433 if (!Type)
6434 return ExprError();
6435
John McCall60d7b3a2010-08-24 06:29:42 +00006436 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006437 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006439 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006440
Douglas Gregorb98b1992009-08-11 05:31:07 +00006441 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006442 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006443 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006444 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006445
John McCall9d125032010-01-15 18:39:57 +00006446 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006447 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006448 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006449 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006450}
Mike Stump1eb44332009-09-09 15:08:12 +00006451
Douglas Gregorb98b1992009-08-11 05:31:07 +00006452template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006453ExprResult
John McCall454feb92009-12-08 09:21:05 +00006454TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006455 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6456 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6457 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006458 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006459
John McCall60d7b3a2010-08-24 06:29:42 +00006460 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006462 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006463
Douglas Gregorb98b1992009-08-11 05:31:07 +00006464 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006465 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006466 Init.get() == E->getInitializer())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006467 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006468
John McCall1d7d8d62010-01-19 22:33:45 +00006469 // Note: the expression type doesn't necessarily match the
6470 // type-as-written, but that's okay, because it should always be
6471 // derivable from the initializer.
6472
John McCall42f56b52010-01-18 19:35:47 +00006473 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006474 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006475 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476}
Mike Stump1eb44332009-09-09 15:08:12 +00006477
Douglas Gregorb98b1992009-08-11 05:31:07 +00006478template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006479ExprResult
John McCall454feb92009-12-08 09:21:05 +00006480TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006481 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006482 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006483 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006484
Douglas Gregorb98b1992009-08-11 05:31:07 +00006485 if (!getDerived().AlwaysRebuild() &&
6486 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006487 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006488
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006490 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006492 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006493 E->getAccessorLoc(),
6494 E->getAccessor());
6495}
Mike Stump1eb44332009-09-09 15:08:12 +00006496
Douglas Gregorb98b1992009-08-11 05:31:07 +00006497template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006498ExprResult
John McCall454feb92009-12-08 09:21:05 +00006499TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006500 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006501
John McCallca0408f2010-08-23 06:44:23 +00006502 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006503 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6504 Inits, &InitChanged))
6505 return ExprError();
6506
Douglas Gregorb98b1992009-08-11 05:31:07 +00006507 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006508 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006509
Douglas Gregorb98b1992009-08-11 05:31:07 +00006510 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006511 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006512}
Mike Stump1eb44332009-09-09 15:08:12 +00006513
Douglas Gregorb98b1992009-08-11 05:31:07 +00006514template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006515ExprResult
John McCall454feb92009-12-08 09:21:05 +00006516TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006517 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006518
Douglas Gregor43959a92009-08-20 07:17:43 +00006519 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006520 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006521 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006522 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006523
Douglas Gregor43959a92009-08-20 07:17:43 +00006524 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006525 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526 bool ExprChanged = false;
6527 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6528 DEnd = E->designators_end();
6529 D != DEnd; ++D) {
6530 if (D->isFieldDesignator()) {
6531 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6532 D->getDotLoc(),
6533 D->getFieldLoc()));
6534 continue;
6535 }
Mike Stump1eb44332009-09-09 15:08:12 +00006536
Douglas Gregorb98b1992009-08-11 05:31:07 +00006537 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006538 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006540 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006541
6542 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006543 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006544
Douglas Gregorb98b1992009-08-11 05:31:07 +00006545 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6546 ArrayExprs.push_back(Index.release());
6547 continue;
6548 }
Mike Stump1eb44332009-09-09 15:08:12 +00006549
Douglas Gregorb98b1992009-08-11 05:31:07 +00006550 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006551 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006552 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6553 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006554 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006555
John McCall60d7b3a2010-08-24 06:29:42 +00006556 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006557 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006558 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006559
6560 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006561 End.get(),
6562 D->getLBracketLoc(),
6563 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006564
Douglas Gregorb98b1992009-08-11 05:31:07 +00006565 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6566 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006567
Douglas Gregorb98b1992009-08-11 05:31:07 +00006568 ArrayExprs.push_back(Start.release());
6569 ArrayExprs.push_back(End.release());
6570 }
Mike Stump1eb44332009-09-09 15:08:12 +00006571
Douglas Gregorb98b1992009-08-11 05:31:07 +00006572 if (!getDerived().AlwaysRebuild() &&
6573 Init.get() == E->getInit() &&
6574 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006575 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006576
Douglas Gregorb98b1992009-08-11 05:31:07 +00006577 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6578 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006579 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006580}
Mike Stump1eb44332009-09-09 15:08:12 +00006581
Douglas Gregorb98b1992009-08-11 05:31:07 +00006582template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006583ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006584TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006585 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006586 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006587
Douglas Gregor5557b252009-10-28 00:29:27 +00006588 // FIXME: Will we ever have proper type location here? Will we actually
6589 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006590 QualType T = getDerived().TransformType(E->getType());
6591 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006592 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006593
Douglas Gregorb98b1992009-08-11 05:31:07 +00006594 if (!getDerived().AlwaysRebuild() &&
6595 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006596 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006597
Douglas Gregorb98b1992009-08-11 05:31:07 +00006598 return getDerived().RebuildImplicitValueInitExpr(T);
6599}
Mike Stump1eb44332009-09-09 15:08:12 +00006600
Douglas Gregorb98b1992009-08-11 05:31:07 +00006601template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006602ExprResult
John McCall454feb92009-12-08 09:21:05 +00006603TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006604 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6605 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006606 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006607
John McCall60d7b3a2010-08-24 06:29:42 +00006608 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006609 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006610 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006611
Douglas Gregorb98b1992009-08-11 05:31:07 +00006612 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006613 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006614 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006615 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006616
John McCall9ae2f072010-08-23 23:25:46 +00006617 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006618 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006619}
6620
6621template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006622ExprResult
John McCall454feb92009-12-08 09:21:05 +00006623TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006625 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006626 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6627 &ArgumentChanged))
6628 return ExprError();
6629
Douglas Gregorb98b1992009-08-11 05:31:07 +00006630 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6631 move_arg(Inits),
6632 E->getRParenLoc());
6633}
Mike Stump1eb44332009-09-09 15:08:12 +00006634
Douglas Gregorb98b1992009-08-11 05:31:07 +00006635/// \brief Transform an address-of-label expression.
6636///
6637/// By default, the transformation of an address-of-label expression always
6638/// rebuilds the expression, so that the label identifier can be resolved to
6639/// the corresponding label statement by semantic analysis.
6640template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006641ExprResult
John McCall454feb92009-12-08 09:21:05 +00006642TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006643 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6644 E->getLabel());
6645 if (!LD)
6646 return ExprError();
6647
Douglas Gregorb98b1992009-08-11 05:31:07 +00006648 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006649 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006650}
Mike Stump1eb44332009-09-09 15:08:12 +00006651
6652template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006653ExprResult
John McCall454feb92009-12-08 09:21:05 +00006654TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006655 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006656 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6657 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006658 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006659
Douglas Gregorb98b1992009-08-11 05:31:07 +00006660 if (!getDerived().AlwaysRebuild() &&
6661 SubStmt.get() == E->getSubStmt())
Douglas Gregor92be2a52011-12-10 00:23:21 +00006662 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006663
6664 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006665 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006666 E->getRParenLoc());
6667}
Mike Stump1eb44332009-09-09 15:08:12 +00006668
Douglas Gregorb98b1992009-08-11 05:31:07 +00006669template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006670ExprResult
John McCall454feb92009-12-08 09:21:05 +00006671TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006672 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006673 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006674 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006675
John McCall60d7b3a2010-08-24 06:29:42 +00006676 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006677 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006678 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006679
John McCall60d7b3a2010-08-24 06:29:42 +00006680 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006681 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006682 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006683
Douglas Gregorb98b1992009-08-11 05:31:07 +00006684 if (!getDerived().AlwaysRebuild() &&
6685 Cond.get() == E->getCond() &&
6686 LHS.get() == E->getLHS() &&
6687 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006688 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006689
Douglas Gregorb98b1992009-08-11 05:31:07 +00006690 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006691 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 E->getRParenLoc());
6693}
Mike Stump1eb44332009-09-09 15:08:12 +00006694
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006696ExprResult
John McCall454feb92009-12-08 09:21:05 +00006697TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006698 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006699}
6700
6701template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006702ExprResult
John McCall454feb92009-12-08 09:21:05 +00006703TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006704 switch (E->getOperator()) {
6705 case OO_New:
6706 case OO_Delete:
6707 case OO_Array_New:
6708 case OO_Array_Delete:
6709 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006710 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006711
Douglas Gregor668d6d92009-12-13 20:44:55 +00006712 case OO_Call: {
6713 // This is a call to an object's operator().
6714 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6715
6716 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006717 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006718 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006719 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006720
6721 // FIXME: Poor location information
6722 SourceLocation FakeLParenLoc
6723 = SemaRef.PP.getLocForEndOfToken(
6724 static_cast<Expr *>(Object.get())->getLocEnd());
6725
6726 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006727 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006728 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6729 Args))
6730 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006731
John McCall9ae2f072010-08-23 23:25:46 +00006732 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006733 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006734 E->getLocEnd());
6735 }
6736
6737#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6738 case OO_##Name:
6739#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6740#include "clang/Basic/OperatorKinds.def"
6741 case OO_Subscript:
6742 // Handled below.
6743 break;
6744
6745 case OO_Conditional:
6746 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006747 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006748
6749 case OO_None:
6750 case NUM_OVERLOADED_OPERATORS:
6751 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006752 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006753 }
6754
John McCall60d7b3a2010-08-24 06:29:42 +00006755 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006756 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006757 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006758
John McCall60d7b3a2010-08-24 06:29:42 +00006759 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006760 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006761 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006762
John McCall60d7b3a2010-08-24 06:29:42 +00006763 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006764 if (E->getNumArgs() == 2) {
6765 Second = getDerived().TransformExpr(E->getArg(1));
6766 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006767 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006768 }
Mike Stump1eb44332009-09-09 15:08:12 +00006769
Douglas Gregorb98b1992009-08-11 05:31:07 +00006770 if (!getDerived().AlwaysRebuild() &&
6771 Callee.get() == E->getCallee() &&
6772 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006773 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregor92be2a52011-12-10 00:23:21 +00006774 return SemaRef.MaybeBindToTemporary(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006775
Douglas Gregorb98b1992009-08-11 05:31:07 +00006776 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6777 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006778 Callee.get(),
6779 First.get(),
6780 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006781}
Mike Stump1eb44332009-09-09 15:08:12 +00006782
Douglas Gregorb98b1992009-08-11 05:31:07 +00006783template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006784ExprResult
John McCall454feb92009-12-08 09:21:05 +00006785TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6786 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006787}
Mike Stump1eb44332009-09-09 15:08:12 +00006788
Douglas Gregorb98b1992009-08-11 05:31:07 +00006789template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006790ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006791TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6792 // Transform the callee.
6793 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6794 if (Callee.isInvalid())
6795 return ExprError();
6796
6797 // Transform exec config.
6798 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6799 if (EC.isInvalid())
6800 return ExprError();
6801
6802 // Transform arguments.
6803 bool ArgChanged = false;
6804 ASTOwningVector<Expr*> Args(SemaRef);
6805 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6806 &ArgChanged))
6807 return ExprError();
6808
6809 if (!getDerived().AlwaysRebuild() &&
6810 Callee.get() == E->getCallee() &&
6811 !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00006812 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbournee08ce652011-02-09 21:07:24 +00006813
6814 // FIXME: Wrong source location information for the '('.
6815 SourceLocation FakeLParenLoc
6816 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6817 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6818 move_arg(Args),
6819 E->getRParenLoc(), EC.get());
6820}
6821
6822template<typename Derived>
6823ExprResult
John McCall454feb92009-12-08 09:21:05 +00006824TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006825 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6826 if (!Type)
6827 return ExprError();
6828
John McCall60d7b3a2010-08-24 06:29:42 +00006829 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006830 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006831 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006832 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006833
Douglas Gregorb98b1992009-08-11 05:31:07 +00006834 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006835 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006836 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006837 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006838
Douglas Gregorb98b1992009-08-11 05:31:07 +00006839 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006840 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6842 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6843 SourceLocation FakeRParenLoc
6844 = SemaRef.PP.getLocForEndOfToken(
6845 E->getSubExpr()->getSourceRange().getEnd());
6846 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006847 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006848 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006849 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006850 FakeRAngleLoc,
6851 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006852 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006853 FakeRParenLoc);
6854}
Mike Stump1eb44332009-09-09 15:08:12 +00006855
Douglas Gregorb98b1992009-08-11 05:31:07 +00006856template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006857ExprResult
John McCall454feb92009-12-08 09:21:05 +00006858TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6859 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006860}
Mike Stump1eb44332009-09-09 15:08:12 +00006861
6862template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006863ExprResult
John McCall454feb92009-12-08 09:21:05 +00006864TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6865 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006866}
6867
Douglas Gregorb98b1992009-08-11 05:31:07 +00006868template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006869ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006871 CXXReinterpretCastExpr *E) {
6872 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006873}
Mike Stump1eb44332009-09-09 15:08:12 +00006874
Douglas Gregorb98b1992009-08-11 05:31:07 +00006875template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006876ExprResult
John McCall454feb92009-12-08 09:21:05 +00006877TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6878 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006879}
Mike Stump1eb44332009-09-09 15:08:12 +00006880
Douglas Gregorb98b1992009-08-11 05:31:07 +00006881template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006882ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006883TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006884 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006885 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6886 if (!Type)
6887 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006888
John McCall60d7b3a2010-08-24 06:29:42 +00006889 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006890 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006891 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006892 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006893
Douglas Gregorb98b1992009-08-11 05:31:07 +00006894 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006895 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006896 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006897 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006898
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006899 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006900 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006901 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006902 E->getRParenLoc());
6903}
Mike Stump1eb44332009-09-09 15:08:12 +00006904
Douglas Gregorb98b1992009-08-11 05:31:07 +00006905template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006906ExprResult
John McCall454feb92009-12-08 09:21:05 +00006907TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006908 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006909 TypeSourceInfo *TInfo
6910 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6911 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006912 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006913
Douglas Gregorb98b1992009-08-11 05:31:07 +00006914 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006915 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006916 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006917
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006918 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6919 E->getLocStart(),
6920 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006921 E->getLocEnd());
6922 }
Mike Stump1eb44332009-09-09 15:08:12 +00006923
Eli Friedmanef331b72012-01-20 01:26:23 +00006924 // We don't know whether the subexpression is potentially evaluated until
6925 // after we perform semantic analysis. We speculatively assume it is
6926 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregorb98b1992009-08-11 05:31:07 +00006927 // potentially evaluated.
Eli Friedmanef331b72012-01-20 01:26:23 +00006928 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006929
John McCall60d7b3a2010-08-24 06:29:42 +00006930 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006931 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006932 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006933
Douglas Gregorb98b1992009-08-11 05:31:07 +00006934 if (!getDerived().AlwaysRebuild() &&
6935 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006936 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006937
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006938 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6939 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006940 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006941 E->getLocEnd());
6942}
6943
6944template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006945ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006946TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6947 if (E->isTypeOperand()) {
6948 TypeSourceInfo *TInfo
6949 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6950 if (!TInfo)
6951 return ExprError();
6952
6953 if (!getDerived().AlwaysRebuild() &&
6954 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006955 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006956
Douglas Gregor3c52a212011-03-06 17:40:41 +00006957 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006958 E->getLocStart(),
6959 TInfo,
6960 E->getLocEnd());
6961 }
6962
Francois Pichet01b7c302010-09-08 12:20:18 +00006963 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6964
6965 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6966 if (SubExpr.isInvalid())
6967 return ExprError();
6968
6969 if (!getDerived().AlwaysRebuild() &&
6970 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006971 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006972
6973 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6974 E->getLocStart(),
6975 SubExpr.get(),
6976 E->getLocEnd());
6977}
6978
6979template<typename Derived>
6980ExprResult
John McCall454feb92009-12-08 09:21:05 +00006981TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006982 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983}
Mike Stump1eb44332009-09-09 15:08:12 +00006984
Douglas Gregorb98b1992009-08-11 05:31:07 +00006985template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006986ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006987TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006988 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006989 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006990}
Mike Stump1eb44332009-09-09 15:08:12 +00006991
Douglas Gregorb98b1992009-08-11 05:31:07 +00006992template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006993ExprResult
John McCall454feb92009-12-08 09:21:05 +00006994TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006995 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00006996 QualType T;
6997 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6998 T = MD->getThisType(getSema().Context);
6999 else
7000 T = getSema().Context.getPointerType(
7001 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00007002
Douglas Gregorba48d6a2010-09-09 16:55:46 +00007003 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00007004 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007005
Douglas Gregor828a1972010-01-07 23:12:05 +00007006 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007007}
Mike Stump1eb44332009-09-09 15:08:12 +00007008
Douglas Gregorb98b1992009-08-11 05:31:07 +00007009template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007010ExprResult
John McCall454feb92009-12-08 09:21:05 +00007011TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007012 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007013 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007014 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007015
Douglas Gregorb98b1992009-08-11 05:31:07 +00007016 if (!getDerived().AlwaysRebuild() &&
7017 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00007018 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007019
Douglas Gregorbca01b42011-07-06 22:04:06 +00007020 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
7021 E->isThrownVariableInScope());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007022}
Mike Stump1eb44332009-09-09 15:08:12 +00007023
Douglas Gregorb98b1992009-08-11 05:31:07 +00007024template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007025ExprResult
John McCall454feb92009-12-08 09:21:05 +00007026TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00007027 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007028 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
7029 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007030 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00007031 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007032
Chandler Carruth53cb6f82010-02-08 06:42:49 +00007033 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007034 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00007035 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007036
Douglas Gregor036aed12009-12-23 23:03:06 +00007037 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007038}
Mike Stump1eb44332009-09-09 15:08:12 +00007039
Douglas Gregorb98b1992009-08-11 05:31:07 +00007040template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007041ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00007042TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
7043 CXXScalarValueInitExpr *E) {
7044 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7045 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007046 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00007047
Douglas Gregorb98b1992009-08-11 05:31:07 +00007048 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007049 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007050 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007051
Douglas Gregorab6677e2010-09-08 00:15:04 +00007052 return getDerived().RebuildCXXScalarValueInitExpr(T,
7053 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00007054 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007055}
Mike Stump1eb44332009-09-09 15:08:12 +00007056
Douglas Gregorb98b1992009-08-11 05:31:07 +00007057template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007058ExprResult
John McCall454feb92009-12-08 09:21:05 +00007059TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007060 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007061 TypeSourceInfo *AllocTypeInfo
7062 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
7063 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007064 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007065
Douglas Gregorb98b1992009-08-11 05:31:07 +00007066 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00007067 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007068 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007069 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007070
Douglas Gregorb98b1992009-08-11 05:31:07 +00007071 // Transform the placement arguments (if any).
7072 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007073 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007074 if (getDerived().TransformExprs(E->getPlacementArgs(),
7075 E->getNumPlacementArgs(), true,
7076 PlacementArgs, &ArgumentChanged))
7077 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007078
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007079 // Transform the constructor arguments (if any).
7080 // As an annoying corner case, we may have introduced an implicit value-
7081 // initialization expression when allocating a new array, which we implicitly
7082 // drop. It will be re-created during type checking.
John McCallca0408f2010-08-23 06:44:23 +00007083 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007084 if (!(E->isArray() && E->getNumConstructorArgs() == 1 &&
7085 isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) &&
7086 TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
Douglas Gregoraa165f82011-01-03 19:04:46 +00007087 ConstructorArgs, &ArgumentChanged))
7088 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007089
Douglas Gregor1af74512010-02-26 00:38:10 +00007090 // Transform constructor, new operator, and delete operator.
7091 CXXConstructorDecl *Constructor = 0;
7092 if (E->getConstructor()) {
7093 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007094 getDerived().TransformDecl(E->getLocStart(),
7095 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007096 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007097 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007098 }
7099
7100 FunctionDecl *OperatorNew = 0;
7101 if (E->getOperatorNew()) {
7102 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007103 getDerived().TransformDecl(E->getLocStart(),
7104 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007105 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00007106 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007107 }
7108
7109 FunctionDecl *OperatorDelete = 0;
7110 if (E->getOperatorDelete()) {
7111 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007112 getDerived().TransformDecl(E->getLocStart(),
7113 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007114 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007115 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007116 }
Sean Huntc3021132010-05-05 15:23:54 +00007117
Douglas Gregorb98b1992009-08-11 05:31:07 +00007118 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007119 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007120 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007121 Constructor == E->getConstructor() &&
7122 OperatorNew == E->getOperatorNew() &&
7123 OperatorDelete == E->getOperatorDelete() &&
7124 !ArgumentChanged) {
7125 // Mark any declarations we need as referenced.
7126 // FIXME: instantiation-specific.
7127 if (Constructor)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007128 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Douglas Gregor1af74512010-02-26 00:38:10 +00007129 if (OperatorNew)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007130 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregor1af74512010-02-26 00:38:10 +00007131 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007132 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007133
7134 if (E->isArray() && Constructor &&
7135 !E->getAllocatedType()->isDependentType()) {
7136 QualType ElementType
7137 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
7138 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
7139 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
7140 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedman5f2987c2012-02-02 03:46:19 +00007141 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor2ad63cf2011-07-26 15:11:03 +00007142 }
7143 }
7144 }
7145
John McCall3fa5cae2010-10-26 07:05:15 +00007146 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007147 }
Mike Stump1eb44332009-09-09 15:08:12 +00007148
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007149 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007150 if (!ArraySize.get()) {
7151 // If no array size was specified, but the new expression was
7152 // instantiated with an array type (e.g., "new T" where T is
7153 // instantiated with "int[4]"), extract the outer bound from the
7154 // array type as our array size. We do this with constant and
7155 // dependently-sized array types.
7156 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
7157 if (!ArrayT) {
7158 // Do nothing
7159 } else if (const ConstantArrayType *ConsArrayT
7160 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00007161 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007162 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
7163 ConsArrayT->getSize(),
7164 SemaRef.Context.getSizeType(),
7165 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007166 AllocType = ConsArrayT->getElementType();
7167 } else if (const DependentSizedArrayType *DepArrayT
7168 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
7169 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00007170 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00007171 AllocType = DepArrayT->getElementType();
7172 }
7173 }
7174 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007175
Douglas Gregorb98b1992009-08-11 05:31:07 +00007176 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
7177 E->isGlobalNew(),
7178 /*FIXME:*/E->getLocStart(),
7179 move_arg(PlacementArgs),
7180 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00007181 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007182 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00007183 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00007184 ArraySize.get(),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007185 E->getConstructorLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007186 move_arg(ConstructorArgs),
Douglas Gregor4e8ea0b2011-10-18 02:43:19 +00007187 E->getConstructorRParen());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007188}
Mike Stump1eb44332009-09-09 15:08:12 +00007189
Douglas Gregorb98b1992009-08-11 05:31:07 +00007190template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007191ExprResult
John McCall454feb92009-12-08 09:21:05 +00007192TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007193 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007194 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007195 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007196
Douglas Gregor1af74512010-02-26 00:38:10 +00007197 // Transform the delete operator, if known.
7198 FunctionDecl *OperatorDelete = 0;
7199 if (E->getOperatorDelete()) {
7200 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007201 getDerived().TransformDecl(E->getLocStart(),
7202 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00007203 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00007204 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00007205 }
Sean Huntc3021132010-05-05 15:23:54 +00007206
Douglas Gregorb98b1992009-08-11 05:31:07 +00007207 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00007208 Operand.get() == E->getArgument() &&
7209 OperatorDelete == E->getOperatorDelete()) {
7210 // Mark any declarations we need as referenced.
7211 // FIXME: instantiation-specific.
7212 if (OperatorDelete)
Eli Friedman5f2987c2012-02-02 03:46:19 +00007213 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007214
7215 if (!E->getArgument()->isTypeDependent()) {
7216 QualType Destroyed = SemaRef.Context.getBaseElementType(
7217 E->getDestroyedType());
7218 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7219 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Eli Friedman5f2987c2012-02-02 03:46:19 +00007220 SemaRef.MarkFunctionReferenced(E->getLocStart(),
7221 SemaRef.LookupDestructor(Record));
Douglas Gregor5833b0b2010-09-14 22:55:20 +00007222 }
7223 }
7224
John McCall3fa5cae2010-10-26 07:05:15 +00007225 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00007226 }
Mike Stump1eb44332009-09-09 15:08:12 +00007227
Douglas Gregorb98b1992009-08-11 05:31:07 +00007228 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7229 E->isGlobalDelete(),
7230 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00007231 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007232}
Mike Stump1eb44332009-09-09 15:08:12 +00007233
Douglas Gregorb98b1992009-08-11 05:31:07 +00007234template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007235ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00007236TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00007237 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00007238 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00007239 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007240 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007241
John McCallb3d87482010-08-24 05:47:05 +00007242 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007243 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007244 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007245 E->getOperatorLoc(),
7246 E->isArrow()? tok::arrow : tok::period,
7247 ObjectTypePtr,
7248 MayBePseudoDestructor);
7249 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007250 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007251
John McCallb3d87482010-08-24 05:47:05 +00007252 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007253 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7254 if (QualifierLoc) {
7255 QualifierLoc
7256 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7257 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007258 return ExprError();
7259 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007260 CXXScopeSpec SS;
7261 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007262
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007263 PseudoDestructorTypeStorage Destroyed;
7264 if (E->getDestroyedTypeInfo()) {
7265 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007266 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007267 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007268 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007269 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007270 Destroyed = DestroyedTypeInfo;
Douglas Gregor6b18e742011-11-09 02:19:47 +00007271 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007272 // We aren't likely to be able to resolve the identifier down to a type
7273 // now anyway, so just retain the identifier.
7274 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7275 E->getDestroyedTypeLoc());
7276 } else {
7277 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007278 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007279 *E->getDestroyedTypeIdentifier(),
7280 E->getDestroyedTypeLoc(),
7281 /*Scope=*/0,
7282 SS, ObjectTypePtr,
7283 false);
7284 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007285 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007286
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007287 Destroyed
7288 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7289 E->getDestroyedTypeLoc());
7290 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007291
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007292 TypeSourceInfo *ScopeTypeInfo = 0;
7293 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007294 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007295 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007296 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007297 }
Sean Huntc3021132010-05-05 15:23:54 +00007298
John McCall9ae2f072010-08-23 23:25:46 +00007299 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007300 E->getOperatorLoc(),
7301 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007302 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007303 ScopeTypeInfo,
7304 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007305 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007306 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007307}
Mike Stump1eb44332009-09-09 15:08:12 +00007308
Douglas Gregora71d8192009-09-04 17:36:40 +00007309template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007310ExprResult
John McCallba135432009-11-21 08:51:07 +00007311TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007312 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007313 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7314 Sema::LookupOrdinaryName);
7315
7316 // Transform all the decls.
7317 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7318 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007319 NamedDecl *InstD = static_cast<NamedDecl*>(
7320 getDerived().TransformDecl(Old->getNameLoc(),
7321 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007322 if (!InstD) {
7323 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7324 // This can happen because of dependent hiding.
7325 if (isa<UsingShadowDecl>(*I))
7326 continue;
7327 else
John McCallf312b1e2010-08-26 23:41:50 +00007328 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007329 }
John McCallf7a1a742009-11-24 19:00:30 +00007330
7331 // Expand using declarations.
7332 if (isa<UsingDecl>(InstD)) {
7333 UsingDecl *UD = cast<UsingDecl>(InstD);
7334 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7335 E = UD->shadow_end(); I != E; ++I)
7336 R.addDecl(*I);
7337 continue;
7338 }
7339
7340 R.addDecl(InstD);
7341 }
7342
7343 // Resolve a kind, but don't do any further analysis. If it's
7344 // ambiguous, the callee needs to deal with it.
7345 R.resolveKind();
7346
7347 // Rebuild the nested-name qualifier, if present.
7348 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007349 if (Old->getQualifierLoc()) {
7350 NestedNameSpecifierLoc QualifierLoc
7351 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7352 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007353 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007354
Douglas Gregor4c9be892011-02-28 20:01:57 +00007355 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007356 }
7357
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007358 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007359 CXXRecordDecl *NamingClass
7360 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7361 Old->getNameLoc(),
7362 Old->getNamingClass()));
7363 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007364 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007365
Douglas Gregor66c45152010-04-27 16:10:10 +00007366 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007367 }
7368
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007369 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7370
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007371 // If we have neither explicit template arguments, nor the template keyword,
7372 // it's a normal declaration name.
7373 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCallf7a1a742009-11-24 19:00:30 +00007374 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7375
7376 // If we have template arguments, rebuild them, then rebuild the
7377 // templateid expression.
7378 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007379 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7380 Old->getNumTemplateArgs(),
7381 TransArgs))
7382 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007383
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007384 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara9d9922a2012-02-06 14:31:00 +00007385 Old->requiresADL(), &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007386}
Mike Stump1eb44332009-09-09 15:08:12 +00007387
Douglas Gregorb98b1992009-08-11 05:31:07 +00007388template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007389ExprResult
John McCall454feb92009-12-08 09:21:05 +00007390TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007391 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7392 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007393 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007394
Douglas Gregorb98b1992009-08-11 05:31:07 +00007395 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007396 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007397 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007398
Mike Stump1eb44332009-09-09 15:08:12 +00007399 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007400 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007401 T,
7402 E->getLocEnd());
7403}
Mike Stump1eb44332009-09-09 15:08:12 +00007404
Douglas Gregorb98b1992009-08-11 05:31:07 +00007405template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007406ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007407TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7408 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7409 if (!LhsT)
7410 return ExprError();
7411
7412 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7413 if (!RhsT)
7414 return ExprError();
7415
7416 if (!getDerived().AlwaysRebuild() &&
7417 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7418 return SemaRef.Owned(E);
7419
7420 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7421 E->getLocStart(),
7422 LhsT, RhsT,
7423 E->getLocEnd());
7424}
7425
7426template<typename Derived>
7427ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007428TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7429 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7430 if (!T)
7431 return ExprError();
7432
7433 if (!getDerived().AlwaysRebuild() &&
7434 T == E->getQueriedTypeSourceInfo())
7435 return SemaRef.Owned(E);
7436
7437 ExprResult SubExpr;
7438 {
7439 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7440 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7441 if (SubExpr.isInvalid())
7442 return ExprError();
7443
7444 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7445 return SemaRef.Owned(E);
7446 }
7447
7448 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7449 E->getLocStart(),
7450 T,
7451 SubExpr.get(),
7452 E->getLocEnd());
7453}
7454
7455template<typename Derived>
7456ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007457TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7458 ExprResult SubExpr;
7459 {
7460 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7461 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7462 if (SubExpr.isInvalid())
7463 return ExprError();
7464
7465 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7466 return SemaRef.Owned(E);
7467 }
7468
7469 return getDerived().RebuildExpressionTrait(
7470 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7471}
7472
7473template<typename Derived>
7474ExprResult
John McCall865d4472009-11-19 22:55:06 +00007475TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007476 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007477 NestedNameSpecifierLoc QualifierLoc
7478 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7479 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007480 return ExprError();
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007481 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump1eb44332009-09-09 15:08:12 +00007482
John McCall43fed0d2010-11-12 08:19:04 +00007483 // TODO: If this is a conversion-function-id, verify that the
7484 // destination type name (if present) resolves the same way after
7485 // instantiation as it did in the local scope.
7486
Abramo Bagnara25777432010-08-11 22:01:17 +00007487 DeclarationNameInfo NameInfo
7488 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7489 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007490 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007491
John McCallf7a1a742009-11-24 19:00:30 +00007492 if (!E->hasExplicitTemplateArgs()) {
7493 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007494 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007495 // Note: it is sufficient to compare the Name component of NameInfo:
7496 // if name has not changed, DNLoc has not changed either.
7497 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007498 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007499
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007500 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007501 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007502 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007503 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007504 }
John McCalld5532b62009-11-23 01:53:49 +00007505
7506 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007507 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7508 E->getNumTemplateArgs(),
7509 TransArgs))
7510 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007511
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007512 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007513 TemplateKWLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007514 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007515 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007516}
7517
7518template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007519ExprResult
John McCall454feb92009-12-08 09:21:05 +00007520TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007521 // CXXConstructExprs are always implicit, so when we have a
7522 // 1-argument construction we just transform that argument.
7523 if (E->getNumArgs() == 1 ||
7524 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7525 return getDerived().TransformExpr(E->getArg(0));
7526
Douglas Gregorb98b1992009-08-11 05:31:07 +00007527 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7528
7529 QualType T = getDerived().TransformType(E->getType());
7530 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007531 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007532
7533 CXXConstructorDecl *Constructor
7534 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007535 getDerived().TransformDecl(E->getLocStart(),
7536 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007537 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007538 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007539
Douglas Gregorb98b1992009-08-11 05:31:07 +00007540 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007541 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007542 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7543 &ArgumentChanged))
7544 return ExprError();
7545
Douglas Gregorb98b1992009-08-11 05:31:07 +00007546 if (!getDerived().AlwaysRebuild() &&
7547 T == E->getType() &&
7548 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007549 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007550 // Mark the constructor as referenced.
7551 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007552 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007553 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007554 }
Mike Stump1eb44332009-09-09 15:08:12 +00007555
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007556 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7557 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007558 move_arg(Args),
Abramo Bagnara7cc58b42011-10-05 07:56:41 +00007559 E->hadMultipleCandidates(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007560 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007561 E->getConstructionKind(),
7562 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007563}
Mike Stump1eb44332009-09-09 15:08:12 +00007564
Douglas Gregorb98b1992009-08-11 05:31:07 +00007565/// \brief Transform a C++ temporary-binding expression.
7566///
Douglas Gregor51326552009-12-24 18:51:59 +00007567/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7568/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007569template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007570ExprResult
John McCall454feb92009-12-08 09:21:05 +00007571TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007572 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007573}
Mike Stump1eb44332009-09-09 15:08:12 +00007574
John McCall4765fa02010-12-06 08:20:24 +00007575/// \brief Transform a C++ expression that contains cleanups that should
7576/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007577///
John McCall4765fa02010-12-06 08:20:24 +00007578/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007579/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007580template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007581ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007582TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007583 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007584}
Mike Stump1eb44332009-09-09 15:08:12 +00007585
Douglas Gregorb98b1992009-08-11 05:31:07 +00007586template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007587ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007588TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007589 CXXTemporaryObjectExpr *E) {
7590 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7591 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007592 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007593
Douglas Gregorb98b1992009-08-11 05:31:07 +00007594 CXXConstructorDecl *Constructor
7595 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007596 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007597 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007598 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007599 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007600
Douglas Gregorb98b1992009-08-11 05:31:07 +00007601 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007602 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007603 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007604 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7605 &ArgumentChanged))
7606 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007607
Douglas Gregorb98b1992009-08-11 05:31:07 +00007608 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007609 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007610 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007611 !ArgumentChanged) {
7612 // FIXME: Instantiation-specific
Eli Friedman5f2987c2012-02-02 03:46:19 +00007613 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007614 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007615 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007616
7617 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7618 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007619 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007620 E->getLocEnd());
7621}
Mike Stump1eb44332009-09-09 15:08:12 +00007622
Douglas Gregorb98b1992009-08-11 05:31:07 +00007623template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007624ExprResult
Douglas Gregor01d08012012-02-07 10:09:13 +00007625TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
7626 assert(false && "Lambda expressions cannot be instantiated (yet)");
7627 return ExprError();
7628}
7629
7630template<typename Derived>
7631ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007632TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007633 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007634 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7635 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007636 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007637
Douglas Gregorb98b1992009-08-11 05:31:07 +00007638 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007639 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007640 Args.reserve(E->arg_size());
7641 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7642 &ArgumentChanged))
7643 return ExprError();
7644
Douglas Gregorb98b1992009-08-11 05:31:07 +00007645 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007646 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007647 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007648 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007649
Douglas Gregorb98b1992009-08-11 05:31:07 +00007650 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007651 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007652 E->getLParenLoc(),
7653 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007654 E->getRParenLoc());
7655}
Mike Stump1eb44332009-09-09 15:08:12 +00007656
Douglas Gregorb98b1992009-08-11 05:31:07 +00007657template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007658ExprResult
John McCall865d4472009-11-19 22:55:06 +00007659TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007660 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007661 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007662 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007663 Expr *OldBase;
7664 QualType BaseType;
7665 QualType ObjectType;
7666 if (!E->isImplicitAccess()) {
7667 OldBase = E->getBase();
7668 Base = getDerived().TransformExpr(OldBase);
7669 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007670 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007671
John McCallaa81e162009-12-01 22:10:20 +00007672 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007673 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007674 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007675 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007676 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007677 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007678 ObjectTy,
7679 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007680 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007681 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007682
John McCallb3d87482010-08-24 05:47:05 +00007683 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007684 BaseType = ((Expr*) Base.get())->getType();
7685 } else {
7686 OldBase = 0;
7687 BaseType = getDerived().TransformType(E->getBaseType());
7688 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7689 }
Mike Stump1eb44332009-09-09 15:08:12 +00007690
Douglas Gregor6cd21982009-10-20 05:58:46 +00007691 // Transform the first part of the nested-name-specifier that qualifies
7692 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007693 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007694 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007695 E->getFirstQualifierFoundInScope(),
7696 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007697
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007698 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007699 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007700 QualifierLoc
7701 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7702 ObjectType,
7703 FirstQualifierInScope);
7704 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007705 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007706 }
Mike Stump1eb44332009-09-09 15:08:12 +00007707
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007708 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
7709
John McCall43fed0d2010-11-12 08:19:04 +00007710 // TODO: If this is a conversion-function-id, verify that the
7711 // destination type name (if present) resolves the same way after
7712 // instantiation as it did in the local scope.
7713
Abramo Bagnara25777432010-08-11 22:01:17 +00007714 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007715 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007716 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007717 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007718
John McCallaa81e162009-12-01 22:10:20 +00007719 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007720 // This is a reference to a member without an explicitly-specified
7721 // template argument list. Optimize for this common case.
7722 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007723 Base.get() == OldBase &&
7724 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007725 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007726 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007727 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007728 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007729
John McCall9ae2f072010-08-23 23:25:46 +00007730 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007731 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007732 E->isArrow(),
7733 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007734 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007735 TemplateKWLoc,
John McCall129e2df2009-11-30 22:42:35 +00007736 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007737 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007738 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007739 }
7740
John McCalld5532b62009-11-23 01:53:49 +00007741 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007742 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7743 E->getNumTemplateArgs(),
7744 TransArgs))
7745 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007746
John McCall9ae2f072010-08-23 23:25:46 +00007747 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007748 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007749 E->isArrow(),
7750 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007751 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007752 TemplateKWLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007753 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007754 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007755 &TransArgs);
7756}
7757
7758template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007759ExprResult
John McCall454feb92009-12-08 09:21:05 +00007760TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007761 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007762 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007763 QualType BaseType;
7764 if (!Old->isImplicitAccess()) {
7765 Base = getDerived().TransformExpr(Old->getBase());
7766 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007767 return ExprError();
Richard Smith9138b4e2011-10-26 19:06:56 +00007768 Base = getSema().PerformMemberExprBaseConversion(Base.take(),
7769 Old->isArrow());
7770 if (Base.isInvalid())
7771 return ExprError();
7772 BaseType = Base.get()->getType();
John McCallaa81e162009-12-01 22:10:20 +00007773 } else {
7774 BaseType = getDerived().TransformType(Old->getBaseType());
7775 }
John McCall129e2df2009-11-30 22:42:35 +00007776
Douglas Gregor4c9be892011-02-28 20:01:57 +00007777 NestedNameSpecifierLoc QualifierLoc;
7778 if (Old->getQualifierLoc()) {
7779 QualifierLoc
7780 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7781 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007782 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007783 }
7784
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007785 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
7786
Abramo Bagnara25777432010-08-11 22:01:17 +00007787 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007788 Sema::LookupOrdinaryName);
7789
7790 // Transform all the decls.
7791 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7792 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007793 NamedDecl *InstD = static_cast<NamedDecl*>(
7794 getDerived().TransformDecl(Old->getMemberLoc(),
7795 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007796 if (!InstD) {
7797 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7798 // This can happen because of dependent hiding.
7799 if (isa<UsingShadowDecl>(*I))
7800 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007801 else {
7802 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007803 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007804 }
John McCall9f54ad42009-12-10 09:41:52 +00007805 }
John McCall129e2df2009-11-30 22:42:35 +00007806
7807 // Expand using declarations.
7808 if (isa<UsingDecl>(InstD)) {
7809 UsingDecl *UD = cast<UsingDecl>(InstD);
7810 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7811 E = UD->shadow_end(); I != E; ++I)
7812 R.addDecl(*I);
7813 continue;
7814 }
7815
7816 R.addDecl(InstD);
7817 }
7818
7819 R.resolveKind();
7820
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007821 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007822 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007823 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007824 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007825 Old->getMemberLoc(),
7826 Old->getNamingClass()));
7827 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007828 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007829
Douglas Gregor66c45152010-04-27 16:10:10 +00007830 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007831 }
Sean Huntc3021132010-05-05 15:23:54 +00007832
John McCall129e2df2009-11-30 22:42:35 +00007833 TemplateArgumentListInfo TransArgs;
7834 if (Old->hasExplicitTemplateArgs()) {
7835 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7836 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007837 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7838 Old->getNumTemplateArgs(),
7839 TransArgs))
7840 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007841 }
John McCallc2233c52010-01-15 08:34:02 +00007842
7843 // FIXME: to do this check properly, we will need to preserve the
7844 // first-qualifier-in-scope here, just in case we had a dependent
7845 // base (and therefore couldn't do the check) and a
7846 // nested-name-qualifier (and therefore could do the lookup).
7847 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007848
John McCall9ae2f072010-08-23 23:25:46 +00007849 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007850 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007851 Old->getOperatorLoc(),
7852 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007853 QualifierLoc,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00007854 TemplateKWLoc,
John McCallc2233c52010-01-15 08:34:02 +00007855 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007856 R,
7857 (Old->hasExplicitTemplateArgs()
7858 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007859}
7860
7861template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007862ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007863TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00007864 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00007865 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7866 if (SubExpr.isInvalid())
7867 return ExprError();
7868
7869 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007870 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007871
7872 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7873}
7874
7875template<typename Derived>
7876ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007877TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007878 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7879 if (Pattern.isInvalid())
7880 return ExprError();
7881
7882 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7883 return SemaRef.Owned(E);
7884
Douglas Gregor67fd1252011-01-14 21:20:45 +00007885 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7886 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007887}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007888
7889template<typename Derived>
7890ExprResult
7891TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7892 // If E is not value-dependent, then nothing will change when we transform it.
7893 // Note: This is an instantiation-centric view.
7894 if (!E->isValueDependent())
7895 return SemaRef.Owned(E);
7896
7897 // Note: None of the implementations of TryExpandParameterPacks can ever
7898 // produce a diagnostic when given only a single unexpanded parameter pack,
7899 // so
7900 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7901 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007902 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007903 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007904 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikiea71f9d02011-09-22 02:34:54 +00007905 Unexpanded,
Douglas Gregord3731192011-01-10 07:32:04 +00007906 ShouldExpand, RetainExpansion,
7907 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007908 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007909
Douglas Gregor089e8932011-10-10 18:59:29 +00007910 if (RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007911 return SemaRef.Owned(E);
Douglas Gregor089e8932011-10-10 18:59:29 +00007912
7913 NamedDecl *Pack = E->getPack();
7914 if (!ShouldExpand) {
7915 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
7916 Pack));
7917 if (!Pack)
7918 return ExprError();
7919 }
7920
Douglas Gregoree8aff02011-01-04 17:33:58 +00007921
7922 // We now know the length of the parameter pack, so build a new expression
7923 // that stores that length.
Douglas Gregor089e8932011-10-10 18:59:29 +00007924 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
Douglas Gregoree8aff02011-01-04 17:33:58 +00007925 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor089e8932011-10-10 18:59:29 +00007926 NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007927}
7928
Douglas Gregorbe230c32011-01-03 17:17:50 +00007929template<typename Derived>
7930ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007931TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7932 SubstNonTypeTemplateParmPackExpr *E) {
7933 // Default behavior is to do nothing with this transformation.
7934 return SemaRef.Owned(E);
7935}
7936
7937template<typename Derived>
7938ExprResult
John McCall91a57552011-07-15 05:09:51 +00007939TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7940 SubstNonTypeTemplateParmExpr *E) {
7941 // Default behavior is to do nothing with this transformation.
7942 return SemaRef.Owned(E);
7943}
7944
7945template<typename Derived>
7946ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00007947TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7948 MaterializeTemporaryExpr *E) {
7949 return getDerived().TransformExpr(E->GetTemporaryExpr());
7950}
7951
7952template<typename Derived>
7953ExprResult
John McCall454feb92009-12-08 09:21:05 +00007954TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007955 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007956}
7957
Mike Stump1eb44332009-09-09 15:08:12 +00007958template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007959ExprResult
John McCall454feb92009-12-08 09:21:05 +00007960TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007961 TypeSourceInfo *EncodedTypeInfo
7962 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7963 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007964 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007965
Douglas Gregorb98b1992009-08-11 05:31:07 +00007966 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007967 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007968 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007969
7970 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007971 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007972 E->getRParenLoc());
7973}
Mike Stump1eb44332009-09-09 15:08:12 +00007974
Douglas Gregorb98b1992009-08-11 05:31:07 +00007975template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00007976ExprResult TreeTransform<Derived>::
7977TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7978 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7979 if (result.isInvalid()) return ExprError();
7980 Expr *subExpr = result.take();
7981
7982 if (!getDerived().AlwaysRebuild() &&
7983 subExpr == E->getSubExpr())
7984 return SemaRef.Owned(E);
7985
7986 return SemaRef.Owned(new(SemaRef.Context)
7987 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7988}
7989
7990template<typename Derived>
7991ExprResult TreeTransform<Derived>::
7992TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7993 TypeSourceInfo *TSInfo
7994 = getDerived().TransformType(E->getTypeInfoAsWritten());
7995 if (!TSInfo)
7996 return ExprError();
7997
7998 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7999 if (Result.isInvalid())
8000 return ExprError();
8001
8002 if (!getDerived().AlwaysRebuild() &&
8003 TSInfo == E->getTypeInfoAsWritten() &&
8004 Result.get() == E->getSubExpr())
8005 return SemaRef.Owned(E);
8006
8007 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
8008 E->getBridgeKeywordLoc(), TSInfo,
8009 Result.get());
8010}
8011
8012template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008013ExprResult
John McCall454feb92009-12-08 09:21:05 +00008014TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00008015 // Transform arguments.
8016 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008017 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008018 Args.reserve(E->getNumArgs());
8019 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
8020 &ArgChanged))
8021 return ExprError();
8022
Douglas Gregor92e986e2010-04-22 16:44:27 +00008023 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
8024 // Class message: transform the receiver type.
8025 TypeSourceInfo *ReceiverTypeInfo
8026 = getDerived().TransformType(E->getClassReceiverTypeInfo());
8027 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00008028 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008029
Douglas Gregor92e986e2010-04-22 16:44:27 +00008030 // If nothing changed, just retain the existing message send.
8031 if (!getDerived().AlwaysRebuild() &&
8032 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008033 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008034
8035 // Build a new class message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008036 SmallVector<SourceLocation, 16> SelLocs;
8037 E->getSelectorLocs(SelLocs);
Douglas Gregor92e986e2010-04-22 16:44:27 +00008038 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
8039 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008040 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008041 E->getMethodDecl(),
8042 E->getLeftLoc(),
8043 move_arg(Args),
8044 E->getRightLoc());
8045 }
8046
8047 // Instance message: transform the receiver
8048 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
8049 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00008050 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00008051 = getDerived().TransformExpr(E->getInstanceReceiver());
8052 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008053 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00008054
8055 // If nothing changed, just retain the existing message send.
8056 if (!getDerived().AlwaysRebuild() &&
8057 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregor92be2a52011-12-10 00:23:21 +00008058 return SemaRef.MaybeBindToTemporary(E);
Sean Huntc3021132010-05-05 15:23:54 +00008059
Douglas Gregor92e986e2010-04-22 16:44:27 +00008060 // Build a new instance message send.
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008061 SmallVector<SourceLocation, 16> SelLocs;
8062 E->getSelectorLocs(SelLocs);
John McCall9ae2f072010-08-23 23:25:46 +00008063 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00008064 E->getSelector(),
Argyrios Kyrtzidis20718082011-10-03 06:36:51 +00008065 SelLocs,
Douglas Gregor92e986e2010-04-22 16:44:27 +00008066 E->getMethodDecl(),
8067 E->getLeftLoc(),
8068 move_arg(Args),
8069 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008070}
8071
Mike Stump1eb44332009-09-09 15:08:12 +00008072template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008073ExprResult
John McCall454feb92009-12-08 09:21:05 +00008074TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008075 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008076}
8077
Mike Stump1eb44332009-09-09 15:08:12 +00008078template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008079ExprResult
John McCall454feb92009-12-08 09:21:05 +00008080TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00008081 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008082}
8083
Mike Stump1eb44332009-09-09 15:08:12 +00008084template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008085ExprResult
John McCall454feb92009-12-08 09:21:05 +00008086TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008087 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008088 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008089 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008090 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008091
8092 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008093
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008094 // If nothing changed, just retain the existing expression.
8095 if (!getDerived().AlwaysRebuild() &&
8096 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008097 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008098
John McCall9ae2f072010-08-23 23:25:46 +00008099 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008100 E->getLocation(),
8101 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008102}
8103
Mike Stump1eb44332009-09-09 15:08:12 +00008104template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008105ExprResult
John McCall454feb92009-12-08 09:21:05 +00008106TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00008107 // 'super' and types never change. Property never changes. Just
8108 // retain the existing expression.
8109 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00008110 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00008111
Douglas Gregore3303542010-04-26 20:47:02 +00008112 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008113 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00008114 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008115 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008116
Douglas Gregore3303542010-04-26 20:47:02 +00008117 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00008118
Douglas Gregore3303542010-04-26 20:47:02 +00008119 // If nothing changed, just retain the existing expression.
8120 if (!getDerived().AlwaysRebuild() &&
8121 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008122 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008123
John McCall12f78a62010-12-02 01:19:52 +00008124 if (E->isExplicitProperty())
8125 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
8126 E->getExplicitProperty(),
8127 E->getLocation());
8128
8129 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall3c3b7f92011-10-25 17:37:35 +00008130 SemaRef.Context.PseudoObjectTy,
John McCall12f78a62010-12-02 01:19:52 +00008131 E->getImplicitPropertyGetter(),
8132 E->getImplicitPropertySetter(),
8133 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008134}
8135
Mike Stump1eb44332009-09-09 15:08:12 +00008136template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008137ExprResult
John McCall454feb92009-12-08 09:21:05 +00008138TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008139 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00008140 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008141 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008142 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00008143
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008144 // If nothing changed, just retain the existing expression.
8145 if (!getDerived().AlwaysRebuild() &&
8146 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00008147 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00008148
John McCall9ae2f072010-08-23 23:25:46 +00008149 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00008150 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00008151}
8152
Mike Stump1eb44332009-09-09 15:08:12 +00008153template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008154ExprResult
John McCall454feb92009-12-08 09:21:05 +00008155TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008156 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00008157 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00008158 SubExprs.reserve(E->getNumSubExprs());
8159 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8160 SubExprs, &ArgumentChanged))
8161 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008162
Douglas Gregorb98b1992009-08-11 05:31:07 +00008163 if (!getDerived().AlwaysRebuild() &&
8164 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00008165 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00008166
Douglas Gregorb98b1992009-08-11 05:31:07 +00008167 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
8168 move_arg(SubExprs),
8169 E->getRParenLoc());
8170}
8171
Mike Stump1eb44332009-09-09 15:08:12 +00008172template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008173ExprResult
John McCall454feb92009-12-08 09:21:05 +00008174TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00008175 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008176
John McCallc6ac9c32011-02-04 18:33:18 +00008177 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
8178 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
8179
8180 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian05865202011-12-03 17:47:53 +00008181 blockScope->TheDecl->setBlockMissingReturnType(
8182 oldBlock->blockMissingReturnType());
Fariborz Jahanianff365592011-05-05 17:18:12 +00008183
Chris Lattner686775d2011-07-20 06:58:45 +00008184 SmallVector<ParmVarDecl*, 4> params;
8185 SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008186
8187 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00008188 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
8189 oldBlock->param_begin(),
8190 oldBlock->param_size(),
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008191 0, paramTypes, &params)) {
8192 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregor92be2a52011-12-10 00:23:21 +00008193 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008194 }
John McCallc6ac9c32011-02-04 18:33:18 +00008195
8196 const FunctionType *exprFunctionType = E->getFunctionType();
Eli Friedman84b007f2012-01-26 03:00:14 +00008197 QualType exprResultType =
8198 getDerived().TransformType(exprFunctionType->getResultType());
Douglas Gregora779d9c2011-01-19 21:32:01 +00008199
8200 // Don't allow returning a objc interface by value.
Eli Friedman84b007f2012-01-26 03:00:14 +00008201 if (exprResultType->isObjCObjectType()) {
John McCallc6ac9c32011-02-04 18:33:18 +00008202 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00008203 diag::err_object_cannot_be_passed_returned_by_value)
Eli Friedman84b007f2012-01-26 03:00:14 +00008204 << 0 << exprResultType;
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008205 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
Douglas Gregora779d9c2011-01-19 21:32:01 +00008206 return ExprError();
8207 }
John McCall711c52b2011-01-05 12:14:39 +00008208
John McCallc6ac9c32011-02-04 18:33:18 +00008209 QualType functionType = getDerived().RebuildFunctionProtoType(
Eli Friedman84b007f2012-01-26 03:00:14 +00008210 exprResultType,
John McCallc6ac9c32011-02-04 18:33:18 +00008211 paramTypes.data(),
8212 paramTypes.size(),
8213 oldBlock->isVariadic(),
Richard Smitheefb3d52012-02-10 09:58:53 +00008214 false, 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00008215 exprFunctionType->getExtInfo());
8216 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00008217
8218 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00008219 if (!params.empty())
David Blaikie4278c652011-09-21 18:16:56 +00008220 blockScope->TheDecl->setParams(params);
Eli Friedman84b007f2012-01-26 03:00:14 +00008221
8222 if (!oldBlock->blockMissingReturnType()) {
8223 blockScope->HasImplicitReturnType = false;
8224 blockScope->ReturnType = exprResultType;
8225 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00008226
John McCall711c52b2011-01-05 12:14:39 +00008227 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00008228 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008229 if (body.isInvalid()) {
8230 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0);
John McCall711c52b2011-01-05 12:14:39 +00008231 return ExprError();
Argyrios Kyrtzidis00b46572012-01-25 03:53:04 +00008232 }
John McCall711c52b2011-01-05 12:14:39 +00008233
John McCallc6ac9c32011-02-04 18:33:18 +00008234#ifndef NDEBUG
8235 // In builds with assertions, make sure that we captured everything we
8236 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00008237 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8238 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8239 e = oldBlock->capture_end(); i != e; ++i) {
8240 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00008241
Douglas Gregorfc921372011-05-20 15:32:55 +00008242 // Ignore parameter packs.
8243 if (isa<ParmVarDecl>(oldCapture) &&
8244 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8245 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00008246
Douglas Gregorfc921372011-05-20 15:32:55 +00008247 VarDecl *newCapture =
8248 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8249 oldCapture));
8250 assert(blockScope->CaptureMap.count(newCapture));
8251 }
John McCallc6ac9c32011-02-04 18:33:18 +00008252 }
8253#endif
8254
8255 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8256 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008257}
8258
Mike Stump1eb44332009-09-09 15:08:12 +00008259template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008260ExprResult
John McCall454feb92009-12-08 09:21:05 +00008261TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008262 ValueDecl *ND
8263 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8264 E->getDecl()));
8265 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00008266 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00008267
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008268 if (!getDerived().AlwaysRebuild() &&
8269 ND == E->getDecl()) {
8270 // Mark it referenced in the new context regardless.
8271 // FIXME: this is a bit instantiation-specific.
Eli Friedman5f2987c2012-02-02 03:46:19 +00008272 SemaRef.MarkBlockDeclRefReferenced(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008273
John McCall3fa5cae2010-10-26 07:05:15 +00008274 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00008275 }
8276
Abramo Bagnara25777432010-08-11 22:01:17 +00008277 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00008278 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00008279 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008280}
Mike Stump1eb44332009-09-09 15:08:12 +00008281
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008282template<typename Derived>
8283ExprResult
8284TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikieb219cfc2011-09-23 05:06:16 +00008285 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008286}
Eli Friedman276b0612011-10-11 02:20:01 +00008287
8288template<typename Derived>
8289ExprResult
8290TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedmandfa64ba2011-10-14 22:48:56 +00008291 QualType RetTy = getDerived().TransformType(E->getType());
8292 bool ArgumentChanged = false;
8293 ASTOwningVector<Expr*> SubExprs(SemaRef);
8294 SubExprs.reserve(E->getNumSubExprs());
8295 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
8296 SubExprs, &ArgumentChanged))
8297 return ExprError();
8298
8299 if (!getDerived().AlwaysRebuild() &&
8300 !ArgumentChanged)
8301 return SemaRef.Owned(E);
8302
8303 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs),
8304 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedman276b0612011-10-11 02:20:01 +00008305}
Tanya Lattner61eee0c2011-06-04 00:47:47 +00008306
Douglas Gregorb98b1992009-08-11 05:31:07 +00008307//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008308// Type reconstruction
8309//===----------------------------------------------------------------------===//
8310
Mike Stump1eb44332009-09-09 15:08:12 +00008311template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008312QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8313 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008314 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008315 getDerived().getBaseEntity());
8316}
8317
Mike Stump1eb44332009-09-09 15:08:12 +00008318template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008319QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8320 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008321 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008322 getDerived().getBaseEntity());
8323}
8324
Mike Stump1eb44332009-09-09 15:08:12 +00008325template<typename Derived>
8326QualType
John McCall85737a72009-10-30 00:06:24 +00008327TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8328 bool WrittenAsLValue,
8329 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008330 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008331 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008332}
8333
8334template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008335QualType
John McCall85737a72009-10-30 00:06:24 +00008336TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8337 QualType ClassType,
8338 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008339 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008340 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008341}
8342
8343template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008344QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008345TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8346 ArrayType::ArraySizeModifier SizeMod,
8347 const llvm::APInt *Size,
8348 Expr *SizeExpr,
8349 unsigned IndexTypeQuals,
8350 SourceRange BracketsRange) {
8351 if (SizeExpr || !Size)
8352 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8353 IndexTypeQuals, BracketsRange,
8354 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008355
8356 QualType Types[] = {
8357 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8358 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8359 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008360 };
8361 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8362 QualType SizeType;
8363 for (unsigned I = 0; I != NumTypes; ++I)
8364 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8365 SizeType = Types[I];
8366 break;
8367 }
Mike Stump1eb44332009-09-09 15:08:12 +00008368
Eli Friedman01f276d2012-01-25 23:20:27 +00008369 // Note that we can return a VariableArrayType here in the case where
8370 // the element type was a dependent VariableArrayType.
8371 IntegerLiteral *ArraySize
8372 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
8373 /*FIXME*/BracketsRange.getBegin());
8374 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008375 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008376 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008377}
Mike Stump1eb44332009-09-09 15:08:12 +00008378
Douglas Gregor577f75a2009-08-04 16:50:30 +00008379template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008380QualType
8381TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008382 ArrayType::ArraySizeModifier SizeMod,
8383 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008384 unsigned IndexTypeQuals,
8385 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008386 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008387 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008388}
8389
8390template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008391QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008392TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008393 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008394 unsigned IndexTypeQuals,
8395 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008396 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008397 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008398}
Mike Stump1eb44332009-09-09 15:08:12 +00008399
Douglas Gregor577f75a2009-08-04 16:50:30 +00008400template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008401QualType
8402TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008403 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008404 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008405 unsigned IndexTypeQuals,
8406 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008407 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008408 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008409 IndexTypeQuals, BracketsRange);
8410}
8411
8412template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008413QualType
8414TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008415 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008416 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008417 unsigned IndexTypeQuals,
8418 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008419 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008420 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008421 IndexTypeQuals, BracketsRange);
8422}
8423
8424template<typename Derived>
8425QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008426 unsigned NumElements,
8427 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008428 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008429 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008430}
Mike Stump1eb44332009-09-09 15:08:12 +00008431
Douglas Gregor577f75a2009-08-04 16:50:30 +00008432template<typename Derived>
8433QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8434 unsigned NumElements,
8435 SourceLocation AttributeLoc) {
8436 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8437 NumElements, true);
8438 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008439 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8440 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008441 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008442}
Mike Stump1eb44332009-09-09 15:08:12 +00008443
Douglas Gregor577f75a2009-08-04 16:50:30 +00008444template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008445QualType
8446TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008447 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008448 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008449 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008450}
Mike Stump1eb44332009-09-09 15:08:12 +00008451
Douglas Gregor577f75a2009-08-04 16:50:30 +00008452template<typename Derived>
8453QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008454 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008455 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008456 bool Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008457 bool HasTrailingReturn,
Eli Friedmanfa869542010-08-05 02:54:05 +00008458 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008459 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008460 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008461 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Richard Smitheefb3d52012-02-10 09:58:53 +00008462 HasTrailingReturn, Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008463 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008464 getDerived().getBaseEntity(),
8465 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008466}
Mike Stump1eb44332009-09-09 15:08:12 +00008467
Douglas Gregor577f75a2009-08-04 16:50:30 +00008468template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008469QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8470 return SemaRef.Context.getFunctionNoProtoType(T);
8471}
8472
8473template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008474QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8475 assert(D && "no decl found");
8476 if (D->isInvalidDecl()) return QualType();
8477
Douglas Gregor92e986e2010-04-22 16:44:27 +00008478 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008479 TypeDecl *Ty;
8480 if (isa<UsingDecl>(D)) {
8481 UsingDecl *Using = cast<UsingDecl>(D);
8482 assert(Using->isTypeName() &&
8483 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8484
8485 // A valid resolved using typename decl points to exactly one type decl.
8486 assert(++Using->shadow_begin() == Using->shadow_end());
8487 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008488
John McCalled976492009-12-04 22:46:56 +00008489 } else {
8490 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8491 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8492 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8493 }
8494
8495 return SemaRef.Context.getTypeDeclType(Ty);
8496}
8497
8498template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008499QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8500 SourceLocation Loc) {
8501 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008502}
8503
8504template<typename Derived>
8505QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8506 return SemaRef.Context.getTypeOfType(Underlying);
8507}
8508
8509template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008510QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8511 SourceLocation Loc) {
8512 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008513}
8514
8515template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008516QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8517 UnaryTransformType::UTTKind UKind,
8518 SourceLocation Loc) {
8519 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8520}
8521
8522template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008523QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008524 TemplateName Template,
8525 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008526 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008527 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008528}
Mike Stump1eb44332009-09-09 15:08:12 +00008529
Douglas Gregordcee1a12009-08-06 05:28:30 +00008530template<typename Derived>
Eli Friedmanb001de72011-10-06 23:00:33 +00008531QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
8532 SourceLocation KWLoc) {
8533 return SemaRef.BuildAtomicType(ValueType, KWLoc);
8534}
8535
8536template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008537TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008538TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008539 bool TemplateKW,
8540 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008541 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008542 Template);
8543}
8544
8545template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008546TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008547TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8548 const IdentifierInfo &Name,
8549 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008550 QualType ObjectType,
8551 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008552 UnqualifiedId TemplateName;
8553 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008554 Sema::TemplateTy Template;
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008555 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00008556 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008557 SS, TemplateKWLoc, TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008558 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008559 /*EnteringContext=*/false,
8560 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008561 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008562}
Mike Stump1eb44332009-09-09 15:08:12 +00008563
Douglas Gregorb98b1992009-08-11 05:31:07 +00008564template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008565TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008566TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008567 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008568 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008569 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008570 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008571 // FIXME: Bogus location information.
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008572 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008573 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008574 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregord6ab2322010-06-16 23:00:59 +00008575 Sema::TemplateTy Template;
8576 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008577 SS, TemplateKWLoc, Name,
John McCallb3d87482010-08-24 05:47:05 +00008578 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008579 /*EnteringContext=*/false,
8580 Template);
8581 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008582}
Sean Huntc3021132010-05-05 15:23:54 +00008583
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008584template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008585ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008586TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8587 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008588 Expr *OrigCallee,
8589 Expr *First,
8590 Expr *Second) {
8591 Expr *Callee = OrigCallee->IgnoreParenCasts();
8592 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008593
Douglas Gregorb98b1992009-08-11 05:31:07 +00008594 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008595 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008596 if (!First->getType()->isOverloadableType() &&
8597 !Second->getType()->isOverloadableType())
8598 return getSema().CreateBuiltinArraySubscriptExpr(First,
8599 Callee->getLocStart(),
8600 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008601 } else if (Op == OO_Arrow) {
8602 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008603 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8604 } else if (Second == 0 || isPostIncDec) {
8605 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008606 // The argument is not of overloadable type, so try to create a
8607 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008608 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008609 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008610
John McCall9ae2f072010-08-23 23:25:46 +00008611 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008612 }
8613 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008614 if (!First->getType()->isOverloadableType() &&
8615 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008616 // Neither of the arguments is an overloadable type, so try to
8617 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008618 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008619 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008620 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008621 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008622 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008623
Douglas Gregorb98b1992009-08-11 05:31:07 +00008624 return move(Result);
8625 }
8626 }
Mike Stump1eb44332009-09-09 15:08:12 +00008627
8628 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008629 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008630 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008631
John McCall9ae2f072010-08-23 23:25:46 +00008632 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008633 assert(ULE->requiresADL());
8634
8635 // FIXME: Do we have to check
8636 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008637 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008638 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008639 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008640 }
Mike Stump1eb44332009-09-09 15:08:12 +00008641
Douglas Gregorb98b1992009-08-11 05:31:07 +00008642 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008643 Expr *Args[2] = { First, Second };
8644 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008645
Douglas Gregorb98b1992009-08-11 05:31:07 +00008646 // Create the overloaded operator invocation for unary operators.
8647 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008648 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008649 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008650 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008651 }
Mike Stump1eb44332009-09-09 15:08:12 +00008652
Douglas Gregor5b8968c2011-07-15 16:25:15 +00008653 if (Op == OO_Subscript) {
8654 SourceLocation LBrace;
8655 SourceLocation RBrace;
8656
8657 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8658 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8659 LBrace = SourceLocation::getFromRawEncoding(
8660 NameLoc.CXXOperatorName.BeginOpNameLoc);
8661 RBrace = SourceLocation::getFromRawEncoding(
8662 NameLoc.CXXOperatorName.EndOpNameLoc);
8663 } else {
8664 LBrace = Callee->getLocStart();
8665 RBrace = OpLoc;
8666 }
8667
8668 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8669 First, Second);
8670 }
Sebastian Redlf322ed62009-10-29 20:17:01 +00008671
Douglas Gregorb98b1992009-08-11 05:31:07 +00008672 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008673 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008674 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008675 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8676 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008677 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008678
Mike Stump1eb44332009-09-09 15:08:12 +00008679 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008680}
Mike Stump1eb44332009-09-09 15:08:12 +00008681
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008682template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008683ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008684TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008685 SourceLocation OperatorLoc,
8686 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008687 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008688 TypeSourceInfo *ScopeType,
8689 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008690 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008691 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008692 QualType BaseType = Base->getType();
8693 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008694 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008695 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008696 !BaseType->getAs<PointerType>()->getPointeeType()
8697 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008698 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008699 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008700 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008701 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008702 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008703 /*FIXME?*/true);
8704 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008705
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008706 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008707 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8708 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8709 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8710 NameInfo.setNamedTypeInfo(DestroyedType);
8711
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008712 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008713
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008714 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCall9ae2f072010-08-23 23:25:46 +00008715 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008716 OperatorLoc, isArrow,
Abramo Bagnarae4b92762012-01-27 09:46:47 +00008717 SS, TemplateKWLoc,
8718 /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008719 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008720 /*TemplateArgs*/ 0);
8721}
8722
Douglas Gregor577f75a2009-08-04 16:50:30 +00008723} // end namespace clang
8724
8725#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H