blob: 0d923d113a22214d6bbbd956dea837f36d78f89f [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"
John McCalla2becad2009-10-21 00:40:46 +000034#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000035#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000036#include <algorithm>
37
38namespace clang {
John McCall781472f2010-08-25 08:40:02 +000039using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000040
Douglas Gregor577f75a2009-08-04 16:50:30 +000041/// \brief A semantic tree transformation that allows one to transform one
42/// abstract syntax tree into another.
43///
Mike Stump1eb44332009-09-09 15:08:12 +000044/// A new tree transformation is defined by creating a new subclass \c X of
45/// \c TreeTransform<X> and then overriding certain operations to provide
46/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000047/// instantiation is implemented as a tree transformation where the
48/// transformation of TemplateTypeParmType nodes involves substituting the
49/// template arguments for their corresponding template parameters; a similar
50/// transformation is performed for non-type template parameters and
51/// template template parameters.
52///
53/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000054/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000055/// override any of the transformation or rebuild operators by providing an
56/// operation with the same signature as the default implementation. The
57/// overridding function should not be virtual.
58///
59/// Semantic tree transformations are split into two stages, either of which
60/// can be replaced by a subclass. The "transform" step transforms an AST node
61/// or the parts of an AST node using the various transformation functions,
62/// then passes the pieces on to the "rebuild" step, which constructs a new AST
63/// node of the appropriate kind from the pieces. The default transformation
64/// routines recursively transform the operands to composite AST nodes (e.g.,
65/// the pointee type of a PointerType node) and, if any of those operand nodes
66/// were changed by the transformation, invokes the rebuild operation to create
67/// a new AST node.
68///
Mike Stump1eb44332009-09-09 15:08:12 +000069/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000070/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor9151c112011-03-02 18:50:38 +000071/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000072/// TransformTemplateName(), or TransformTemplateArgument() with entirely
73/// new implementations.
74///
75/// For more fine-grained transformations, subclasses can replace any of the
76/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000077/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000078/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000079/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000080/// parameters. Additionally, subclasses can override the \c RebuildXXX
81/// functions to control how AST nodes are rebuilt when their operands change.
82/// By default, \c TreeTransform will invoke semantic analysis to rebuild
83/// AST nodes. However, certain other tree transformations (e.g, cloning) may
84/// be able to use more efficient rebuild steps.
85///
86/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000087/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000088/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
89/// operands have not changed (\c AlwaysRebuild()), and customize the
90/// default locations and entity names used for type-checking
91/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000092template<typename Derived>
93class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000094 /// \brief Private RAII object that helps us forget and then re-remember
95 /// the template argument corresponding to a partially-substituted parameter
96 /// pack.
97 class ForgetPartiallySubstitutedPackRAII {
98 Derived &Self;
99 TemplateArgument Old;
100
101 public:
102 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
103 Old = Self.ForgetPartiallySubstitutedPack();
104 }
105
106 ~ForgetPartiallySubstitutedPackRAII() {
107 Self.RememberPartiallySubstitutedPack(Old);
108 }
109 };
110
Douglas Gregor577f75a2009-08-04 16:50:30 +0000111protected:
112 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000113
Mike Stump1eb44332009-09-09 15:08:12 +0000114public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000115 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000116 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000117
Douglas Gregor577f75a2009-08-04 16:50:30 +0000118 /// \brief Retrieves a reference to the derived class.
119 Derived &getDerived() { return static_cast<Derived&>(*this); }
120
121 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000122 const Derived &getDerived() const {
123 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000124 }
125
John McCall60d7b3a2010-08-24 06:29:42 +0000126 static inline ExprResult Owned(Expr *E) { return E; }
127 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000128
Douglas Gregor577f75a2009-08-04 16:50:30 +0000129 /// \brief Retrieves a reference to the semantic analysis object used for
130 /// this tree transform.
131 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000132
Douglas Gregor577f75a2009-08-04 16:50:30 +0000133 /// \brief Whether the transformation should always rebuild AST nodes, even
134 /// if none of the children have changed.
135 ///
136 /// Subclasses may override this function to specify when the transformation
137 /// should rebuild all AST nodes.
138 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000139
Douglas Gregor577f75a2009-08-04 16:50:30 +0000140 /// \brief Returns the location of the entity being transformed, if that
141 /// information was not available elsewhere in the AST.
142 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000143 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000144 /// provide an alternative implementation that provides better location
145 /// information.
146 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000147
Douglas Gregor577f75a2009-08-04 16:50:30 +0000148 /// \brief Returns the name of the entity being transformed, if that
149 /// information was not available elsewhere in the AST.
150 ///
151 /// By default, returns an empty name. Subclasses can provide an alternative
152 /// implementation with a more precise name.
153 DeclarationName getBaseEntity() { return DeclarationName(); }
154
Douglas Gregorb98b1992009-08-11 05:31:07 +0000155 /// \brief Sets the "base" location and entity when that
156 /// information is known based on another transformation.
157 ///
158 /// By default, the source location and entity are ignored. Subclasses can
159 /// override this function to provide a customized implementation.
160 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000161
Douglas Gregorb98b1992009-08-11 05:31:07 +0000162 /// \brief RAII object that temporarily sets the base location and entity
163 /// used for reporting diagnostics in types.
164 class TemporaryBase {
165 TreeTransform &Self;
166 SourceLocation OldLocation;
167 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000168
Douglas Gregorb98b1992009-08-11 05:31:07 +0000169 public:
170 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000171 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000172 OldLocation = Self.getDerived().getBaseLocation();
173 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregorae201f72011-01-25 17:51:48 +0000174
175 if (Location.isValid())
176 Self.getDerived().setBase(Location, Entity);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000177 }
Mike Stump1eb44332009-09-09 15:08:12 +0000178
Douglas Gregorb98b1992009-08-11 05:31:07 +0000179 ~TemporaryBase() {
180 Self.getDerived().setBase(OldLocation, OldEntity);
181 }
182 };
Mike Stump1eb44332009-09-09 15:08:12 +0000183
184 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000185 /// transformed.
186 ///
187 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000188 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000189 /// not change. For example, template instantiation need not traverse
190 /// non-dependent types.
191 bool AlreadyTransformed(QualType T) {
192 return T.isNull();
193 }
194
Douglas Gregor6eef5192009-12-14 19:27:10 +0000195 /// \brief Determine whether the given call argument should be dropped, e.g.,
196 /// because it is a default argument.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine to
199 /// determine which kinds of call arguments get dropped. By default,
200 /// CXXDefaultArgument nodes are dropped (prior to transformation).
201 bool DropCallArgument(Expr *E) {
202 return E->isDefaultArgument();
203 }
Sean Huntc3021132010-05-05 15:23:54 +0000204
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000205 /// \brief Determine whether we should expand a pack expansion with the
206 /// given set of parameter packs into separate arguments by repeatedly
207 /// transforming the pattern.
208 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000209 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000210 /// Subclasses can override this routine to provide different behavior.
211 ///
212 /// \param EllipsisLoc The location of the ellipsis that identifies the
213 /// pack expansion.
214 ///
215 /// \param PatternRange The source range that covers the entire pattern of
216 /// the pack expansion.
217 ///
218 /// \param Unexpanded The set of unexpanded parameter packs within the
219 /// pattern.
220 ///
221 /// \param NumUnexpanded The number of unexpanded parameter packs in
222 /// \p Unexpanded.
223 ///
224 /// \param ShouldExpand Will be set to \c true if the transformer should
225 /// expand the corresponding pack expansions into separate arguments. When
226 /// set, \c NumExpansions must also be set.
227 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000228 /// \param RetainExpansion Whether the caller should add an unexpanded
229 /// pack expansion after all of the expanded arguments. This is used
230 /// when extending explicitly-specified template argument packs per
231 /// C++0x [temp.arg.explicit]p9.
232 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000233 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregorcded4f62011-01-14 17:04:44 +0000234 /// the expanded form of the corresponding pack expansion. This is both an
235 /// input and an output parameter, which can be set by the caller if the
236 /// number of expansions is known a priori (e.g., due to a prior substitution)
237 /// and will be set by the callee when the number of expansions is known.
238 /// The callee must set this value when \c ShouldExpand is \c true; it may
239 /// set this value in other cases.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000240 ///
241 /// \returns true if an error occurred (e.g., because the parameter packs
242 /// are to be instantiated with arguments of different lengths), false
243 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
244 /// must be set.
245 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
246 SourceRange PatternRange,
247 const UnexpandedParameterPack *Unexpanded,
248 unsigned NumUnexpanded,
249 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,
348 llvm::SmallVectorImpl<Expr *> &Outputs,
349 bool *ArgChanged = 0);
350
Douglas Gregor577f75a2009-08-04 16:50:30 +0000351 /// \brief Transform the given declaration, which is referenced from a type
352 /// or expression.
353 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000354 /// By default, acts as the identity function on declarations. Subclasses
355 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000356 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000357
358 /// \brief Transform the definition of the given declaration.
359 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000360 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000361 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000362 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
363 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000364 }
Mike Stump1eb44332009-09-09 15:08:12 +0000365
Douglas Gregor6cd21982009-10-20 05:58:46 +0000366 /// \brief Transform the given declaration, which was the first part of a
367 /// nested-name-specifier in a member access expression.
368 ///
Sean Huntc3021132010-05-05 15:23:54 +0000369 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000370 /// identifier in a nested-name-specifier of a member access expression, e.g.,
371 /// the \c T in \c x->T::member
372 ///
373 /// By default, invokes TransformDecl() to transform the declaration.
374 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000375 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
376 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000377 }
Sean Huntc3021132010-05-05 15:23:54 +0000378
Douglas Gregorc22b5ff2011-02-25 02:25:35 +0000379 /// \brief Transform the given nested-name-specifier with source-location
380 /// information.
381 ///
382 /// By default, transforms all of the types and declarations within the
383 /// nested-name-specifier. Subclasses may override this function to provide
384 /// alternate behavior.
385 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
386 NestedNameSpecifierLoc NNS,
387 QualType ObjectType = QualType(),
388 NamedDecl *FirstQualifierInScope = 0);
389
Douglas Gregor81499bb2009-09-03 22:13:48 +0000390 /// \brief Transform the given declaration name.
391 ///
392 /// By default, transforms the types of conversion function, constructor,
393 /// and destructor names and then (if needed) rebuilds the declaration name.
394 /// Identifiers and selectors are returned unmodified. Sublcasses may
395 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000396 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000397 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000398
Douglas Gregor577f75a2009-08-04 16:50:30 +0000399 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000400 ///
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000401 /// \param SS The nested-name-specifier that qualifies the template
402 /// name. This nested-name-specifier must already have been transformed.
403 ///
404 /// \param Name The template name to transform.
405 ///
406 /// \param NameLoc The source location of the template name.
407 ///
408 /// \param ObjectType If we're translating a template name within a member
409 /// access expression, this is the type of the object whose member template
410 /// is being referenced.
411 ///
412 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
413 /// also refers to a name within the current (lexical) scope, this is the
414 /// declaration it refers to.
415 ///
416 /// By default, transforms the template name by transforming the declarations
417 /// and nested-name-specifiers that occur within the template name.
418 /// Subclasses may override this function to provide alternate behavior.
419 TemplateName TransformTemplateName(CXXScopeSpec &SS,
420 TemplateName Name,
421 SourceLocation NameLoc,
422 QualType ObjectType = QualType(),
423 NamedDecl *FirstQualifierInScope = 0);
424
Douglas Gregor577f75a2009-08-04 16:50:30 +0000425 /// \brief Transform the given template argument.
426 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000427 /// By default, this operation transforms the type, expression, or
428 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000429 /// new template argument from the transformed result. Subclasses may
430 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000431 ///
432 /// Returns true if there was an error.
433 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
434 TemplateArgumentLoc &Output);
435
Douglas Gregorfcc12532010-12-20 17:31:10 +0000436 /// \brief Transform the given set of template arguments.
437 ///
438 /// By default, this operation transforms all of the template arguments
439 /// in the input set using \c TransformTemplateArgument(), and appends
440 /// the transformed arguments to the output list.
441 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000442 /// Note that this overload of \c TransformTemplateArguments() is merely
443 /// a convenience function. Subclasses that wish to override this behavior
444 /// should override the iterator-based member template version.
445 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000446 /// \param Inputs The set of template arguments to be transformed.
447 ///
448 /// \param NumInputs The number of template arguments in \p Inputs.
449 ///
450 /// \param Outputs The set of transformed template arguments output by this
451 /// routine.
452 ///
453 /// Returns true if an error occurred.
454 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
455 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000456 TemplateArgumentListInfo &Outputs) {
457 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
458 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000459
460 /// \brief Transform the given set of template arguments.
461 ///
462 /// By default, this operation transforms all of the template arguments
463 /// in the input set using \c TransformTemplateArgument(), and appends
464 /// the transformed arguments to the output list.
465 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000466 /// \param First An iterator to the first template argument.
467 ///
468 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000469 ///
470 /// \param Outputs The set of transformed template arguments output by this
471 /// routine.
472 ///
473 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000474 template<typename InputIterator>
475 bool TransformTemplateArguments(InputIterator First,
476 InputIterator Last,
477 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000478
John McCall833ca992009-10-29 08:12:44 +0000479 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
480 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
481 TemplateArgumentLoc &ArgLoc);
482
John McCalla93c9342009-12-07 02:54:59 +0000483 /// \brief Fakes up a TypeSourceInfo for a type.
484 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
485 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000486 getDerived().getBaseLocation());
487 }
Mike Stump1eb44332009-09-09 15:08:12 +0000488
John McCalla2becad2009-10-21 00:40:46 +0000489#define ABSTRACT_TYPELOC(CLASS, PARENT)
490#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000491 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000492#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000493
John Wiegley28bbe4b2011-04-28 01:08:34 +0000494 StmtResult
495 TransformSEHHandler(Stmt *Handler);
496
John McCall43fed0d2010-11-12 08:19:04 +0000497 QualType
498 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
499 TemplateSpecializationTypeLoc TL,
500 TemplateName Template);
501
502 QualType
503 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
504 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +0000505 TemplateName Template,
506 CXXScopeSpec &SS);
Douglas Gregora88f09f2011-02-28 17:23:35 +0000507
508 QualType
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000510 DependentTemplateSpecializationTypeLoc TL,
511 NestedNameSpecifierLoc QualifierLoc);
512
John McCall21ef0fa2010-03-11 09:03:00 +0000513 /// \brief Transforms the parameters of a function type into the
514 /// given vectors.
515 ///
516 /// The result vectors should be kept in sync; null entries in the
517 /// variables vector are acceptable.
518 ///
519 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000520 bool TransformFunctionTypeParams(SourceLocation Loc,
521 ParmVarDecl **Params, unsigned NumParams,
522 const QualType *ParamTypes,
John McCall21ef0fa2010-03-11 09:03:00 +0000523 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregora009b592011-01-07 00:20:55 +0000524 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000525
526 /// \brief Transforms a single function-type parameter. Return null
527 /// on error.
John McCallfb44de92011-05-01 22:35:37 +0000528 ///
529 /// \param indexAdjustment - A number to add to the parameter's
530 /// scope index; can be negative
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000531 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +0000532 int indexAdjustment,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +0000533 llvm::Optional<unsigned> NumExpansions);
John McCall21ef0fa2010-03-11 09:03:00 +0000534
John McCall43fed0d2010-11-12 08:19:04 +0000535 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000536
John McCall60d7b3a2010-08-24 06:29:42 +0000537 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
538 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000539
Douglas Gregor43959a92009-08-20 07:17:43 +0000540#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000541 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000542#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000543 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000544#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000545#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000546
Douglas Gregor577f75a2009-08-04 16:50:30 +0000547 /// \brief Build a new pointer type given its pointee type.
548 ///
549 /// By default, performs semantic analysis when building the pointer type.
550 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000551 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000552
553 /// \brief Build a new block pointer type given its pointee type.
554 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000555 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000556 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000557 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000558
John McCall85737a72009-10-30 00:06:24 +0000559 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000560 ///
John McCall85737a72009-10-30 00:06:24 +0000561 /// By default, performs semantic analysis when building the
562 /// reference type. Subclasses may override this routine to provide
563 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000564 ///
John McCall85737a72009-10-30 00:06:24 +0000565 /// \param LValue whether the type was written with an lvalue sigil
566 /// or an rvalue sigil.
567 QualType RebuildReferenceType(QualType ReferentType,
568 bool LValue,
569 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000570
Douglas Gregor577f75a2009-08-04 16:50:30 +0000571 /// \brief Build a new member pointer type given the pointee type and the
572 /// class type it refers into.
573 ///
574 /// By default, performs semantic analysis when building the member pointer
575 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000576 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
577 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000578
Douglas Gregor577f75a2009-08-04 16:50:30 +0000579 /// \brief Build a new array type given the element type, size
580 /// modifier, size of the array (if known), size expression, and index type
581 /// qualifiers.
582 ///
583 /// By default, performs semantic analysis when building the array type.
584 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000585 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000586 QualType RebuildArrayType(QualType ElementType,
587 ArrayType::ArraySizeModifier SizeMod,
588 const llvm::APInt *Size,
589 Expr *SizeExpr,
590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000592
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593 /// \brief Build a new constant array type given the element type, size
594 /// modifier, (known) size of the array, and index type qualifiers.
595 ///
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000598 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
600 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000603
Douglas Gregor577f75a2009-08-04 16:50:30 +0000604 /// \brief Build a new incomplete array type given the element type, size
605 /// modifier, and index type qualifiers.
606 ///
607 /// By default, performs semantic analysis when building the array type.
608 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000609 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000610 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000613
Mike Stump1eb44332009-09-09 15:08:12 +0000614 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000615 /// size modifier, size expression, and index type qualifiers.
616 ///
617 /// By default, performs semantic analysis when building the array type.
618 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000619 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000620 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000621 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
624
Mike Stump1eb44332009-09-09 15:08:12 +0000625 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000626 /// size modifier, size expression, and index type qualifiers.
627 ///
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000630 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000632 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
635
636 /// \brief Build a new vector type given the element type and
637 /// number of elements.
638 ///
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000641 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000642 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000643
Douglas Gregor577f75a2009-08-04 16:50:30 +0000644 /// \brief Build a new extended vector type given the element type and
645 /// number of elements.
646 ///
647 /// By default, performs semantic analysis when building the vector type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
650 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000651
652 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000653 /// given the element type and number of elements.
654 ///
655 /// By default, performs semantic analysis when building the vector type.
656 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000657 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000659 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000660
Douglas Gregor577f75a2009-08-04 16:50:30 +0000661 /// \brief Build a new function type.
662 ///
663 /// By default, performs semantic analysis when building the function type.
664 /// Subclasses may override this routine to provide different behavior.
665 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000666 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000667 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000668 bool Variadic, unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +0000669 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +0000670 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000671
John McCalla2becad2009-10-21 00:40:46 +0000672 /// \brief Build a new unprototyped function type.
673 QualType RebuildFunctionNoProtoType(QualType ResultType);
674
John McCalled976492009-12-04 22:46:56 +0000675 /// \brief Rebuild an unresolved typename type, given the decl that
676 /// the UnresolvedUsingTypenameDecl was transformed to.
677 QualType RebuildUnresolvedUsingType(Decl *D);
678
Douglas Gregor577f75a2009-08-04 16:50:30 +0000679 /// \brief Build a new typedef type.
Richard Smith162e1c12011-04-15 14:24:37 +0000680 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregor577f75a2009-08-04 16:50:30 +0000681 return SemaRef.Context.getTypeDeclType(Typedef);
682 }
683
684 /// \brief Build a new class/struct/union type.
685 QualType RebuildRecordType(RecordDecl *Record) {
686 return SemaRef.Context.getTypeDeclType(Record);
687 }
688
689 /// \brief Build a new Enum type.
690 QualType RebuildEnumType(EnumDecl *Enum) {
691 return SemaRef.Context.getTypeDeclType(Enum);
692 }
John McCall7da24312009-09-05 00:15:47 +0000693
Mike Stump1eb44332009-09-09 15:08:12 +0000694 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000695 ///
696 /// By default, performs semantic analysis when building the typeof type.
697 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000698 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000699
Mike Stump1eb44332009-09-09 15:08:12 +0000700 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000701 ///
702 /// By default, builds a new TypeOfType with the given underlying type.
703 QualType RebuildTypeOfType(QualType Underlying);
704
Sean Huntca63c202011-05-24 22:41:36 +0000705 /// \brief Build a new unary transform type.
706 QualType RebuildUnaryTransformType(QualType BaseType,
707 UnaryTransformType::UTTKind UKind,
708 SourceLocation Loc);
709
Mike Stump1eb44332009-09-09 15:08:12 +0000710 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000711 ///
712 /// By default, performs semantic analysis when building the decltype type.
713 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000714 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000715
Richard Smith34b41d92011-02-20 03:19:35 +0000716 /// \brief Build a new C++0x auto type.
717 ///
718 /// By default, builds a new AutoType with the given deduced type.
719 QualType RebuildAutoType(QualType Deduced) {
720 return SemaRef.Context.getAutoType(Deduced);
721 }
722
Douglas Gregor577f75a2009-08-04 16:50:30 +0000723 /// \brief Build a new template specialization type.
724 ///
725 /// By default, performs semantic analysis when building the template
726 /// specialization type. Subclasses may override this routine to provide
727 /// different behavior.
728 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000729 SourceLocation TemplateLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000730 TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000731
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000732 /// \brief Build a new parenthesized type.
733 ///
734 /// By default, builds a new ParenType type from the inner type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildParenType(QualType InnerType) {
737 return SemaRef.Context.getParenType(InnerType);
738 }
739
Douglas Gregor577f75a2009-08-04 16:50:30 +0000740 /// \brief Build a new qualified name type.
741 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000742 /// By default, builds a new ElaboratedType type from the keyword,
743 /// the nested-name-specifier and the named type.
744 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000745 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
746 ElaboratedTypeKeyword Keyword,
Douglas Gregor9e876872011-03-01 18:12:44 +0000747 NestedNameSpecifierLoc QualifierLoc,
748 QualType Named) {
749 return SemaRef.Context.getElaboratedType(Keyword,
750 QualifierLoc.getNestedNameSpecifier(),
751 Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000752 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000753
754 /// \brief Build a new typename type that refers to a template-id.
755 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000756 /// By default, builds a new DependentNameType type from the
757 /// nested-name-specifier and the given type. Subclasses may override
758 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000759 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000760 ElaboratedTypeKeyword Keyword,
761 NestedNameSpecifierLoc QualifierLoc,
762 const IdentifierInfo *Name,
763 SourceLocation NameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +0000764 TemplateArgumentListInfo &Args) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000765 // Rebuild the template name.
766 // TODO: avoid TemplateName abstraction
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000767 CXXScopeSpec SS;
768 SS.Adopt(QualifierLoc);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000769 TemplateName InstName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000770 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregor94fdffa2011-03-01 20:11:18 +0000771
772 if (InstName.isNull())
773 return QualType();
774
775 // If it's still dependent, make a dependent specialization.
776 if (InstName.getAsDependentTemplateName())
777 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
778 QualifierLoc.getNestedNameSpecifier(),
779 Name,
780 Args);
781
782 // Otherwise, make an elaborated type wrapping a non-dependent
783 // specialization.
784 QualType T =
785 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
786 if (T.isNull()) return QualType();
787
788 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
789 return T;
790
791 return SemaRef.Context.getElaboratedType(Keyword,
792 QualifierLoc.getNestedNameSpecifier(),
793 T);
794 }
795
Douglas Gregor577f75a2009-08-04 16:50:30 +0000796 /// \brief Build a new typename type that refers to an identifier.
797 ///
798 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000799 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000800 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000801 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000802 SourceLocation KeywordLoc,
Douglas Gregor2494dd02011-03-01 01:34:45 +0000803 NestedNameSpecifierLoc QualifierLoc,
804 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000805 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000806 CXXScopeSpec SS;
Douglas Gregor2494dd02011-03-01 01:34:45 +0000807 SS.Adopt(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000808
Douglas Gregor2494dd02011-03-01 01:34:45 +0000809 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregor40336422010-03-31 22:19:08 +0000810 // If the name is still dependent, just build a new dependent name type.
811 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor2494dd02011-03-01 01:34:45 +0000812 return SemaRef.Context.getDependentNameType(Keyword,
813 QualifierLoc.getNestedNameSpecifier(),
814 Id);
Douglas Gregor40336422010-03-31 22:19:08 +0000815 }
816
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000817 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor2494dd02011-03-01 01:34:45 +0000818 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregore29425b2011-02-28 22:42:13 +0000819 *Id, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000820
821 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
822
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000823 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000824 // into a non-dependent elaborated-type-specifier. Find the tag we're
825 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000826 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000827 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
828 if (!DC)
829 return QualType();
830
John McCall56138762010-05-27 06:40:31 +0000831 if (SemaRef.RequireCompleteDeclContext(SS, DC))
832 return QualType();
833
Douglas Gregor40336422010-03-31 22:19:08 +0000834 TagDecl *Tag = 0;
835 SemaRef.LookupQualifiedName(Result, DC);
836 switch (Result.getResultKind()) {
837 case LookupResult::NotFound:
838 case LookupResult::NotFoundInCurrentInstantiation:
839 break;
Sean Huntc3021132010-05-05 15:23:54 +0000840
Douglas Gregor40336422010-03-31 22:19:08 +0000841 case LookupResult::Found:
842 Tag = Result.getAsSingle<TagDecl>();
843 break;
Sean Huntc3021132010-05-05 15:23:54 +0000844
Douglas Gregor40336422010-03-31 22:19:08 +0000845 case LookupResult::FoundOverloaded:
846 case LookupResult::FoundUnresolvedValue:
847 llvm_unreachable("Tag lookup cannot find non-tags");
848 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000849
Douglas Gregor40336422010-03-31 22:19:08 +0000850 case LookupResult::Ambiguous:
851 // Let the LookupResult structure handle ambiguities.
852 return QualType();
853 }
854
855 if (!Tag) {
Nick Lewycky446e4022011-01-24 19:01:04 +0000856 // Check where the name exists but isn't a tag type and use that to emit
857 // better diagnostics.
858 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
859 SemaRef.LookupQualifiedName(Result, DC);
860 switch (Result.getResultKind()) {
861 case LookupResult::Found:
862 case LookupResult::FoundOverloaded:
863 case LookupResult::FoundUnresolvedValue: {
Richard Smith3e4c6c42011-05-05 21:57:07 +0000864 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky446e4022011-01-24 19:01:04 +0000865 unsigned Kind = 0;
866 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smith162e1c12011-04-15 14:24:37 +0000867 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
868 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky446e4022011-01-24 19:01:04 +0000869 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
870 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
871 break;
Richard Smith3e4c6c42011-05-05 21:57:07 +0000872 }
Nick Lewycky446e4022011-01-24 19:01:04 +0000873 default:
874 // FIXME: Would be nice to highlight just the source range.
875 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
876 << Kind << Id << DC;
877 break;
878 }
Douglas Gregor40336422010-03-31 22:19:08 +0000879 return QualType();
880 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000881
Richard Trieubbf34c02011-06-10 03:11:26 +0000882 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
883 IdLoc, *Id)) {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000884 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000885 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
886 return QualType();
887 }
888
889 // Build the elaborated-type-specifier type.
890 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor2494dd02011-03-01 01:34:45 +0000891 return SemaRef.Context.getElaboratedType(Keyword,
892 QualifierLoc.getNestedNameSpecifier(),
893 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000894 }
Mike Stump1eb44332009-09-09 15:08:12 +0000895
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000896 /// \brief Build a new pack expansion type.
897 ///
898 /// By default, builds a new PackExpansionType type from the given pattern.
899 /// Subclasses may override this routine to provide different behavior.
900 QualType RebuildPackExpansionType(QualType Pattern,
901 SourceRange PatternRange,
Douglas Gregorcded4f62011-01-14 17:04:44 +0000902 SourceLocation EllipsisLoc,
903 llvm::Optional<unsigned> NumExpansions) {
904 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
905 NumExpansions);
Douglas Gregor2fc1bb72011-01-12 17:07:58 +0000906 }
907
Douglas Gregord1067e52009-08-06 06:41:21 +0000908 /// \brief Build a new template name given a nested name specifier, a flag
909 /// indicating whether the "template" keyword was provided, and the template
910 /// that the template name refers to.
911 ///
912 /// By default, builds the new template name directly. Subclasses may override
913 /// this routine to provide different behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000914 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +0000915 bool TemplateKW,
916 TemplateDecl *Template);
917
Douglas Gregord1067e52009-08-06 06:41:21 +0000918 /// \brief Build a new template name given a nested name specifier and the
919 /// name that is referred to as a template.
920 ///
921 /// By default, performs semantic analysis to determine whether the name can
922 /// be resolved to a specific template, then builds the appropriate kind of
923 /// template name. Subclasses may override this routine to provide different
924 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000925 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
926 const IdentifierInfo &Name,
927 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +0000928 QualType ObjectType,
929 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000930
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000931 /// \brief Build a new template name given a nested name specifier and the
932 /// overloaded operator name that is referred to as a template.
933 ///
934 /// By default, performs semantic analysis to determine whether the name can
935 /// be resolved to a specific template, then builds the appropriate kind of
936 /// template name. Subclasses may override this routine to provide different
937 /// behavior.
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000938 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000939 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +0000940 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000941 QualType ObjectType);
Douglas Gregor1aee05d2011-01-15 06:45:20 +0000942
943 /// \brief Build a new template name given a template template parameter pack
944 /// and the
945 ///
946 /// By default, performs semantic analysis to determine whether the name can
947 /// be resolved to a specific template, then builds the appropriate kind of
948 /// template name. Subclasses may override this routine to provide different
949 /// behavior.
950 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
951 const TemplateArgument &ArgPack) {
952 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
953 }
954
Douglas Gregor43959a92009-08-20 07:17:43 +0000955 /// \brief Build a new compound statement.
956 ///
957 /// By default, performs semantic analysis to build the new statement.
958 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000959 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000960 MultiStmtArg Statements,
961 SourceLocation RBraceLoc,
962 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000963 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000964 IsStmtExpr);
965 }
966
967 /// \brief Build a new case statement.
968 ///
969 /// By default, performs semantic analysis to build the new statement.
970 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000971 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000972 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000973 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000974 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000975 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000976 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000977 ColonLoc);
978 }
Mike Stump1eb44332009-09-09 15:08:12 +0000979
Douglas Gregor43959a92009-08-20 07:17:43 +0000980 /// \brief Attach the body to a new case statement.
981 ///
982 /// By default, performs semantic analysis to build the new statement.
983 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000984 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000985 getSema().ActOnCaseStmtBody(S, Body);
986 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000987 }
Mike Stump1eb44332009-09-09 15:08:12 +0000988
Douglas Gregor43959a92009-08-20 07:17:43 +0000989 /// \brief Build a new default statement.
990 ///
991 /// By default, performs semantic analysis to build the new statement.
992 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000993 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000994 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000995 Stmt *SubStmt) {
996 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000997 /*CurScope=*/0);
998 }
Mike Stump1eb44332009-09-09 15:08:12 +0000999
Douglas Gregor43959a92009-08-20 07:17:43 +00001000 /// \brief Build a new label statement.
1001 ///
1002 /// By default, performs semantic analysis to build the new statement.
1003 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001004 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1005 SourceLocation ColonLoc, Stmt *SubStmt) {
1006 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregor43959a92009-08-20 07:17:43 +00001007 }
Mike Stump1eb44332009-09-09 15:08:12 +00001008
Douglas Gregor43959a92009-08-20 07:17:43 +00001009 /// \brief Build a new "if" statement.
1010 ///
1011 /// By default, performs semantic analysis to build the new statement.
1012 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001013 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattner57ad3782011-02-17 20:34:02 +00001014 VarDecl *CondVar, Stmt *Then,
1015 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00001016 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +00001017 }
Mike Stump1eb44332009-09-09 15:08:12 +00001018
Douglas Gregor43959a92009-08-20 07:17:43 +00001019 /// \brief Start building a new switch statement.
1020 ///
1021 /// By default, performs semantic analysis to build the new statement.
1022 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001023 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001024 Expr *Cond, VarDecl *CondVar) {
John McCall9ae2f072010-08-23 23:25:46 +00001025 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +00001026 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00001027 }
Mike Stump1eb44332009-09-09 15:08:12 +00001028
Douglas Gregor43959a92009-08-20 07:17:43 +00001029 /// \brief Attach the body to the switch statement.
1030 ///
1031 /// By default, performs semantic analysis to build the new statement.
1032 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001033 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattner57ad3782011-02-17 20:34:02 +00001034 Stmt *Switch, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001035 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001036 }
1037
1038 /// \brief Build a new while statement.
1039 ///
1040 /// By default, performs semantic analysis to build the new statement.
1041 /// Subclasses may override this routine to provide different behavior.
Chris Lattner57ad3782011-02-17 20:34:02 +00001042 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1043 VarDecl *CondVar, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001044 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001045 }
Mike Stump1eb44332009-09-09 15:08:12 +00001046
Douglas Gregor43959a92009-08-20 07:17:43 +00001047 /// \brief Build a new do-while statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001051 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001052 SourceLocation WhileLoc, SourceLocation LParenLoc,
1053 Expr *Cond, SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001054 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1055 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001056 }
1057
1058 /// \brief Build a new for statement.
1059 ///
1060 /// By default, performs semantic analysis to build the new statement.
1061 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001062 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1063 Stmt *Init, Sema::FullExprArg Cond,
1064 VarDecl *CondVar, Sema::FullExprArg Inc,
1065 SourceLocation RParenLoc, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +00001066 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001067 CondVar, Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001068 }
Mike Stump1eb44332009-09-09 15:08:12 +00001069
Douglas Gregor43959a92009-08-20 07:17:43 +00001070 /// \brief Build a new goto statement.
1071 ///
1072 /// By default, performs semantic analysis to build the new statement.
1073 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001074 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1075 LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001076 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregor43959a92009-08-20 07:17:43 +00001077 }
1078
1079 /// \brief Build a new indirect goto statement.
1080 ///
1081 /// By default, performs semantic analysis to build the new statement.
1082 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001083 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001084 SourceLocation StarLoc,
1085 Expr *Target) {
John McCall9ae2f072010-08-23 23:25:46 +00001086 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001087 }
Mike Stump1eb44332009-09-09 15:08:12 +00001088
Douglas Gregor43959a92009-08-20 07:17:43 +00001089 /// \brief Build a new return statement.
1090 ///
1091 /// By default, performs semantic analysis to build the new statement.
1092 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001093 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCall9ae2f072010-08-23 23:25:46 +00001094 return getSema().ActOnReturnStmt(ReturnLoc, Result);
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 declaration statement.
1098 ///
1099 /// By default, performs semantic analysis to build the new statement.
1100 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001101 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001102 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001103 SourceLocation EndLoc) {
Richard Smith406c38e2011-02-23 00:37:57 +00001104 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1105 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001106 }
Mike Stump1eb44332009-09-09 15:08:12 +00001107
Anders Carlsson703e3942010-01-24 05:50:09 +00001108 /// \brief Build a new inline asm statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001112 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001113 bool IsSimple,
1114 bool IsVolatile,
1115 unsigned NumOutputs,
1116 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001117 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001118 MultiExprArg Constraints,
1119 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001120 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001121 MultiExprArg Clobbers,
1122 SourceLocation RParenLoc,
1123 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001124 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001125 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001126 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001127 RParenLoc, MSAsm);
1128 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001129
1130 /// \brief Build a new Objective-C @try statement.
1131 ///
1132 /// By default, performs semantic analysis to build the new statement.
1133 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001134 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001135 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001136 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001137 Stmt *Finally) {
1138 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1139 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001140 }
1141
Douglas Gregorbe270a02010-04-26 17:57:08 +00001142 /// \brief Rebuild an Objective-C exception declaration.
1143 ///
1144 /// By default, performs semantic analysis to build the new declaration.
1145 /// Subclasses may override this routine to provide different behavior.
1146 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1147 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001148 return getSema().BuildObjCExceptionDecl(TInfo, T,
1149 ExceptionDecl->getInnerLocStart(),
1150 ExceptionDecl->getLocation(),
1151 ExceptionDecl->getIdentifier());
Douglas Gregorbe270a02010-04-26 17:57:08 +00001152 }
Sean Huntc3021132010-05-05 15:23:54 +00001153
Douglas Gregorbe270a02010-04-26 17:57:08 +00001154 /// \brief Build a new Objective-C @catch statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001158 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001159 SourceLocation RParenLoc,
1160 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001161 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001162 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001163 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001164 }
Sean Huntc3021132010-05-05 15:23:54 +00001165
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001166 /// \brief Build a new Objective-C @finally statement.
1167 ///
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001170 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001171 Stmt *Body) {
1172 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001173 }
Sean Huntc3021132010-05-05 15:23:54 +00001174
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001175 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001179 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001180 Expr *Operand) {
1181 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001182 }
Sean Huntc3021132010-05-05 15:23:54 +00001183
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001184 /// \brief Build a new Objective-C @synchronized statement.
1185 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001186 /// By default, performs semantic analysis to build the new statement.
1187 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001188 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001189 Expr *Object,
1190 Stmt *Body) {
1191 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1192 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001193 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001194
John McCallf85e1932011-06-15 23:02:42 +00001195 /// \brief Build a new Objective-C @autoreleasepool statement.
1196 ///
1197 /// By default, performs semantic analysis to build the new statement.
1198 /// Subclasses may override this routine to provide different behavior.
1199 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1200 Stmt *Body) {
1201 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1202 }
1203
1204
Douglas Gregorc3203e72010-04-22 23:10:45 +00001205 /// \brief Build a new Objective-C fast enumeration statement.
1206 ///
1207 /// By default, performs semantic analysis to build the new statement.
1208 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001209 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001210 SourceLocation LParenLoc,
1211 Stmt *Element,
1212 Expr *Collection,
1213 SourceLocation RParenLoc,
1214 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001215 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001216 Element,
1217 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001218 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001219 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001220 }
Sean Huntc3021132010-05-05 15:23:54 +00001221
Douglas Gregor43959a92009-08-20 07:17:43 +00001222 /// \brief Build a new C++ exception declaration.
1223 ///
1224 /// By default, performs semantic analysis to build the new decaration.
1225 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001226 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001227 TypeSourceInfo *Declarator,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00001228 SourceLocation StartLoc,
1229 SourceLocation IdLoc,
1230 IdentifierInfo *Id) {
Douglas Gregorefdf9882011-04-14 22:32:28 +00001231 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1232 StartLoc, IdLoc, Id);
1233 if (Var)
1234 getSema().CurContext->addDecl(Var);
1235 return Var;
Douglas Gregor43959a92009-08-20 07:17:43 +00001236 }
1237
1238 /// \brief Build a new C++ catch statement.
1239 ///
1240 /// By default, performs semantic analysis to build the new statement.
1241 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001242 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001243 VarDecl *ExceptionDecl,
1244 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001245 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1246 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001247 }
Mike Stump1eb44332009-09-09 15:08:12 +00001248
Douglas Gregor43959a92009-08-20 07:17:43 +00001249 /// \brief Build a new C++ try statement.
1250 ///
1251 /// By default, performs semantic analysis to build the new statement.
1252 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001253 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001254 Stmt *TryBlock,
1255 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001256 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001257 }
Mike Stump1eb44332009-09-09 15:08:12 +00001258
Richard Smithad762fc2011-04-14 22:09:26 +00001259 /// \brief Build a new C++0x range-based for statement.
1260 ///
1261 /// By default, performs semantic analysis to build the new statement.
1262 /// Subclasses may override this routine to provide different behavior.
1263 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1264 SourceLocation ColonLoc,
1265 Stmt *Range, Stmt *BeginEnd,
1266 Expr *Cond, Expr *Inc,
1267 Stmt *LoopVar,
1268 SourceLocation RParenLoc) {
1269 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1270 Cond, Inc, LoopVar, RParenLoc);
1271 }
1272
1273 /// \brief Attach body to a C++0x range-based for statement.
1274 ///
1275 /// By default, performs semantic analysis to finish the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
1277 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1278 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1279 }
1280
John Wiegley28bbe4b2011-04-28 01:08:34 +00001281 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1282 SourceLocation TryLoc,
1283 Stmt *TryBlock,
1284 Stmt *Handler) {
1285 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1286 }
1287
1288 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1289 Expr *FilterExpr,
1290 Stmt *Block) {
1291 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1292 }
1293
1294 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1295 Stmt *Block) {
1296 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1297 }
1298
Douglas Gregorb98b1992009-08-11 05:31:07 +00001299 /// \brief Build a new expression that references a declaration.
1300 ///
1301 /// By default, performs semantic analysis to build the new expression.
1302 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001303 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001304 LookupResult &R,
1305 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001306 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1307 }
1308
1309
1310 /// \brief Build a new expression that references a declaration.
1311 ///
1312 /// By default, performs semantic analysis to build the new expression.
1313 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001314 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001315 ValueDecl *VD,
1316 const DeclarationNameInfo &NameInfo,
1317 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001318 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001319 SS.Adopt(QualifierLoc);
John McCalldbd872f2009-12-08 09:08:17 +00001320
1321 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001322
1323 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001324 }
Mike Stump1eb44332009-09-09 15:08:12 +00001325
Douglas Gregorb98b1992009-08-11 05:31:07 +00001326 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001327 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001328 /// By default, performs semantic analysis to build the new expression.
1329 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001330 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001331 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001332 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001333 }
1334
Douglas Gregora71d8192009-09-04 17:36:40 +00001335 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001336 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001337 /// By default, performs semantic analysis to build the new expression.
1338 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001339 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00001340 SourceLocation OperatorLoc,
1341 bool isArrow,
1342 CXXScopeSpec &SS,
1343 TypeSourceInfo *ScopeType,
1344 SourceLocation CCLoc,
1345 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001346 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001347
Douglas Gregorb98b1992009-08-11 05:31:07 +00001348 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001349 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001350 /// By default, performs semantic analysis to build the new expression.
1351 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001352 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001353 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001354 Expr *SubExpr) {
1355 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001356 }
Mike Stump1eb44332009-09-09 15:08:12 +00001357
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001358 /// \brief Build a new builtin offsetof expression.
1359 ///
1360 /// By default, performs semantic analysis to build the new expression.
1361 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001362 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001363 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001364 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001365 unsigned NumComponents,
1366 SourceLocation RParenLoc) {
1367 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1368 NumComponents, RParenLoc);
1369 }
Sean Huntc3021132010-05-05 15:23:54 +00001370
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001371 /// \brief Build a new sizeof, alignof or vec_step expression with a
1372 /// type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001373 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001374 /// By default, performs semantic analysis to build the new expression.
1375 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001376 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1377 SourceLocation OpLoc,
1378 UnaryExprOrTypeTrait ExprKind,
1379 SourceRange R) {
1380 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001381 }
1382
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001383 /// \brief Build a new sizeof, alignof or vec step expression with an
1384 /// expression argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001385 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001386 /// By default, performs semantic analysis to build the new expression.
1387 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00001388 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1389 UnaryExprOrTypeTrait ExprKind,
1390 SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001391 ExprResult Result
Chandler Carruthe72c55b2011-05-29 07:32:14 +00001392 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001393 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001394 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001395
Douglas Gregorb98b1992009-08-11 05:31:07 +00001396 return move(Result);
1397 }
Mike Stump1eb44332009-09-09 15:08:12 +00001398
Douglas Gregorb98b1992009-08-11 05:31:07 +00001399 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001400 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001401 /// By default, performs semantic analysis to build the new expression.
1402 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001403 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001404 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001405 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001406 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001407 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1408 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001409 RBracketLoc);
1410 }
1411
1412 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001413 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001414 /// By default, performs semantic analysis to build the new expression.
1415 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001416 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001417 MultiExprArg Args,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001418 SourceLocation RParenLoc,
1419 Expr *ExecConfig = 0) {
John McCall9ae2f072010-08-23 23:25:46 +00001420 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbournee08ce652011-02-09 21:07:24 +00001421 move(Args), RParenLoc, ExecConfig);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001422 }
1423
1424 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001425 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001426 /// By default, performs semantic analysis to build the new expression.
1427 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001428 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001429 bool isArrow,
Douglas Gregor40d96a62011-02-28 21:54:11 +00001430 NestedNameSpecifierLoc QualifierLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001431 const DeclarationNameInfo &MemberNameInfo,
1432 ValueDecl *Member,
1433 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001434 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001435 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001436 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001437 // We have a reference to an unnamed field. This is always the
1438 // base of an anonymous struct/union member access, i.e. the
1439 // field is always of record type.
Douglas Gregor40d96a62011-02-28 21:54:11 +00001440 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001441 assert(Member->getType()->isRecordType() &&
1442 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001443
John Wiegley429bb272011-04-08 18:41:53 +00001444 ExprResult BaseResult =
1445 getSema().PerformObjectMemberConversion(Base,
1446 QualifierLoc.getNestedNameSpecifier(),
1447 FoundDecl, Member);
1448 if (BaseResult.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001449 return ExprError();
John Wiegley429bb272011-04-08 18:41:53 +00001450 Base = BaseResult.take();
John McCallf89e55a2010-11-18 06:31:45 +00001451 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001452 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001453 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001454 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001455 cast<FieldDecl>(Member)->getType(),
1456 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001457 return getSema().Owned(ME);
1458 }
Mike Stump1eb44332009-09-09 15:08:12 +00001459
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001460 CXXScopeSpec SS;
Douglas Gregor40d96a62011-02-28 21:54:11 +00001461 SS.Adopt(QualifierLoc);
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001462
John Wiegley429bb272011-04-08 18:41:53 +00001463 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1464 if (BaseResult.isInvalid())
1465 return ExprError();
1466 Base = BaseResult.take();
John McCall9ae2f072010-08-23 23:25:46 +00001467 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001468
John McCall6bb80172010-03-30 21:47:33 +00001469 // FIXME: this involves duplicating earlier analysis in a lot of
1470 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001471 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001472 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001473 R.resolveKind();
1474
John McCall9ae2f072010-08-23 23:25:46 +00001475 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001476 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001477 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001478 }
Mike Stump1eb44332009-09-09 15:08:12 +00001479
Douglas Gregorb98b1992009-08-11 05:31:07 +00001480 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001481 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 /// By default, performs semantic analysis to build the new expression.
1483 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001484 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001485 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001486 Expr *LHS, Expr *RHS) {
1487 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001488 }
1489
1490 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001491 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001492 /// By default, performs semantic analysis to build the new expression.
1493 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001494 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCall56ca35d2011-02-17 10:25:35 +00001495 SourceLocation QuestionLoc,
1496 Expr *LHS,
1497 SourceLocation ColonLoc,
1498 Expr *RHS) {
John McCall9ae2f072010-08-23 23:25:46 +00001499 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1500 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 }
1502
Douglas Gregorb98b1992009-08-11 05:31:07 +00001503 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001504 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001505 /// By default, performs semantic analysis to build the new expression.
1506 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001507 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001508 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001509 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001510 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001511 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001512 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001513 }
Mike Stump1eb44332009-09-09 15:08:12 +00001514
Douglas Gregorb98b1992009-08-11 05:31:07 +00001515 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001516 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001517 /// By default, performs semantic analysis to build the new expression.
1518 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001519 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001520 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001521 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001522 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001523 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001524 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 }
Mike Stump1eb44332009-09-09 15:08:12 +00001526
Douglas Gregorb98b1992009-08-11 05:31:07 +00001527 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001528 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001529 /// By default, performs semantic analysis to build the new expression.
1530 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001531 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001532 SourceLocation OpLoc,
1533 SourceLocation AccessorLoc,
1534 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001535
John McCall129e2df2009-11-30 22:42:35 +00001536 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001537 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001538 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001539 OpLoc, /*IsArrow*/ false,
1540 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001541 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001542 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001543 }
Mike Stump1eb44332009-09-09 15:08:12 +00001544
Douglas Gregorb98b1992009-08-11 05:31:07 +00001545 /// \brief Build a new initializer list expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001546 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001547 /// By default, performs semantic analysis to build the new expression.
1548 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001549 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001550 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001551 SourceLocation RBraceLoc,
1552 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001553 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001554 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1555 if (Result.isInvalid() || ResultTy->isDependentType())
1556 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001557
Douglas Gregore48319a2009-11-09 17:16:50 +00001558 // Patch in the result type we were given, which may have been computed
1559 // when the initial InitListExpr was built.
1560 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1561 ILE->setType(ResultTy);
1562 return move(Result);
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 designated initializer 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 RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001570 MultiExprArg ArrayExprs,
1571 SourceLocation EqualOrColonLoc,
1572 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001573 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001574 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001575 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001576 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001577 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001578 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001579
Douglas Gregorb98b1992009-08-11 05:31:07 +00001580 ArrayExprs.release();
1581 return move(Result);
1582 }
Mike Stump1eb44332009-09-09 15:08:12 +00001583
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001585 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 /// By default, builds the implicit value initialization without performing
1587 /// any semantic analysis. Subclasses may override this routine to provide
1588 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001589 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001590 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1591 }
Mike Stump1eb44332009-09-09 15:08:12 +00001592
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001594 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001595 /// By default, performs semantic analysis to build the new expression.
1596 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001597 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001598 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001599 SourceLocation RParenLoc) {
1600 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001601 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001602 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001603 }
1604
1605 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001606 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001607 /// By default, performs semantic analysis to build the new expression.
1608 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001609 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001610 MultiExprArg SubExprs,
1611 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001612 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001613 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001614 }
Mike Stump1eb44332009-09-09 15:08:12 +00001615
Douglas Gregorb98b1992009-08-11 05:31:07 +00001616 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001617 ///
1618 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001619 /// rather than attempting to map the label statement itself.
1620 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001621 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerad8dcf42011-02-17 07:39:24 +00001622 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattner57ad3782011-02-17 20:34:02 +00001623 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001624 }
Mike Stump1eb44332009-09-09 15:08:12 +00001625
Douglas Gregorb98b1992009-08-11 05:31:07 +00001626 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001627 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001628 /// By default, performs semantic analysis to build the new expression.
1629 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001630 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001631 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001632 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001633 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001634 }
Mike Stump1eb44332009-09-09 15:08:12 +00001635
Douglas Gregorb98b1992009-08-11 05:31:07 +00001636 /// \brief Build a new __builtin_choose_expr expression.
1637 ///
1638 /// By default, performs semantic analysis to build the new expression.
1639 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001640 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001641 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 SourceLocation RParenLoc) {
1643 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001644 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001645 RParenLoc);
1646 }
Mike Stump1eb44332009-09-09 15:08:12 +00001647
Peter Collingbournef111d932011-04-15 00:35:48 +00001648 /// \brief Build a new generic selection expression.
1649 ///
1650 /// By default, performs semantic analysis to build the new expression.
1651 /// Subclasses may override this routine to provide different behavior.
1652 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1653 SourceLocation DefaultLoc,
1654 SourceLocation RParenLoc,
1655 Expr *ControllingExpr,
1656 TypeSourceInfo **Types,
1657 Expr **Exprs,
1658 unsigned NumAssocs) {
1659 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1660 ControllingExpr, Types, Exprs,
1661 NumAssocs);
1662 }
1663
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 /// \brief Build a new overloaded operator call expression.
1665 ///
1666 /// By default, performs semantic analysis to build the new expression.
1667 /// The semantic analysis provides the behavior of template instantiation,
1668 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001669 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001670 /// argument-dependent lookup, etc. Subclasses may override this routine to
1671 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001672 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001673 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001674 Expr *Callee,
1675 Expr *First,
1676 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001677
1678 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001679 /// reinterpret_cast.
1680 ///
1681 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001682 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001683 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001684 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001685 Stmt::StmtClass Class,
1686 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001687 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001688 SourceLocation RAngleLoc,
1689 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001690 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001691 SourceLocation RParenLoc) {
1692 switch (Class) {
1693 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001694 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001695 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001696 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001697
1698 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001699 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001700 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001701 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001702
Douglas Gregorb98b1992009-08-11 05:31:07 +00001703 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001704 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001705 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001706 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001707 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001708
Douglas Gregorb98b1992009-08-11 05:31:07 +00001709 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001710 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001711 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001712 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001713
Douglas Gregorb98b1992009-08-11 05:31:07 +00001714 default:
1715 assert(false && "Invalid C++ named cast");
1716 break;
1717 }
Mike Stump1eb44332009-09-09 15:08:12 +00001718
John McCallf312b1e2010-08-26 23:41:50 +00001719 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001720 }
Mike Stump1eb44332009-09-09 15:08:12 +00001721
Douglas Gregorb98b1992009-08-11 05:31:07 +00001722 /// \brief Build a new C++ static_cast expression.
1723 ///
1724 /// By default, performs semantic analysis to build the new expression.
1725 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001726 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001727 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001728 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001729 SourceLocation RAngleLoc,
1730 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001731 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001732 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001733 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001734 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001735 SourceRange(LAngleLoc, RAngleLoc),
1736 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001737 }
1738
1739 /// \brief Build a new C++ dynamic_cast expression.
1740 ///
1741 /// By default, performs semantic analysis to build the new expression.
1742 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001743 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001744 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001745 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 SourceLocation RAngleLoc,
1747 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001748 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001749 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001750 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001751 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001752 SourceRange(LAngleLoc, RAngleLoc),
1753 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001754 }
1755
1756 /// \brief Build a new C++ reinterpret_cast expression.
1757 ///
1758 /// By default, performs semantic analysis to build the new expression.
1759 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001760 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001761 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001762 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001763 SourceLocation RAngleLoc,
1764 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001765 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001766 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001767 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001768 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001769 SourceRange(LAngleLoc, RAngleLoc),
1770 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001771 }
1772
1773 /// \brief Build a new C++ const_cast expression.
1774 ///
1775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001777 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001778 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001779 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001780 SourceLocation RAngleLoc,
1781 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001782 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001783 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001784 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001785 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001786 SourceRange(LAngleLoc, RAngleLoc),
1787 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001788 }
Mike Stump1eb44332009-09-09 15:08:12 +00001789
Douglas Gregorb98b1992009-08-11 05:31:07 +00001790 /// \brief Build a new C++ functional-style cast expression.
1791 ///
1792 /// By default, performs semantic analysis to build the new expression.
1793 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001794 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1795 SourceLocation LParenLoc,
1796 Expr *Sub,
1797 SourceLocation RParenLoc) {
1798 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001799 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001800 RParenLoc);
1801 }
Mike Stump1eb44332009-09-09 15:08:12 +00001802
Douglas Gregorb98b1992009-08-11 05:31:07 +00001803 /// \brief Build a new C++ typeid(type) expression.
1804 ///
1805 /// By default, performs semantic analysis to build the new expression.
1806 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001807 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001808 SourceLocation TypeidLoc,
1809 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001811 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001812 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001813 }
Mike Stump1eb44332009-09-09 15:08:12 +00001814
Francois Pichet01b7c302010-09-08 12:20:18 +00001815
Douglas Gregorb98b1992009-08-11 05:31:07 +00001816 /// \brief Build a new C++ typeid(expr) expression.
1817 ///
1818 /// By default, performs semantic analysis to build the new expression.
1819 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001820 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001821 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001822 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001823 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001824 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001825 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001826 }
1827
Francois Pichet01b7c302010-09-08 12:20:18 +00001828 /// \brief Build a new C++ __uuidof(type) expression.
1829 ///
1830 /// By default, performs semantic analysis to build the new expression.
1831 /// Subclasses may override this routine to provide different behavior.
1832 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1833 SourceLocation TypeidLoc,
1834 TypeSourceInfo *Operand,
1835 SourceLocation RParenLoc) {
1836 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1837 RParenLoc);
1838 }
1839
1840 /// \brief Build a new C++ __uuidof(expr) expression.
1841 ///
1842 /// By default, performs semantic analysis to build the new expression.
1843 /// Subclasses may override this routine to provide different behavior.
1844 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1845 SourceLocation TypeidLoc,
1846 Expr *Operand,
1847 SourceLocation RParenLoc) {
1848 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1849 RParenLoc);
1850 }
1851
Douglas Gregorb98b1992009-08-11 05:31:07 +00001852 /// \brief Build a new C++ "this" expression.
1853 ///
1854 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001855 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001856 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001857 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001858 QualType ThisType,
1859 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001860 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001861 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1862 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001863 }
1864
1865 /// \brief Build a new C++ throw expression.
1866 ///
1867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001869 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001870 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001871 }
1872
1873 /// \brief Build a new C++ default-argument expression.
1874 ///
1875 /// By default, builds a new default-argument expression, which does not
1876 /// require any semantic analysis. Subclasses may override this routine to
1877 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001878 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001879 ParmVarDecl *Param) {
1880 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1881 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001882 }
1883
1884 /// \brief Build a new C++ zero-initialization expression.
1885 ///
1886 /// By default, performs semantic analysis to build the new expression.
1887 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001888 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1889 SourceLocation LParenLoc,
1890 SourceLocation RParenLoc) {
1891 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001892 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001893 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001894 }
Mike Stump1eb44332009-09-09 15:08:12 +00001895
Douglas Gregorb98b1992009-08-11 05:31:07 +00001896 /// \brief Build a new C++ "new" expression.
1897 ///
1898 /// By default, performs semantic analysis to build the new expression.
1899 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001900 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001901 bool UseGlobal,
1902 SourceLocation PlacementLParen,
1903 MultiExprArg PlacementArgs,
1904 SourceLocation PlacementRParen,
1905 SourceRange TypeIdParens,
1906 QualType AllocatedType,
1907 TypeSourceInfo *AllocatedTypeInfo,
1908 Expr *ArraySize,
1909 SourceLocation ConstructorLParen,
1910 MultiExprArg ConstructorArgs,
1911 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001912 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001913 PlacementLParen,
1914 move(PlacementArgs),
1915 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001916 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001917 AllocatedType,
1918 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001919 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001920 ConstructorLParen,
1921 move(ConstructorArgs),
1922 ConstructorRParen);
1923 }
Mike Stump1eb44332009-09-09 15:08:12 +00001924
Douglas Gregorb98b1992009-08-11 05:31:07 +00001925 /// \brief Build a new C++ "delete" expression.
1926 ///
1927 /// By default, performs semantic analysis to build the new expression.
1928 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001929 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001930 bool IsGlobalDelete,
1931 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001932 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001933 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001934 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001935 }
Mike Stump1eb44332009-09-09 15:08:12 +00001936
Douglas Gregorb98b1992009-08-11 05:31:07 +00001937 /// \brief Build a new unary type trait expression.
1938 ///
1939 /// By default, performs semantic analysis to build the new expression.
1940 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001941 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001942 SourceLocation StartLoc,
1943 TypeSourceInfo *T,
1944 SourceLocation RParenLoc) {
1945 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001946 }
1947
Francois Pichet6ad6f282010-12-07 00:08:36 +00001948 /// \brief Build a new binary type trait expression.
1949 ///
1950 /// By default, performs semantic analysis to build the new expression.
1951 /// Subclasses may override this routine to provide different behavior.
1952 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1953 SourceLocation StartLoc,
1954 TypeSourceInfo *LhsT,
1955 TypeSourceInfo *RhsT,
1956 SourceLocation RParenLoc) {
1957 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1958 }
1959
John Wiegley21ff2e52011-04-28 00:16:57 +00001960 /// \brief Build a new array type trait expression.
1961 ///
1962 /// By default, performs semantic analysis to build the new expression.
1963 /// Subclasses may override this routine to provide different behavior.
1964 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1965 SourceLocation StartLoc,
1966 TypeSourceInfo *TSInfo,
1967 Expr *DimExpr,
1968 SourceLocation RParenLoc) {
1969 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1970 }
1971
John Wiegley55262202011-04-25 06:54:41 +00001972 /// \brief Build a new expression trait expression.
1973 ///
1974 /// By default, performs semantic analysis to build the new expression.
1975 /// Subclasses may override this routine to provide different behavior.
1976 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1977 SourceLocation StartLoc,
1978 Expr *Queried,
1979 SourceLocation RParenLoc) {
1980 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1981 }
1982
Mike Stump1eb44332009-09-09 15:08:12 +00001983 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001984 /// expression.
1985 ///
1986 /// By default, performs semantic analysis to build the new expression.
1987 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001988 ExprResult RebuildDependentScopeDeclRefExpr(
1989 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00001990 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001991 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001992 CXXScopeSpec SS;
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00001993 SS.Adopt(QualifierLoc);
John McCallf7a1a742009-11-24 19:00:30 +00001994
1995 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001996 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001997 *TemplateArgs);
1998
Abramo Bagnara25777432010-08-11 22:01:17 +00001999 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002000 }
2001
2002 /// \brief Build a new template-id expression.
2003 ///
2004 /// By default, performs semantic analysis to build the new expression.
2005 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002006 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00002007 LookupResult &R,
2008 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00002009 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00002010 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002011 }
2012
2013 /// \brief Build a new object-construction expression.
2014 ///
2015 /// By default, performs semantic analysis to build the new expression.
2016 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002017 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002018 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002019 CXXConstructorDecl *Constructor,
2020 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002021 MultiExprArg Args,
2022 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00002023 CXXConstructExpr::ConstructionKind ConstructKind,
2024 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00002025 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00002026 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002027 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00002028 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002029
Douglas Gregor4411d2e2009-12-14 16:27:04 +00002030 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00002031 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00002032 RequiresZeroInit, ConstructKind,
2033 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002034 }
2035
2036 /// \brief Build a new object-construction expression.
2037 ///
2038 /// By default, performs semantic analysis to build the new expression.
2039 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002040 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2041 SourceLocation LParenLoc,
2042 MultiExprArg Args,
2043 SourceLocation RParenLoc) {
2044 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002045 LParenLoc,
2046 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002047 RParenLoc);
2048 }
2049
2050 /// \brief Build a new object-construction expression.
2051 ///
2052 /// By default, performs semantic analysis to build the new expression.
2053 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00002054 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2055 SourceLocation LParenLoc,
2056 MultiExprArg Args,
2057 SourceLocation RParenLoc) {
2058 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002059 LParenLoc,
2060 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002061 RParenLoc);
2062 }
Mike Stump1eb44332009-09-09 15:08:12 +00002063
Douglas Gregorb98b1992009-08-11 05:31:07 +00002064 /// \brief Build a new member reference expression.
2065 ///
2066 /// By default, performs semantic analysis to build the new expression.
2067 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002068 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002069 QualType BaseType,
2070 bool IsArrow,
2071 SourceLocation OperatorLoc,
2072 NestedNameSpecifierLoc QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00002073 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002074 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00002075 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002076 CXXScopeSpec SS;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002077 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002078
John McCall9ae2f072010-08-23 23:25:46 +00002079 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002080 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00002081 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00002082 MemberNameInfo,
2083 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002084 }
2085
John McCall129e2df2009-11-30 22:42:35 +00002086 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002087 ///
2088 /// By default, performs semantic analysis to build the new expression.
2089 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002090 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00002091 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00002092 SourceLocation OperatorLoc,
2093 bool IsArrow,
Douglas Gregor4c9be892011-02-28 20:01:57 +00002094 NestedNameSpecifierLoc QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00002095 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00002096 LookupResult &R,
2097 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002098 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00002099 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00002100
John McCall9ae2f072010-08-23 23:25:46 +00002101 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00002102 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00002103 SS, FirstQualifierInScope,
2104 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002105 }
Mike Stump1eb44332009-09-09 15:08:12 +00002106
Sebastian Redl2e156222010-09-10 20:55:43 +00002107 /// \brief Build a new noexcept expression.
2108 ///
2109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
2111 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2112 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2113 }
2114
Douglas Gregoree8aff02011-01-04 17:33:58 +00002115 /// \brief Build a new expression to compute the length of a parameter pack.
2116 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2117 SourceLocation PackLoc,
2118 SourceLocation RParenLoc,
2119 unsigned Length) {
2120 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2121 OperatorLoc, Pack, PackLoc,
2122 RParenLoc, Length);
2123 }
2124
Douglas Gregorb98b1992009-08-11 05:31:07 +00002125 /// \brief Build a new Objective-C @encode expression.
2126 ///
2127 /// By default, performs semantic analysis to build the new expression.
2128 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002129 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00002130 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002131 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00002132 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00002133 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002134 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00002135
Douglas Gregor92e986e2010-04-22 16:44:27 +00002136 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00002137 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002138 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002139 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002140 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002141 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002142 MultiExprArg Args,
2143 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00002144 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2145 ReceiverTypeInfo->getType(),
2146 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002147 Sel, Method, LBracLoc, SelectorLoc,
2148 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002149 }
2150
2151 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00002152 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002153 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002154 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002155 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002156 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002157 MultiExprArg Args,
2158 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002159 return SemaRef.BuildInstanceMessage(Receiver,
2160 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002161 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002162 Sel, Method, LBracLoc, SelectorLoc,
2163 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002164 }
2165
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002166 /// \brief Build a new Objective-C ivar reference expression.
2167 ///
2168 /// By default, performs semantic analysis to build the new expression.
2169 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002170 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002171 SourceLocation IvarLoc,
2172 bool IsArrow, bool IsFreeIvar) {
2173 // FIXME: We lose track of the IsFreeIvar bit.
2174 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002175 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002176 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2177 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002178 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002179 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002180 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002181 false);
John Wiegley429bb272011-04-08 18:41:53 +00002182 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002183 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002184
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002185 if (Result.get())
2186 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002187
John Wiegley429bb272011-04-08 18:41:53 +00002188 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002189 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002190 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002191 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002192 /*TemplateArgs=*/0);
2193 }
Douglas Gregore3303542010-04-26 20:47:02 +00002194
2195 /// \brief Build a new Objective-C property reference expression.
2196 ///
2197 /// By default, performs semantic analysis to build the new expression.
2198 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002199 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002200 ObjCPropertyDecl *Property,
2201 SourceLocation PropertyLoc) {
2202 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002203 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregore3303542010-04-26 20:47:02 +00002204 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2205 Sema::LookupMemberName);
2206 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002207 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002208 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002209 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002210 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002211 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002212
Douglas Gregore3303542010-04-26 20:47:02 +00002213 if (Result.get())
2214 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002215
John Wiegley429bb272011-04-08 18:41:53 +00002216 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002217 /*FIXME:*/PropertyLoc, IsArrow,
2218 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002219 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002220 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002221 /*TemplateArgs=*/0);
2222 }
Sean Huntc3021132010-05-05 15:23:54 +00002223
John McCall12f78a62010-12-02 01:19:52 +00002224 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002225 ///
2226 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002227 /// Subclasses may override this routine to provide different behavior.
2228 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2229 ObjCMethodDecl *Getter,
2230 ObjCMethodDecl *Setter,
2231 SourceLocation PropertyLoc) {
2232 // Since these expressions can only be value-dependent, we do not
2233 // need to perform semantic analysis again.
2234 return Owned(
2235 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2236 VK_LValue, OK_ObjCProperty,
2237 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002238 }
2239
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002240 /// \brief Build a new Objective-C "isa" expression.
2241 ///
2242 /// By default, performs semantic analysis to build the new expression.
2243 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002244 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002245 bool IsArrow) {
2246 CXXScopeSpec SS;
John Wiegley429bb272011-04-08 18:41:53 +00002247 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002248 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2249 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002250 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002251 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002252 SS, 0, false);
John Wiegley429bb272011-04-08 18:41:53 +00002253 if (Result.isInvalid() || Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002254 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002255
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002256 if (Result.get())
2257 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002258
John Wiegley429bb272011-04-08 18:41:53 +00002259 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002260 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002261 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002262 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002263 /*TemplateArgs=*/0);
2264 }
Sean Huntc3021132010-05-05 15:23:54 +00002265
Douglas Gregorb98b1992009-08-11 05:31:07 +00002266 /// \brief Build a new shuffle vector expression.
2267 ///
2268 /// By default, performs semantic analysis to build the new expression.
2269 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002270 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002271 MultiExprArg SubExprs,
2272 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002273 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002274 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002275 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2276 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2277 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2278 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002279
Douglas Gregorb98b1992009-08-11 05:31:07 +00002280 // Build a reference to the __builtin_shufflevector builtin
2281 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley429bb272011-04-08 18:41:53 +00002282 ExprResult Callee
2283 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2284 VK_LValue, BuiltinLoc));
2285 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2286 if (Callee.isInvalid())
2287 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002288
2289 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002290 unsigned NumSubExprs = SubExprs.size();
2291 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley429bb272011-04-08 18:41:53 +00002292 ExprResult TheCall = SemaRef.Owned(
2293 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002294 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002295 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002296 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley429bb272011-04-08 18:41:53 +00002297 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00002298
Douglas Gregorb98b1992009-08-11 05:31:07 +00002299 // Type-check the __builtin_shufflevector expression.
John Wiegley429bb272011-04-08 18:41:53 +00002300 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00002301 }
John McCall43fed0d2010-11-12 08:19:04 +00002302
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002303 /// \brief Build a new template argument pack expansion.
2304 ///
2305 /// By default, performs semantic analysis to build a new pack expansion
2306 /// for a template argument. Subclasses may override this routine to provide
2307 /// different behavior.
2308 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregorcded4f62011-01-14 17:04:44 +00002309 SourceLocation EllipsisLoc,
2310 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002311 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002312 case TemplateArgument::Expression: {
2313 ExprResult Result
Douglas Gregor67fd1252011-01-14 21:20:45 +00002314 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2315 EllipsisLoc, NumExpansions);
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002316 if (Result.isInvalid())
2317 return TemplateArgumentLoc();
2318
2319 return TemplateArgumentLoc(Result.get(), Result.get());
2320 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002321
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002322 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002323 return TemplateArgumentLoc(TemplateArgument(
2324 Pattern.getArgument().getAsTemplate(),
Douglas Gregor2be29f42011-01-14 23:41:42 +00002325 NumExpansions),
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002326 Pattern.getTemplateQualifierLoc(),
Douglas Gregora7fc9012011-01-05 18:58:31 +00002327 Pattern.getTemplateNameLoc(),
2328 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002329
2330 case TemplateArgument::Null:
2331 case TemplateArgument::Integral:
2332 case TemplateArgument::Declaration:
2333 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002334 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002335 llvm_unreachable("Pack expansion pattern has no parameter packs");
2336
2337 case TemplateArgument::Type:
2338 if (TypeSourceInfo *Expansion
2339 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00002340 EllipsisLoc,
2341 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002342 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2343 Expansion);
2344 break;
2345 }
2346
2347 return TemplateArgumentLoc();
2348 }
2349
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002350 /// \brief Build a new expression pack expansion.
2351 ///
2352 /// By default, performs semantic analysis to build a new pack expansion
2353 /// for an expression. Subclasses may override this routine to provide
2354 /// different behavior.
Douglas Gregor67fd1252011-01-14 21:20:45 +00002355 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2356 llvm::Optional<unsigned> NumExpansions) {
2357 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002358 }
2359
John McCall43fed0d2010-11-12 08:19:04 +00002360private:
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002361 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2362 QualType ObjectType,
2363 NamedDecl *FirstQualifierInScope,
2364 CXXScopeSpec &SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00002365
2366 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2367 QualType ObjectType,
2368 NamedDecl *FirstQualifierInScope,
2369 CXXScopeSpec &SS);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002370};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002371
Douglas Gregor43959a92009-08-20 07:17:43 +00002372template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002373StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002374 if (!S)
2375 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002376
Douglas Gregor43959a92009-08-20 07:17:43 +00002377 switch (S->getStmtClass()) {
2378 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002379
Douglas Gregor43959a92009-08-20 07:17:43 +00002380 // Transform individual statement nodes
2381#define STMT(Node, Parent) \
2382 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCall63c00d72011-02-09 08:16:59 +00002383#define ABSTRACT_STMT(Node)
Douglas Gregor43959a92009-08-20 07:17:43 +00002384#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002385#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002386
Douglas Gregor43959a92009-08-20 07:17:43 +00002387 // Transform expressions by calling TransformExpr.
2388#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002389#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002390#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002391#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002392 {
John McCall60d7b3a2010-08-24 06:29:42 +00002393 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002394 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002395 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002396
John McCall9ae2f072010-08-23 23:25:46 +00002397 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002398 }
Mike Stump1eb44332009-09-09 15:08:12 +00002399 }
2400
John McCall3fa5cae2010-10-26 07:05:15 +00002401 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002402}
Mike Stump1eb44332009-09-09 15:08:12 +00002403
2404
Douglas Gregor670444e2009-08-04 22:27:00 +00002405template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002406ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002407 if (!E)
2408 return SemaRef.Owned(E);
2409
2410 switch (E->getStmtClass()) {
2411 case Stmt::NoStmtClass: break;
2412#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002413#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002414#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002415 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002416#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002417 }
2418
John McCall3fa5cae2010-10-26 07:05:15 +00002419 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002420}
2421
2422template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002423bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2424 unsigned NumInputs,
2425 bool IsCall,
2426 llvm::SmallVectorImpl<Expr *> &Outputs,
2427 bool *ArgChanged) {
2428 for (unsigned I = 0; I != NumInputs; ++I) {
2429 // If requested, drop call arguments that need to be dropped.
2430 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2431 if (ArgChanged)
2432 *ArgChanged = true;
2433
2434 break;
2435 }
2436
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002437 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2438 Expr *Pattern = Expansion->getPattern();
2439
2440 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2441 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2442 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2443
2444 // Determine whether the set of unexpanded parameter packs can and should
2445 // be expanded.
2446 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002447 bool RetainExpansion = false;
Douglas Gregor67fd1252011-01-14 21:20:45 +00002448 llvm::Optional<unsigned> OrigNumExpansions
2449 = Expansion->getNumExpansions();
2450 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002451 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2452 Pattern->getSourceRange(),
2453 Unexpanded.data(),
2454 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002455 Expand, RetainExpansion,
2456 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002457 return true;
2458
2459 if (!Expand) {
2460 // The transform has determined that we should perform a simple
2461 // transformation on the pack expansion, producing another pack
2462 // expansion.
2463 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2464 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2465 if (OutPattern.isInvalid())
2466 return true;
2467
2468 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregor67fd1252011-01-14 21:20:45 +00002469 Expansion->getEllipsisLoc(),
2470 NumExpansions);
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002471 if (Out.isInvalid())
2472 return true;
2473
2474 if (ArgChanged)
2475 *ArgChanged = true;
2476 Outputs.push_back(Out.get());
2477 continue;
2478 }
2479
2480 // The transform has determined that we should perform an elementwise
2481 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00002482 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002483 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2484 ExprResult Out = getDerived().TransformExpr(Pattern);
2485 if (Out.isInvalid())
2486 return true;
2487
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002488 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregor67fd1252011-01-14 21:20:45 +00002489 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2490 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002491 if (Out.isInvalid())
2492 return true;
2493 }
2494
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002495 if (ArgChanged)
2496 *ArgChanged = true;
2497 Outputs.push_back(Out.get());
2498 }
2499
2500 continue;
2501 }
2502
Douglas Gregoraa165f82011-01-03 19:04:46 +00002503 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2504 if (Result.isInvalid())
2505 return true;
2506
2507 if (Result.get() != Inputs[I] && ArgChanged)
2508 *ArgChanged = true;
2509
2510 Outputs.push_back(Result.get());
2511 }
2512
2513 return false;
2514}
2515
2516template<typename Derived>
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002517NestedNameSpecifierLoc
2518TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2519 NestedNameSpecifierLoc NNS,
2520 QualType ObjectType,
2521 NamedDecl *FirstQualifierInScope) {
2522 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2523 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2524 Qualifier = Qualifier.getPrefix())
2525 Qualifiers.push_back(Qualifier);
2526
2527 CXXScopeSpec SS;
2528 while (!Qualifiers.empty()) {
2529 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2530 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2531
2532 switch (QNNS->getKind()) {
2533 case NestedNameSpecifier::Identifier:
2534 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2535 *QNNS->getAsIdentifier(),
2536 Q.getLocalBeginLoc(),
2537 Q.getLocalEndLoc(),
2538 ObjectType, false, SS,
2539 FirstQualifierInScope, false))
2540 return NestedNameSpecifierLoc();
2541
2542 break;
2543
2544 case NestedNameSpecifier::Namespace: {
2545 NamespaceDecl *NS
2546 = cast_or_null<NamespaceDecl>(
2547 getDerived().TransformDecl(
2548 Q.getLocalBeginLoc(),
2549 QNNS->getAsNamespace()));
2550 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2551 break;
2552 }
2553
2554 case NestedNameSpecifier::NamespaceAlias: {
2555 NamespaceAliasDecl *Alias
2556 = cast_or_null<NamespaceAliasDecl>(
2557 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2558 QNNS->getAsNamespaceAlias()));
2559 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2560 Q.getLocalEndLoc());
2561 break;
2562 }
2563
2564 case NestedNameSpecifier::Global:
2565 // There is no meaningful transformation that one could perform on the
2566 // global scope.
2567 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2568 break;
2569
2570 case NestedNameSpecifier::TypeSpecWithTemplate:
2571 case NestedNameSpecifier::TypeSpec: {
2572 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2573 FirstQualifierInScope, SS);
2574
2575 if (!TL)
2576 return NestedNameSpecifierLoc();
2577
2578 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2579 (SemaRef.getLangOptions().CPlusPlus0x &&
2580 TL.getType()->isEnumeralType())) {
2581 assert(!TL.getType().hasLocalQualifiers() &&
2582 "Can't get cv-qualifiers here");
2583 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2584 Q.getLocalEndLoc());
2585 break;
2586 }
Richard Trieu00c93a12011-05-07 01:36:37 +00002587 // If the nested-name-specifier is an invalid type def, don't emit an
2588 // error because a previous error should have already been emitted.
2589 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2590 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2591 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2592 << TL.getType() << SS.getRange();
2593 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002594 return NestedNameSpecifierLoc();
2595 }
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002596 }
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002597
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002598 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002599 FirstQualifierInScope = 0;
Douglas Gregor7c3179c2011-02-28 18:50:33 +00002600 ObjectType = QualType();
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00002601 }
2602
2603 // Don't rebuild the nested-name-specifier if we don't have to.
2604 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2605 !getDerived().AlwaysRebuild())
2606 return NNS;
2607
2608 // If we can re-use the source-location data from the original
2609 // nested-name-specifier, do so.
2610 if (SS.location_size() == NNS.getDataLength() &&
2611 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2612 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2613
2614 // Allocate new nested-name-specifier location information.
2615 return SS.getWithLocInContext(SemaRef.Context);
2616}
2617
2618template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002619DeclarationNameInfo
2620TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002621::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002622 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002623 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002624 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002625
2626 switch (Name.getNameKind()) {
2627 case DeclarationName::Identifier:
2628 case DeclarationName::ObjCZeroArgSelector:
2629 case DeclarationName::ObjCOneArgSelector:
2630 case DeclarationName::ObjCMultiArgSelector:
2631 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002632 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002633 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002634 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002635
Douglas Gregor81499bb2009-09-03 22:13:48 +00002636 case DeclarationName::CXXConstructorName:
2637 case DeclarationName::CXXDestructorName:
2638 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002639 TypeSourceInfo *NewTInfo;
2640 CanQualType NewCanTy;
2641 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002642 NewTInfo = getDerived().TransformType(OldTInfo);
2643 if (!NewTInfo)
2644 return DeclarationNameInfo();
2645 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002646 }
2647 else {
2648 NewTInfo = 0;
2649 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002650 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002651 if (NewT.isNull())
2652 return DeclarationNameInfo();
2653 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2654 }
Mike Stump1eb44332009-09-09 15:08:12 +00002655
Abramo Bagnara25777432010-08-11 22:01:17 +00002656 DeclarationName NewName
2657 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2658 NewCanTy);
2659 DeclarationNameInfo NewNameInfo(NameInfo);
2660 NewNameInfo.setName(NewName);
2661 NewNameInfo.setNamedTypeInfo(NewTInfo);
2662 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002663 }
Mike Stump1eb44332009-09-09 15:08:12 +00002664 }
2665
Abramo Bagnara25777432010-08-11 22:01:17 +00002666 assert(0 && "Unknown name kind.");
2667 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002668}
2669
2670template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002671TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00002672TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2673 TemplateName Name,
2674 SourceLocation NameLoc,
2675 QualType ObjectType,
2676 NamedDecl *FirstQualifierInScope) {
2677 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2678 TemplateDecl *Template = QTN->getTemplateDecl();
2679 assert(Template && "qualified template name must refer to a template");
2680
2681 TemplateDecl *TransTemplate
2682 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2683 Template));
2684 if (!TransTemplate)
2685 return TemplateName();
2686
2687 if (!getDerived().AlwaysRebuild() &&
2688 SS.getScopeRep() == QTN->getQualifier() &&
2689 TransTemplate == Template)
2690 return Name;
2691
2692 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2693 TransTemplate);
2694 }
2695
2696 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2697 if (SS.getScopeRep()) {
2698 // These apply to the scope specifier, not the template.
2699 ObjectType = QualType();
2700 FirstQualifierInScope = 0;
2701 }
2702
2703 if (!getDerived().AlwaysRebuild() &&
2704 SS.getScopeRep() == DTN->getQualifier() &&
2705 ObjectType.isNull())
2706 return Name;
2707
2708 if (DTN->isIdentifier()) {
2709 return getDerived().RebuildTemplateName(SS,
2710 *DTN->getIdentifier(),
2711 NameLoc,
2712 ObjectType,
2713 FirstQualifierInScope);
2714 }
2715
2716 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2717 ObjectType);
2718 }
2719
2720 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2721 TemplateDecl *TransTemplate
2722 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2723 Template));
2724 if (!TransTemplate)
2725 return TemplateName();
2726
2727 if (!getDerived().AlwaysRebuild() &&
2728 TransTemplate == Template)
2729 return Name;
2730
2731 return TemplateName(TransTemplate);
2732 }
2733
2734 if (SubstTemplateTemplateParmPackStorage *SubstPack
2735 = Name.getAsSubstTemplateTemplateParmPack()) {
2736 TemplateTemplateParmDecl *TransParam
2737 = cast_or_null<TemplateTemplateParmDecl>(
2738 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2739 if (!TransParam)
2740 return TemplateName();
2741
2742 if (!getDerived().AlwaysRebuild() &&
2743 TransParam == SubstPack->getParameterPack())
2744 return Name;
2745
2746 return getDerived().RebuildTemplateName(TransParam,
2747 SubstPack->getArgumentPack());
2748 }
2749
2750 // These should be getting filtered out before they reach the AST.
2751 llvm_unreachable("overloaded function decl survived to here");
2752 return TemplateName();
2753}
2754
2755template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002756void TreeTransform<Derived>::InventTemplateArgumentLoc(
2757 const TemplateArgument &Arg,
2758 TemplateArgumentLoc &Output) {
2759 SourceLocation Loc = getDerived().getBaseLocation();
2760 switch (Arg.getKind()) {
2761 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002762 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002763 break;
2764
2765 case TemplateArgument::Type:
2766 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002767 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002768
John McCall833ca992009-10-29 08:12:44 +00002769 break;
2770
Douglas Gregor788cd062009-11-11 01:00:40 +00002771 case TemplateArgument::Template:
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002772 case TemplateArgument::TemplateExpansion: {
2773 NestedNameSpecifierLocBuilder Builder;
2774 TemplateName Template = Arg.getAsTemplate();
2775 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2776 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2777 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2778 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2779
2780 if (Arg.getKind() == TemplateArgument::Template)
2781 Output = TemplateArgumentLoc(Arg,
2782 Builder.getWithLocInContext(SemaRef.Context),
2783 Loc);
2784 else
2785 Output = TemplateArgumentLoc(Arg,
2786 Builder.getWithLocInContext(SemaRef.Context),
2787 Loc, Loc);
2788
Douglas Gregor788cd062009-11-11 01:00:40 +00002789 break;
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002790 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002791
John McCall833ca992009-10-29 08:12:44 +00002792 case TemplateArgument::Expression:
2793 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2794 break;
2795
2796 case TemplateArgument::Declaration:
2797 case TemplateArgument::Integral:
2798 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002799 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002800 break;
2801 }
2802}
2803
2804template<typename Derived>
2805bool TreeTransform<Derived>::TransformTemplateArgument(
2806 const TemplateArgumentLoc &Input,
2807 TemplateArgumentLoc &Output) {
2808 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002809 switch (Arg.getKind()) {
2810 case TemplateArgument::Null:
2811 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002812 Output = Input;
2813 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002814
Douglas Gregor670444e2009-08-04 22:27:00 +00002815 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002816 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002817 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002818 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002819
2820 DI = getDerived().TransformType(DI);
2821 if (!DI) return true;
2822
2823 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2824 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002825 }
Mike Stump1eb44332009-09-09 15:08:12 +00002826
Douglas Gregor670444e2009-08-04 22:27:00 +00002827 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002828 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002829 DeclarationName Name;
2830 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2831 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002832 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002833 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002834 if (!D) return true;
2835
John McCall828bff22009-10-29 18:45:58 +00002836 Expr *SourceExpr = Input.getSourceDeclExpression();
2837 if (SourceExpr) {
2838 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002839 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002840 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002841 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002842 }
2843
2844 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002845 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002846 }
Mike Stump1eb44332009-09-09 15:08:12 +00002847
Douglas Gregor788cd062009-11-11 01:00:40 +00002848 case TemplateArgument::Template: {
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002849 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2850 if (QualifierLoc) {
2851 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2852 if (!QualifierLoc)
2853 return true;
2854 }
2855
Douglas Gregor1d752d72011-03-02 18:46:51 +00002856 CXXScopeSpec SS;
2857 SS.Adopt(QualifierLoc);
Douglas Gregor788cd062009-11-11 01:00:40 +00002858 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00002859 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2860 Input.getTemplateNameLoc());
Douglas Gregor788cd062009-11-11 01:00:40 +00002861 if (Template.isNull())
2862 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002863
Douglas Gregorb6744ef2011-03-02 17:09:35 +00002864 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor788cd062009-11-11 01:00:40 +00002865 Input.getTemplateNameLoc());
2866 return false;
2867 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002868
2869 case TemplateArgument::TemplateExpansion:
2870 llvm_unreachable("Caller should expand pack expansions");
2871
Douglas Gregor670444e2009-08-04 22:27:00 +00002872 case TemplateArgument::Expression: {
2873 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002874 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002875 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002876
John McCall833ca992009-10-29 08:12:44 +00002877 Expr *InputExpr = Input.getSourceExpression();
2878 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2879
Chris Lattner223de242011-04-25 20:37:58 +00002880 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall833ca992009-10-29 08:12:44 +00002881 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002882 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002883 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002884 }
Mike Stump1eb44332009-09-09 15:08:12 +00002885
Douglas Gregor670444e2009-08-04 22:27:00 +00002886 case TemplateArgument::Pack: {
2887 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2888 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002889 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002890 AEnd = Arg.pack_end();
2891 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002892
John McCall833ca992009-10-29 08:12:44 +00002893 // FIXME: preserve source information here when we start
2894 // caring about parameter packs.
2895
John McCall828bff22009-10-29 18:45:58 +00002896 TemplateArgumentLoc InputArg;
2897 TemplateArgumentLoc OutputArg;
2898 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2899 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002900 return true;
2901
John McCall828bff22009-10-29 18:45:58 +00002902 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002903 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002904
2905 TemplateArgument *TransformedArgsPtr
2906 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2907 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2908 TransformedArgsPtr);
2909 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2910 TransformedArgs.size()),
2911 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002912 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002913 }
2914 }
Mike Stump1eb44332009-09-09 15:08:12 +00002915
Douglas Gregor670444e2009-08-04 22:27:00 +00002916 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002917 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002918}
2919
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002920/// \brief Iterator adaptor that invents template argument location information
2921/// for each of the template arguments in its underlying iterator.
2922template<typename Derived, typename InputIterator>
2923class TemplateArgumentLocInventIterator {
2924 TreeTransform<Derived> &Self;
2925 InputIterator Iter;
2926
2927public:
2928 typedef TemplateArgumentLoc value_type;
2929 typedef TemplateArgumentLoc reference;
2930 typedef typename std::iterator_traits<InputIterator>::difference_type
2931 difference_type;
2932 typedef std::input_iterator_tag iterator_category;
2933
2934 class pointer {
2935 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002936
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002937 public:
2938 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2939
2940 const TemplateArgumentLoc *operator->() const { return &Arg; }
2941 };
2942
2943 TemplateArgumentLocInventIterator() { }
2944
2945 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2946 InputIterator Iter)
2947 : Self(Self), Iter(Iter) { }
2948
2949 TemplateArgumentLocInventIterator &operator++() {
2950 ++Iter;
2951 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002952 }
2953
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002954 TemplateArgumentLocInventIterator operator++(int) {
2955 TemplateArgumentLocInventIterator Old(*this);
2956 ++(*this);
2957 return Old;
2958 }
2959
2960 reference operator*() const {
2961 TemplateArgumentLoc Result;
2962 Self.InventTemplateArgumentLoc(*Iter, Result);
2963 return Result;
2964 }
2965
2966 pointer operator->() const { return pointer(**this); }
2967
2968 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2969 const TemplateArgumentLocInventIterator &Y) {
2970 return X.Iter == Y.Iter;
2971 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002972
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002973 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2974 const TemplateArgumentLocInventIterator &Y) {
2975 return X.Iter != Y.Iter;
2976 }
2977};
2978
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002979template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002980template<typename InputIterator>
2981bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2982 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002983 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002984 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002985 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002986 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002987
2988 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2989 // Unpack argument packs, which we translate them into separate
2990 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002991 // FIXME: We could do much better if we could guarantee that the
2992 // TemplateArgumentLocInfo for the pack expansion would be usable for
2993 // all of the template arguments in the argument pack.
2994 typedef TemplateArgumentLocInventIterator<Derived,
2995 TemplateArgument::pack_iterator>
2996 PackLocIterator;
2997 if (TransformTemplateArguments(PackLocIterator(*this,
2998 In.getArgument().pack_begin()),
2999 PackLocIterator(*this,
3000 In.getArgument().pack_end()),
3001 Outputs))
3002 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003003
3004 continue;
3005 }
3006
3007 if (In.getArgument().isPackExpansion()) {
3008 // We have a pack expansion, for which we will be substituting into
3009 // the pattern.
3010 SourceLocation Ellipsis;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003011 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003012 TemplateArgumentLoc Pattern
Douglas Gregorcded4f62011-01-14 17:04:44 +00003013 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3014 getSema().Context);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003015
3016 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3017 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3018 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3019
3020 // Determine whether the set of unexpanded parameter packs can and should
3021 // be expanded.
3022 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00003023 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003024 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003025 if (getDerived().TryExpandParameterPacks(Ellipsis,
3026 Pattern.getSourceRange(),
3027 Unexpanded.data(),
3028 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003029 Expand,
3030 RetainExpansion,
3031 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003032 return true;
3033
3034 if (!Expand) {
3035 // The transform has determined that we should perform a simple
3036 // transformation on the pack expansion, producing another pack
3037 // expansion.
3038 TemplateArgumentLoc OutPattern;
3039 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3040 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3041 return true;
3042
Douglas Gregorcded4f62011-01-14 17:04:44 +00003043 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3044 NumExpansions);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003045 if (Out.getArgument().isNull())
3046 return true;
3047
3048 Outputs.addArgument(Out);
3049 continue;
3050 }
3051
3052 // The transform has determined that we should perform an elementwise
3053 // expansion of the pattern. Do so.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003054 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003055 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3056
3057 if (getDerived().TransformTemplateArgument(Pattern, Out))
3058 return true;
3059
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003060 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregorcded4f62011-01-14 17:04:44 +00003061 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3062 OrigNumExpansions);
Douglas Gregor77d6bb92011-01-11 22:21:24 +00003063 if (Out.getArgument().isNull())
3064 return true;
3065 }
3066
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003067 Outputs.addArgument(Out);
3068 }
3069
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003070 // If we're supposed to retain a pack expansion, do so by temporarily
3071 // forgetting the partially-substituted parameter pack.
3072 if (RetainExpansion) {
3073 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3074
3075 if (getDerived().TransformTemplateArgument(Pattern, Out))
3076 return true;
3077
Douglas Gregorcded4f62011-01-14 17:04:44 +00003078 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3079 OrigNumExpansions);
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003080 if (Out.getArgument().isNull())
3081 return true;
3082
3083 Outputs.addArgument(Out);
3084 }
Douglas Gregord3731192011-01-10 07:32:04 +00003085
Douglas Gregor8491ffe2010-12-20 22:05:00 +00003086 continue;
3087 }
3088
3089 // The simple case:
3090 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00003091 return true;
3092
3093 Outputs.addArgument(Out);
3094 }
3095
3096 return false;
3097
3098}
3099
Douglas Gregor577f75a2009-08-04 16:50:30 +00003100//===----------------------------------------------------------------------===//
3101// Type transformation
3102//===----------------------------------------------------------------------===//
3103
3104template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003105QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00003106 if (getDerived().AlreadyTransformed(T))
3107 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00003108
John McCalla2becad2009-10-21 00:40:46 +00003109 // Temporary workaround. All of these transformations should
3110 // eventually turn into transformations on TypeLocs.
Douglas Gregorc21c7e92011-01-25 19:13:18 +00003111 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3112 getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00003113
John McCall43fed0d2010-11-12 08:19:04 +00003114 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00003115
John McCalla2becad2009-10-21 00:40:46 +00003116 if (!NewDI)
3117 return QualType();
3118
3119 return NewDI->getType();
3120}
3121
3122template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00003123TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00003124 if (getDerived().AlreadyTransformed(DI->getType()))
3125 return DI;
3126
3127 TypeLocBuilder TLB;
3128
3129 TypeLoc TL = DI->getTypeLoc();
3130 TLB.reserve(TL.getFullDataSize());
3131
John McCall43fed0d2010-11-12 08:19:04 +00003132 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00003133 if (Result.isNull())
3134 return 0;
3135
John McCalla93c9342009-12-07 02:54:59 +00003136 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00003137}
3138
3139template<typename Derived>
3140QualType
John McCall43fed0d2010-11-12 08:19:04 +00003141TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003142 switch (T.getTypeLocClass()) {
3143#define ABSTRACT_TYPELOC(CLASS, PARENT)
3144#define TYPELOC(CLASS, PARENT) \
3145 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00003146 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00003147#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00003148 }
Mike Stump1eb44332009-09-09 15:08:12 +00003149
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00003150 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00003151 return QualType();
3152}
3153
3154/// FIXME: By default, this routine adds type qualifiers only to types
3155/// that can have qualifiers, and silently suppresses those qualifiers
3156/// that are not permitted (e.g., qualifiers on reference or function
3157/// types). This is the right thing for template instantiation, but
3158/// probably not for other clients.
3159template<typename Derived>
3160QualType
3161TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003162 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00003163 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00003164
John McCall43fed0d2010-11-12 08:19:04 +00003165 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00003166 if (Result.isNull())
3167 return QualType();
3168
3169 // Silently suppress qualifiers if the result type can't be qualified.
3170 // FIXME: this is the right thing for template instantiation, but
3171 // probably not for other clients.
3172 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00003173 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00003174
John McCallf85e1932011-06-15 23:02:42 +00003175 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore559ca12011-06-17 22:11:49 +00003176 // resulting type.
3177 if (Quals.hasObjCLifetime()) {
3178 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3179 Quals.removeObjCLifetime();
Douglas Gregor4020cae2011-06-17 23:16:24 +00003180 else if (Result.getObjCLifetime()) {
Douglas Gregore559ca12011-06-17 22:11:49 +00003181 // Objective-C ARC:
3182 // A lifetime qualifier applied to a substituted template parameter
3183 // overrides the lifetime qualifier from the template argument.
3184 if (const SubstTemplateTypeParmType *SubstTypeParam
3185 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3186 QualType Replacement = SubstTypeParam->getReplacementType();
3187 Qualifiers Qs = Replacement.getQualifiers();
3188 Qs.removeObjCLifetime();
3189 Replacement
3190 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3191 Qs);
3192 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3193 SubstTypeParam->getReplacedParameter(),
3194 Replacement);
3195 TLB.TypeWasModifiedSafely(Result);
3196 } else {
Douglas Gregor4020cae2011-06-17 23:16:24 +00003197 // Otherwise, complain about the addition of a qualifier to an
3198 // already-qualified type.
3199 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidisb8b03132011-06-24 00:08:59 +00003200 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregor4020cae2011-06-17 23:16:24 +00003201 << Result << R;
3202
Douglas Gregore559ca12011-06-17 22:11:49 +00003203 Quals.removeObjCLifetime();
3204 }
3205 }
3206 }
John McCall28654742010-06-05 06:41:15 +00003207 if (!Quals.empty()) {
3208 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3209 TLB.push<QualifiedTypeLoc>(Result);
3210 // No location information to preserve.
3211 }
John McCalla2becad2009-10-21 00:40:46 +00003212
3213 return Result;
3214}
3215
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003216template<typename Derived>
3217TypeLoc
3218TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3219 QualType ObjectType,
3220 NamedDecl *UnqualLookup,
3221 CXXScopeSpec &SS) {
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003222 QualType T = TL.getType();
3223 if (getDerived().AlreadyTransformed(T))
3224 return TL;
3225
3226 TypeLocBuilder TLB;
3227 QualType Result;
3228
3229 if (isa<TemplateSpecializationType>(T)) {
3230 TemplateSpecializationTypeLoc SpecTL
3231 = cast<TemplateSpecializationTypeLoc>(TL);
3232
3233 TemplateName Template =
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003234 getDerived().TransformTemplateName(SS,
3235 SpecTL.getTypePtr()->getTemplateName(),
3236 SpecTL.getTemplateNameLoc(),
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003237 ObjectType, UnqualLookup);
3238 if (Template.isNull())
3239 return TypeLoc();
3240
3241 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3242 Template);
3243 } else if (isa<DependentTemplateSpecializationType>(T)) {
3244 DependentTemplateSpecializationTypeLoc SpecTL
3245 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3246
Douglas Gregora88f09f2011-02-28 17:23:35 +00003247 TemplateName Template
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003248 = getDerived().RebuildTemplateName(SS,
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003249 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00003250 SpecTL.getNameLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00003251 ObjectType, UnqualLookup);
Douglas Gregora88f09f2011-02-28 17:23:35 +00003252 if (Template.isNull())
3253 return TypeLoc();
3254
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003255 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregora88f09f2011-02-28 17:23:35 +00003256 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003257 Template,
3258 SS);
Douglas Gregorc22b5ff2011-02-25 02:25:35 +00003259 } else {
3260 // Nothing special needs to be done for these.
3261 Result = getDerived().TransformType(TLB, TL);
3262 }
3263
3264 if (Result.isNull())
3265 return TypeLoc();
3266
3267 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3268}
3269
Douglas Gregorb71d8212011-03-02 18:32:08 +00003270template<typename Derived>
3271TypeSourceInfo *
3272TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3273 QualType ObjectType,
3274 NamedDecl *UnqualLookup,
3275 CXXScopeSpec &SS) {
3276 // FIXME: Painfully copy-paste from the above!
3277
3278 QualType T = TSInfo->getType();
3279 if (getDerived().AlreadyTransformed(T))
3280 return TSInfo;
3281
3282 TypeLocBuilder TLB;
3283 QualType Result;
3284
3285 TypeLoc TL = TSInfo->getTypeLoc();
3286 if (isa<TemplateSpecializationType>(T)) {
3287 TemplateSpecializationTypeLoc SpecTL
3288 = cast<TemplateSpecializationTypeLoc>(TL);
3289
3290 TemplateName Template
3291 = getDerived().TransformTemplateName(SS,
3292 SpecTL.getTypePtr()->getTemplateName(),
3293 SpecTL.getTemplateNameLoc(),
3294 ObjectType, UnqualLookup);
3295 if (Template.isNull())
3296 return 0;
3297
3298 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3299 Template);
3300 } else if (isa<DependentTemplateSpecializationType>(T)) {
3301 DependentTemplateSpecializationTypeLoc SpecTL
3302 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3303
3304 TemplateName Template
3305 = getDerived().RebuildTemplateName(SS,
3306 *SpecTL.getTypePtr()->getIdentifier(),
3307 SpecTL.getNameLoc(),
3308 ObjectType, UnqualLookup);
3309 if (Template.isNull())
3310 return 0;
3311
3312 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3313 SpecTL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00003314 Template,
3315 SS);
Douglas Gregorb71d8212011-03-02 18:32:08 +00003316 } else {
3317 // Nothing special needs to be done for these.
3318 Result = getDerived().TransformType(TLB, TL);
3319 }
3320
3321 if (Result.isNull())
3322 return 0;
3323
3324 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3325}
3326
John McCalla2becad2009-10-21 00:40:46 +00003327template <class TyLoc> static inline
3328QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3329 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3330 NewT.setNameLoc(T.getNameLoc());
3331 return T.getType();
3332}
3333
John McCalla2becad2009-10-21 00:40:46 +00003334template<typename Derived>
3335QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003336 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003337 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3338 NewT.setBuiltinLoc(T.getBuiltinLoc());
3339 if (T.needsExtraLocalData())
3340 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3341 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003342}
Mike Stump1eb44332009-09-09 15:08:12 +00003343
Douglas Gregor577f75a2009-08-04 16:50:30 +00003344template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003345QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003346 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003347 // FIXME: recurse?
3348 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003349}
Mike Stump1eb44332009-09-09 15:08:12 +00003350
Douglas Gregor577f75a2009-08-04 16:50:30 +00003351template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003352QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003353 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003354 QualType PointeeType
3355 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003356 if (PointeeType.isNull())
3357 return QualType();
3358
3359 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003360 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003361 // A dependent pointer type 'T *' has is being transformed such
3362 // that an Objective-C class type is being replaced for 'T'. The
3363 // resulting pointer type is an ObjCObjectPointerType, not a
3364 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003365 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003366
John McCallc12c5bb2010-05-15 11:32:37 +00003367 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3368 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003369 return Result;
3370 }
John McCall43fed0d2010-11-12 08:19:04 +00003371
Douglas Gregor92e986e2010-04-22 16:44:27 +00003372 if (getDerived().AlwaysRebuild() ||
3373 PointeeType != TL.getPointeeLoc().getType()) {
3374 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3375 if (Result.isNull())
3376 return QualType();
3377 }
John McCallf85e1932011-06-15 23:02:42 +00003378
3379 // Objective-C ARC can add lifetime qualifiers to the type that we're
3380 // pointing to.
3381 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3382
Douglas Gregor92e986e2010-04-22 16:44:27 +00003383 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3384 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003385 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003386}
Mike Stump1eb44332009-09-09 15:08:12 +00003387
3388template<typename Derived>
3389QualType
John McCalla2becad2009-10-21 00:40:46 +00003390TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003391 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003392 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003393 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3394 if (PointeeType.isNull())
3395 return QualType();
3396
3397 QualType Result = TL.getType();
3398 if (getDerived().AlwaysRebuild() ||
3399 PointeeType != TL.getPointeeLoc().getType()) {
3400 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003401 TL.getSigilLoc());
3402 if (Result.isNull())
3403 return QualType();
3404 }
3405
Douglas Gregor39968ad2010-04-22 16:50:51 +00003406 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003407 NewT.setSigilLoc(TL.getSigilLoc());
3408 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003409}
3410
John McCall85737a72009-10-30 00:06:24 +00003411/// Transforms a reference type. Note that somewhat paradoxically we
3412/// don't care whether the type itself is an l-value type or an r-value
3413/// type; we only care if the type was *written* as an l-value type
3414/// or an r-value type.
3415template<typename Derived>
3416QualType
3417TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003418 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003419 const ReferenceType *T = TL.getTypePtr();
3420
3421 // Note that this works with the pointee-as-written.
3422 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3423 if (PointeeType.isNull())
3424 return QualType();
3425
3426 QualType Result = TL.getType();
3427 if (getDerived().AlwaysRebuild() ||
3428 PointeeType != T->getPointeeTypeAsWritten()) {
3429 Result = getDerived().RebuildReferenceType(PointeeType,
3430 T->isSpelledAsLValue(),
3431 TL.getSigilLoc());
3432 if (Result.isNull())
3433 return QualType();
3434 }
3435
John McCallf85e1932011-06-15 23:02:42 +00003436 // Objective-C ARC can add lifetime qualifiers to the type that we're
3437 // referring to.
3438 TLB.TypeWasModifiedSafely(
3439 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3440
John McCall85737a72009-10-30 00:06:24 +00003441 // r-value references can be rebuilt as l-value references.
3442 ReferenceTypeLoc NewTL;
3443 if (isa<LValueReferenceType>(Result))
3444 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3445 else
3446 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3447 NewTL.setSigilLoc(TL.getSigilLoc());
3448
3449 return Result;
3450}
3451
Mike Stump1eb44332009-09-09 15:08:12 +00003452template<typename Derived>
3453QualType
John McCalla2becad2009-10-21 00:40:46 +00003454TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003455 LValueReferenceTypeLoc TL) {
3456 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003457}
3458
Mike Stump1eb44332009-09-09 15:08:12 +00003459template<typename Derived>
3460QualType
John McCalla2becad2009-10-21 00:40:46 +00003461TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003462 RValueReferenceTypeLoc TL) {
3463 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003464}
Mike Stump1eb44332009-09-09 15:08:12 +00003465
Douglas Gregor577f75a2009-08-04 16:50:30 +00003466template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003467QualType
John McCalla2becad2009-10-21 00:40:46 +00003468TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003469 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003470 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003471 if (PointeeType.isNull())
3472 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003473
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003474 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3475 TypeSourceInfo* NewClsTInfo = 0;
3476 if (OldClsTInfo) {
3477 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3478 if (!NewClsTInfo)
3479 return QualType();
3480 }
3481
3482 const MemberPointerType *T = TL.getTypePtr();
3483 QualType OldClsType = QualType(T->getClass(), 0);
3484 QualType NewClsType;
3485 if (NewClsTInfo)
3486 NewClsType = NewClsTInfo->getType();
3487 else {
3488 NewClsType = getDerived().TransformType(OldClsType);
3489 if (NewClsType.isNull())
3490 return QualType();
3491 }
Mike Stump1eb44332009-09-09 15:08:12 +00003492
John McCalla2becad2009-10-21 00:40:46 +00003493 QualType Result = TL.getType();
3494 if (getDerived().AlwaysRebuild() ||
3495 PointeeType != T->getPointeeType() ||
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003496 NewClsType != OldClsType) {
3497 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall85737a72009-10-30 00:06:24 +00003498 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003499 if (Result.isNull())
3500 return QualType();
3501 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003502
John McCalla2becad2009-10-21 00:40:46 +00003503 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3504 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnarab6ab6c12011-03-05 14:42:21 +00003505 NewTL.setClassTInfo(NewClsTInfo);
John McCalla2becad2009-10-21 00:40:46 +00003506
3507 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003508}
3509
Mike Stump1eb44332009-09-09 15:08:12 +00003510template<typename Derived>
3511QualType
John McCalla2becad2009-10-21 00:40:46 +00003512TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003513 ConstantArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003514 const ConstantArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003515 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003516 if (ElementType.isNull())
3517 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003518
John McCalla2becad2009-10-21 00:40:46 +00003519 QualType Result = TL.getType();
3520 if (getDerived().AlwaysRebuild() ||
3521 ElementType != T->getElementType()) {
3522 Result = getDerived().RebuildConstantArrayType(ElementType,
3523 T->getSizeModifier(),
3524 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003525 T->getIndexTypeCVRQualifiers(),
3526 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003527 if (Result.isNull())
3528 return QualType();
3529 }
Sean Huntc3021132010-05-05 15:23:54 +00003530
John McCalla2becad2009-10-21 00:40:46 +00003531 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3532 NewTL.setLBracketLoc(TL.getLBracketLoc());
3533 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003534
John McCalla2becad2009-10-21 00:40:46 +00003535 Expr *Size = TL.getSizeExpr();
3536 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003537 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003538 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3539 }
3540 NewTL.setSizeExpr(Size);
3541
3542 return Result;
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>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003546QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003547 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003548 IncompleteArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003549 const IncompleteArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003550 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003551 if (ElementType.isNull())
3552 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003553
John McCalla2becad2009-10-21 00:40:46 +00003554 QualType Result = TL.getType();
3555 if (getDerived().AlwaysRebuild() ||
3556 ElementType != T->getElementType()) {
3557 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003558 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003559 T->getIndexTypeCVRQualifiers(),
3560 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003561 if (Result.isNull())
3562 return QualType();
3563 }
Sean Huntc3021132010-05-05 15:23:54 +00003564
John McCalla2becad2009-10-21 00:40:46 +00003565 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3566 NewTL.setLBracketLoc(TL.getLBracketLoc());
3567 NewTL.setRBracketLoc(TL.getRBracketLoc());
3568 NewTL.setSizeExpr(0);
3569
3570 return Result;
3571}
3572
3573template<typename Derived>
3574QualType
3575TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003576 VariableArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003577 const VariableArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003578 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3579 if (ElementType.isNull())
3580 return QualType();
3581
3582 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003583 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003584
John McCall60d7b3a2010-08-24 06:29:42 +00003585 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003586 = getDerived().TransformExpr(T->getSizeExpr());
3587 if (SizeResult.isInvalid())
3588 return QualType();
3589
John McCall9ae2f072010-08-23 23:25:46 +00003590 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003591
3592 QualType Result = TL.getType();
3593 if (getDerived().AlwaysRebuild() ||
3594 ElementType != T->getElementType() ||
3595 Size != T->getSizeExpr()) {
3596 Result = getDerived().RebuildVariableArrayType(ElementType,
3597 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003598 Size,
John McCalla2becad2009-10-21 00:40:46 +00003599 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003600 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003601 if (Result.isNull())
3602 return QualType();
3603 }
Sean Huntc3021132010-05-05 15:23:54 +00003604
John McCalla2becad2009-10-21 00:40:46 +00003605 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3606 NewTL.setLBracketLoc(TL.getLBracketLoc());
3607 NewTL.setRBracketLoc(TL.getRBracketLoc());
3608 NewTL.setSizeExpr(Size);
3609
3610 return Result;
3611}
3612
3613template<typename Derived>
3614QualType
3615TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003616 DependentSizedArrayTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003617 const DependentSizedArrayType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003618 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3619 if (ElementType.isNull())
3620 return QualType();
3621
3622 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003623 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003624
John McCall3b657512011-01-19 10:06:00 +00003625 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3626 Expr *origSize = TL.getSizeExpr();
3627 if (!origSize) origSize = T->getSizeExpr();
3628
3629 ExprResult sizeResult
3630 = getDerived().TransformExpr(origSize);
3631 if (sizeResult.isInvalid())
John McCalla2becad2009-10-21 00:40:46 +00003632 return QualType();
3633
John McCall3b657512011-01-19 10:06:00 +00003634 Expr *size = sizeResult.get();
John McCalla2becad2009-10-21 00:40:46 +00003635
3636 QualType Result = TL.getType();
3637 if (getDerived().AlwaysRebuild() ||
3638 ElementType != T->getElementType() ||
John McCall3b657512011-01-19 10:06:00 +00003639 size != origSize) {
John McCalla2becad2009-10-21 00:40:46 +00003640 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3641 T->getSizeModifier(),
John McCall3b657512011-01-19 10:06:00 +00003642 size,
John McCalla2becad2009-10-21 00:40:46 +00003643 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003644 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003645 if (Result.isNull())
3646 return QualType();
3647 }
John McCalla2becad2009-10-21 00:40:46 +00003648
3649 // We might have any sort of array type now, but fortunately they
3650 // all have the same location layout.
3651 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3652 NewTL.setLBracketLoc(TL.getLBracketLoc());
3653 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall3b657512011-01-19 10:06:00 +00003654 NewTL.setSizeExpr(size);
John McCalla2becad2009-10-21 00:40:46 +00003655
3656 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003657}
Mike Stump1eb44332009-09-09 15:08:12 +00003658
3659template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003660QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003661 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003662 DependentSizedExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003663 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003664
3665 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003666 QualType ElementType = getDerived().TransformType(T->getElementType());
3667 if (ElementType.isNull())
3668 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003669
Douglas Gregor670444e2009-08-04 22:27:00 +00003670 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003671 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003672
John McCall60d7b3a2010-08-24 06:29:42 +00003673 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003674 if (Size.isInvalid())
3675 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003676
John McCalla2becad2009-10-21 00:40:46 +00003677 QualType Result = TL.getType();
3678 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003679 ElementType != T->getElementType() ||
3680 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003681 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003682 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003683 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003684 if (Result.isNull())
3685 return QualType();
3686 }
John McCalla2becad2009-10-21 00:40:46 +00003687
3688 // Result might be dependent or not.
3689 if (isa<DependentSizedExtVectorType>(Result)) {
3690 DependentSizedExtVectorTypeLoc NewTL
3691 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3692 NewTL.setNameLoc(TL.getNameLoc());
3693 } else {
3694 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3695 NewTL.setNameLoc(TL.getNameLoc());
3696 }
3697
3698 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003699}
Mike Stump1eb44332009-09-09 15:08:12 +00003700
3701template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003702QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003703 VectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003704 const VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003705 QualType ElementType = getDerived().TransformType(T->getElementType());
3706 if (ElementType.isNull())
3707 return QualType();
3708
John McCalla2becad2009-10-21 00:40:46 +00003709 QualType Result = TL.getType();
3710 if (getDerived().AlwaysRebuild() ||
3711 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003712 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003713 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003714 if (Result.isNull())
3715 return QualType();
3716 }
Sean Huntc3021132010-05-05 15:23:54 +00003717
John McCalla2becad2009-10-21 00:40:46 +00003718 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3719 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003720
John McCalla2becad2009-10-21 00:40:46 +00003721 return Result;
3722}
3723
3724template<typename Derived>
3725QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003726 ExtVectorTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00003727 const VectorType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00003728 QualType ElementType = getDerived().TransformType(T->getElementType());
3729 if (ElementType.isNull())
3730 return QualType();
3731
3732 QualType Result = TL.getType();
3733 if (getDerived().AlwaysRebuild() ||
3734 ElementType != T->getElementType()) {
3735 Result = getDerived().RebuildExtVectorType(ElementType,
3736 T->getNumElements(),
3737 /*FIXME*/ SourceLocation());
3738 if (Result.isNull())
3739 return QualType();
3740 }
Sean Huntc3021132010-05-05 15:23:54 +00003741
John McCalla2becad2009-10-21 00:40:46 +00003742 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3743 NewTL.setNameLoc(TL.getNameLoc());
3744
3745 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003746}
Mike Stump1eb44332009-09-09 15:08:12 +00003747
3748template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003749ParmVarDecl *
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003750TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003751 int indexAdjustment,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003752 llvm::Optional<unsigned> NumExpansions) {
John McCall21ef0fa2010-03-11 09:03:00 +00003753 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003754 TypeSourceInfo *NewDI = 0;
3755
3756 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3757 // If we're substituting into a pack expansion type and we know the
3758 TypeLoc OldTL = OldDI->getTypeLoc();
3759 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3760
3761 TypeLocBuilder TLB;
3762 TypeLoc NewTL = OldDI->getTypeLoc();
3763 TLB.reserve(NewTL.getFullDataSize());
3764
3765 QualType Result = getDerived().TransformType(TLB,
3766 OldExpansionTL.getPatternLoc());
3767 if (Result.isNull())
3768 return 0;
3769
3770 Result = RebuildPackExpansionType(Result,
3771 OldExpansionTL.getPatternLoc().getSourceRange(),
3772 OldExpansionTL.getEllipsisLoc(),
3773 NumExpansions);
3774 if (Result.isNull())
3775 return 0;
3776
3777 PackExpansionTypeLoc NewExpansionTL
3778 = TLB.push<PackExpansionTypeLoc>(Result);
3779 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3780 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3781 } else
3782 NewDI = getDerived().TransformType(OldDI);
John McCall21ef0fa2010-03-11 09:03:00 +00003783 if (!NewDI)
3784 return 0;
3785
John McCallfb44de92011-05-01 22:35:37 +00003786 if (NewDI == OldDI && indexAdjustment == 0)
John McCall21ef0fa2010-03-11 09:03:00 +00003787 return OldParm;
John McCallfb44de92011-05-01 22:35:37 +00003788
3789 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3790 OldParm->getDeclContext(),
3791 OldParm->getInnerLocStart(),
3792 OldParm->getLocation(),
3793 OldParm->getIdentifier(),
3794 NewDI->getType(),
3795 NewDI,
3796 OldParm->getStorageClass(),
3797 OldParm->getStorageClassAsWritten(),
3798 /* DefArg */ NULL);
3799 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3800 OldParm->getFunctionScopeIndex() + indexAdjustment);
3801 return newParm;
John McCall21ef0fa2010-03-11 09:03:00 +00003802}
3803
3804template<typename Derived>
3805bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003806 TransformFunctionTypeParams(SourceLocation Loc,
3807 ParmVarDecl **Params, unsigned NumParams,
3808 const QualType *ParamTypes,
3809 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3810 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCallfb44de92011-05-01 22:35:37 +00003811 int indexAdjustment = 0;
3812
Douglas Gregora009b592011-01-07 00:20:55 +00003813 for (unsigned i = 0; i != NumParams; ++i) {
3814 if (ParmVarDecl *OldParm = Params[i]) {
John McCallfb44de92011-05-01 22:35:37 +00003815 assert(OldParm->getFunctionScopeIndex() == i);
3816
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003817 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003818 ParmVarDecl *NewParm = 0;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003819 if (OldParm->isParameterPack()) {
3820 // We have a function parameter pack that may need to be expanded.
3821 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003822
Douglas Gregor603cfb42011-01-05 23:12:31 +00003823 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003824 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3825 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3826 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3827 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor406f98f2011-03-02 02:04:06 +00003828 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3829
Douglas Gregor603cfb42011-01-05 23:12:31 +00003830 // Determine whether we should expand the parameter packs.
3831 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003832 bool RetainExpansion = false;
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003833 llvm::Optional<unsigned> OrigNumExpansions
3834 = ExpansionTL.getTypePtr()->getNumExpansions();
3835 NumExpansions = OrigNumExpansions;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003836 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3837 Pattern.getSourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003838 Unexpanded.data(),
3839 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003840 ShouldExpand,
3841 RetainExpansion,
3842 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003843 return true;
3844 }
3845
3846 if (ShouldExpand) {
3847 // Expand the function parameter pack into multiple, separate
3848 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003849 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregorcded4f62011-01-14 17:04:44 +00003850 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003851 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3852 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003853 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003854 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003855 OrigNumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003856 if (!NewParm)
3857 return true;
3858
Douglas Gregora009b592011-01-07 00:20:55 +00003859 OutParamTypes.push_back(NewParm->getType());
3860 if (PVars)
3861 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003862 }
Douglas Gregord3731192011-01-10 07:32:04 +00003863
3864 // If we're supposed to retain a pack expansion, do so by temporarily
3865 // forgetting the partially-substituted parameter pack.
3866 if (RetainExpansion) {
3867 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3868 ParmVarDecl *NewParm
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003869 = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003870 indexAdjustment++,
Douglas Gregor6a24bfd2011-01-14 22:40:04 +00003871 OrigNumExpansions);
Douglas Gregord3731192011-01-10 07:32:04 +00003872 if (!NewParm)
3873 return true;
3874
3875 OutParamTypes.push_back(NewParm->getType());
3876 if (PVars)
3877 PVars->push_back(NewParm);
3878 }
3879
John McCallfb44de92011-05-01 22:35:37 +00003880 // The next parameter should have the same adjustment as the
3881 // last thing we pushed, but we post-incremented indexAdjustment
3882 // on every push. Also, if we push nothing, the adjustment should
3883 // go down by one.
3884 indexAdjustment--;
3885
Douglas Gregor603cfb42011-01-05 23:12:31 +00003886 // We're done with the pack expansion.
3887 continue;
3888 }
3889
3890 // We'll substitute the parameter now without expanding the pack
3891 // expansion.
Douglas Gregor406f98f2011-03-02 02:04:06 +00003892 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3893 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003894 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003895 NumExpansions);
3896 } else {
3897 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCallfb44de92011-05-01 22:35:37 +00003898 indexAdjustment,
Douglas Gregor406f98f2011-03-02 02:04:06 +00003899 llvm::Optional<unsigned>());
Douglas Gregor603cfb42011-01-05 23:12:31 +00003900 }
Douglas Gregor406f98f2011-03-02 02:04:06 +00003901
John McCall21ef0fa2010-03-11 09:03:00 +00003902 if (!NewParm)
3903 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003904
Douglas Gregora009b592011-01-07 00:20:55 +00003905 OutParamTypes.push_back(NewParm->getType());
3906 if (PVars)
3907 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003908 continue;
3909 }
John McCall21ef0fa2010-03-11 09:03:00 +00003910
3911 // Deal with the possibility that we don't have a parameter
3912 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003913 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003914 bool IsPackExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00003915 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003916 QualType NewType;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003917 if (const PackExpansionType *Expansion
3918 = dyn_cast<PackExpansionType>(OldType)) {
3919 // We have a function parameter pack that may need to be expanded.
3920 QualType Pattern = Expansion->getPattern();
3921 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3922 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3923
3924 // Determine whether we should expand the parameter packs.
3925 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003926 bool RetainExpansion = false;
Douglas Gregora009b592011-01-07 00:20:55 +00003927 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003928 Unexpanded.data(),
3929 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003930 ShouldExpand,
3931 RetainExpansion,
3932 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003933 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003934 }
3935
3936 if (ShouldExpand) {
3937 // Expand the function parameter pack into multiple, separate
3938 // parameters.
Douglas Gregorcded4f62011-01-14 17:04:44 +00003939 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003940 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3941 QualType NewType = getDerived().TransformType(Pattern);
3942 if (NewType.isNull())
3943 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003944
Douglas Gregora009b592011-01-07 00:20:55 +00003945 OutParamTypes.push_back(NewType);
3946 if (PVars)
3947 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003948 }
3949
3950 // We're done with the pack expansion.
3951 continue;
3952 }
3953
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003954 // If we're supposed to retain a pack expansion, do so by temporarily
3955 // forgetting the partially-substituted parameter pack.
3956 if (RetainExpansion) {
3957 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3958 QualType NewType = getDerived().TransformType(Pattern);
3959 if (NewType.isNull())
3960 return true;
3961
3962 OutParamTypes.push_back(NewType);
3963 if (PVars)
3964 PVars->push_back(0);
3965 }
Douglas Gregord3731192011-01-10 07:32:04 +00003966
Douglas Gregor603cfb42011-01-05 23:12:31 +00003967 // We'll substitute the parameter now without expanding the pack
3968 // expansion.
3969 OldType = Expansion->getPattern();
3970 IsPackExpansion = true;
Douglas Gregor406f98f2011-03-02 02:04:06 +00003971 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3972 NewType = getDerived().TransformType(OldType);
3973 } else {
3974 NewType = getDerived().TransformType(OldType);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003975 }
3976
Douglas Gregor603cfb42011-01-05 23:12:31 +00003977 if (NewType.isNull())
3978 return true;
3979
3980 if (IsPackExpansion)
Douglas Gregorcded4f62011-01-14 17:04:44 +00003981 NewType = getSema().Context.getPackExpansionType(NewType,
3982 NumExpansions);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003983
Douglas Gregora009b592011-01-07 00:20:55 +00003984 OutParamTypes.push_back(NewType);
3985 if (PVars)
3986 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00003987 }
3988
John McCallfb44de92011-05-01 22:35:37 +00003989#ifndef NDEBUG
3990 if (PVars) {
3991 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
3992 if (ParmVarDecl *parm = (*PVars)[i])
3993 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003994 }
John McCallfb44de92011-05-01 22:35:37 +00003995#endif
3996
3997 return false;
3998}
John McCall21ef0fa2010-03-11 09:03:00 +00003999
4000template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00004001QualType
John McCalla2becad2009-10-21 00:40:46 +00004002TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004003 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00004004 // Transform the parameters and return type.
4005 //
4006 // We instantiate in source order, with the return type first followed by
4007 // the parameters, because users tend to expect this (even if they shouldn't
4008 // rely on it!).
4009 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00004010 // When the function has a trailing return type, we instantiate the
4011 // parameters before the return type, since the return type can then refer
4012 // to the parameters themselves (via decltype, sizeof, etc.).
4013 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00004014 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00004015 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCallf4c73712011-01-19 06:33:43 +00004016 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00004017
Douglas Gregordab60ad2010-10-01 18:44:50 +00004018 QualType ResultType;
4019
4020 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00004021 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4022 TL.getParmArray(),
4023 TL.getNumArgs(),
4024 TL.getTypePtr()->arg_type_begin(),
4025 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004026 return QualType();
4027
4028 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4029 if (ResultType.isNull())
4030 return QualType();
4031 }
4032 else {
4033 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4034 if (ResultType.isNull())
4035 return QualType();
4036
Douglas Gregora009b592011-01-07 00:20:55 +00004037 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4038 TL.getParmArray(),
4039 TL.getNumArgs(),
4040 TL.getTypePtr()->arg_type_begin(),
4041 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00004042 return QualType();
4043 }
4044
John McCalla2becad2009-10-21 00:40:46 +00004045 QualType Result = TL.getType();
4046 if (getDerived().AlwaysRebuild() ||
4047 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00004048 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00004049 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4050 Result = getDerived().RebuildFunctionProtoType(ResultType,
4051 ParamTypes.data(),
4052 ParamTypes.size(),
4053 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004054 T->getTypeQuals(),
Douglas Gregorc938c162011-01-26 05:01:58 +00004055 T->getRefQualifier(),
Eli Friedmanfa869542010-08-05 02:54:05 +00004056 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00004057 if (Result.isNull())
4058 return QualType();
4059 }
Mike Stump1eb44332009-09-09 15:08:12 +00004060
John McCalla2becad2009-10-21 00:40:46 +00004061 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004062 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4063 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004064 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00004065 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4066 NewTL.setArg(i, ParamDecls[i]);
4067
4068 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004069}
Mike Stump1eb44332009-09-09 15:08:12 +00004070
Douglas Gregor577f75a2009-08-04 16:50:30 +00004071template<typename Derived>
4072QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00004073 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004074 FunctionNoProtoTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004075 const FunctionNoProtoType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004076 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4077 if (ResultType.isNull())
4078 return QualType();
4079
4080 QualType Result = TL.getType();
4081 if (getDerived().AlwaysRebuild() ||
4082 ResultType != T->getResultType())
4083 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4084
4085 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnara796aa442011-03-12 11:17:06 +00004086 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4087 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregordab60ad2010-10-01 18:44:50 +00004088 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00004089
4090 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004091}
Mike Stump1eb44332009-09-09 15:08:12 +00004092
John McCalled976492009-12-04 22:46:56 +00004093template<typename Derived> QualType
4094TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004095 UnresolvedUsingTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004096 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004097 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00004098 if (!D)
4099 return QualType();
4100
4101 QualType Result = TL.getType();
4102 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4103 Result = getDerived().RebuildUnresolvedUsingType(D);
4104 if (Result.isNull())
4105 return QualType();
4106 }
4107
4108 // We might get an arbitrary type spec type back. We should at
4109 // least always get a type spec type, though.
4110 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4111 NewTL.setNameLoc(TL.getNameLoc());
4112
4113 return Result;
4114}
4115
Douglas Gregor577f75a2009-08-04 16:50:30 +00004116template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004117QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004118 TypedefTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004119 const TypedefType *T = TL.getTypePtr();
Richard Smith162e1c12011-04-15 14:24:37 +00004120 TypedefNameDecl *Typedef
4121 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4122 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004123 if (!Typedef)
4124 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004125
John McCalla2becad2009-10-21 00:40:46 +00004126 QualType Result = TL.getType();
4127 if (getDerived().AlwaysRebuild() ||
4128 Typedef != T->getDecl()) {
4129 Result = getDerived().RebuildTypedefType(Typedef);
4130 if (Result.isNull())
4131 return QualType();
4132 }
Mike Stump1eb44332009-09-09 15:08:12 +00004133
John McCalla2becad2009-10-21 00:40:46 +00004134 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4135 NewTL.setNameLoc(TL.getNameLoc());
4136
4137 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004138}
Mike Stump1eb44332009-09-09 15:08:12 +00004139
Douglas Gregor577f75a2009-08-04 16:50:30 +00004140template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004141QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004142 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00004143 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004144 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004145
John McCall60d7b3a2010-08-24 06:29:42 +00004146 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004147 if (E.isInvalid())
4148 return QualType();
4149
John McCalla2becad2009-10-21 00:40:46 +00004150 QualType Result = TL.getType();
4151 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00004152 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004153 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00004154 if (Result.isNull())
4155 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004156 }
John McCalla2becad2009-10-21 00:40:46 +00004157 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004158
John McCalla2becad2009-10-21 00:40:46 +00004159 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004160 NewTL.setTypeofLoc(TL.getTypeofLoc());
4161 NewTL.setLParenLoc(TL.getLParenLoc());
4162 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00004163
4164 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004165}
Mike Stump1eb44332009-09-09 15:08:12 +00004166
4167template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004168QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004169 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00004170 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4171 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4172 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004173 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004174
John McCalla2becad2009-10-21 00:40:46 +00004175 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00004176 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4177 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00004178 if (Result.isNull())
4179 return QualType();
4180 }
Mike Stump1eb44332009-09-09 15:08:12 +00004181
John McCalla2becad2009-10-21 00:40:46 +00004182 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00004183 NewTL.setTypeofLoc(TL.getTypeofLoc());
4184 NewTL.setLParenLoc(TL.getLParenLoc());
4185 NewTL.setRParenLoc(TL.getRParenLoc());
4186 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00004187
4188 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004189}
Mike Stump1eb44332009-09-09 15:08:12 +00004190
4191template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004192QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004193 DecltypeTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004194 const DecltypeType *T = TL.getTypePtr();
John McCalla2becad2009-10-21 00:40:46 +00004195
Douglas Gregor670444e2009-08-04 22:27:00 +00004196 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00004197 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004198
John McCall60d7b3a2010-08-24 06:29:42 +00004199 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004200 if (E.isInvalid())
4201 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004202
John McCalla2becad2009-10-21 00:40:46 +00004203 QualType Result = TL.getType();
4204 if (getDerived().AlwaysRebuild() ||
4205 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00004206 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004207 if (Result.isNull())
4208 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004209 }
John McCalla2becad2009-10-21 00:40:46 +00004210 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00004211
John McCalla2becad2009-10-21 00:40:46 +00004212 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4213 NewTL.setNameLoc(TL.getNameLoc());
4214
4215 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004216}
4217
4218template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00004219QualType TreeTransform<Derived>::TransformUnaryTransformType(
4220 TypeLocBuilder &TLB,
4221 UnaryTransformTypeLoc TL) {
4222 QualType Result = TL.getType();
4223 if (Result->isDependentType()) {
4224 const UnaryTransformType *T = TL.getTypePtr();
4225 QualType NewBase =
4226 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4227 Result = getDerived().RebuildUnaryTransformType(NewBase,
4228 T->getUTTKind(),
4229 TL.getKWLoc());
4230 if (Result.isNull())
4231 return QualType();
4232 }
4233
4234 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4235 NewTL.setKWLoc(TL.getKWLoc());
4236 NewTL.setParensRange(TL.getParensRange());
4237 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4238 return Result;
4239}
4240
4241template<typename Derived>
Richard Smith34b41d92011-02-20 03:19:35 +00004242QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4243 AutoTypeLoc TL) {
4244 const AutoType *T = TL.getTypePtr();
4245 QualType OldDeduced = T->getDeducedType();
4246 QualType NewDeduced;
4247 if (!OldDeduced.isNull()) {
4248 NewDeduced = getDerived().TransformType(OldDeduced);
4249 if (NewDeduced.isNull())
4250 return QualType();
4251 }
4252
4253 QualType Result = TL.getType();
4254 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4255 Result = getDerived().RebuildAutoType(NewDeduced);
4256 if (Result.isNull())
4257 return QualType();
4258 }
4259
4260 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4261 NewTL.setNameLoc(TL.getNameLoc());
4262
4263 return Result;
4264}
4265
4266template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004267QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004268 RecordTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004269 const RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004270 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004271 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4272 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004273 if (!Record)
4274 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004275
John McCalla2becad2009-10-21 00:40:46 +00004276 QualType Result = TL.getType();
4277 if (getDerived().AlwaysRebuild() ||
4278 Record != T->getDecl()) {
4279 Result = getDerived().RebuildRecordType(Record);
4280 if (Result.isNull())
4281 return QualType();
4282 }
Mike Stump1eb44332009-09-09 15:08:12 +00004283
John McCalla2becad2009-10-21 00:40:46 +00004284 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4285 NewTL.setNameLoc(TL.getNameLoc());
4286
4287 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004288}
Mike Stump1eb44332009-09-09 15:08:12 +00004289
4290template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004291QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004292 EnumTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004293 const EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004294 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00004295 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4296 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00004297 if (!Enum)
4298 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004299
John McCalla2becad2009-10-21 00:40:46 +00004300 QualType Result = TL.getType();
4301 if (getDerived().AlwaysRebuild() ||
4302 Enum != T->getDecl()) {
4303 Result = getDerived().RebuildEnumType(Enum);
4304 if (Result.isNull())
4305 return QualType();
4306 }
Mike Stump1eb44332009-09-09 15:08:12 +00004307
John McCalla2becad2009-10-21 00:40:46 +00004308 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4309 NewTL.setNameLoc(TL.getNameLoc());
4310
4311 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004312}
John McCall7da24312009-09-05 00:15:47 +00004313
John McCall3cb0ebd2010-03-10 03:28:59 +00004314template<typename Derived>
4315QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4316 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004317 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00004318 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4319 TL.getTypePtr()->getDecl());
4320 if (!D) return QualType();
4321
4322 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4323 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4324 return T;
4325}
4326
Douglas Gregor577f75a2009-08-04 16:50:30 +00004327template<typename Derived>
4328QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004329 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004330 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00004331 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00004332}
4333
Mike Stump1eb44332009-09-09 15:08:12 +00004334template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00004335QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00004336 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004337 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor0b4bcb62011-03-05 17:19:27 +00004338 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4339
4340 // Substitute into the replacement type, which itself might involve something
4341 // that needs to be transformed. This only tends to occur with default
4342 // template arguments of template template parameters.
4343 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4344 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4345 if (Replacement.isNull())
4346 return QualType();
4347
4348 // Always canonicalize the replacement type.
4349 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4350 QualType Result
4351 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4352 Replacement);
4353
4354 // Propagate type-source information.
4355 SubstTemplateTypeParmTypeLoc NewTL
4356 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4357 NewTL.setNameLoc(TL.getNameLoc());
4358 return Result;
4359
John McCall49a832b2009-10-18 09:09:24 +00004360}
4361
4362template<typename Derived>
Douglas Gregorc3069d62011-01-14 02:55:32 +00004363QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4364 TypeLocBuilder &TLB,
4365 SubstTemplateTypeParmPackTypeLoc TL) {
4366 return TransformTypeSpecType(TLB, TL);
4367}
4368
4369template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00004370QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00004371 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004372 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00004373 const TemplateSpecializationType *T = TL.getTypePtr();
4374
Douglas Gregor1d752d72011-03-02 18:46:51 +00004375 // The nested-name-specifier never matters in a TemplateSpecializationType,
4376 // because we can't have a dependent nested-name-specifier anyway.
4377 CXXScopeSpec SS;
Mike Stump1eb44332009-09-09 15:08:12 +00004378 TemplateName Template
Douglas Gregor1d752d72011-03-02 18:46:51 +00004379 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4380 TL.getTemplateNameLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004381 if (Template.isNull())
4382 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004383
John McCall43fed0d2010-11-12 08:19:04 +00004384 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4385}
4386
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004387namespace {
4388 /// \brief Simple iterator that traverses the template arguments in a
4389 /// container that provides a \c getArgLoc() member function.
4390 ///
4391 /// This iterator is intended to be used with the iterator form of
4392 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4393 template<typename ArgLocContainer>
4394 class TemplateArgumentLocContainerIterator {
4395 ArgLocContainer *Container;
4396 unsigned Index;
4397
4398 public:
4399 typedef TemplateArgumentLoc value_type;
4400 typedef TemplateArgumentLoc reference;
4401 typedef int difference_type;
4402 typedef std::input_iterator_tag iterator_category;
4403
4404 class pointer {
4405 TemplateArgumentLoc Arg;
4406
4407 public:
4408 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4409
4410 const TemplateArgumentLoc *operator->() const {
4411 return &Arg;
4412 }
4413 };
4414
4415
4416 TemplateArgumentLocContainerIterator() {}
4417
4418 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4419 unsigned Index)
4420 : Container(&Container), Index(Index) { }
4421
4422 TemplateArgumentLocContainerIterator &operator++() {
4423 ++Index;
4424 return *this;
4425 }
4426
4427 TemplateArgumentLocContainerIterator operator++(int) {
4428 TemplateArgumentLocContainerIterator Old(*this);
4429 ++(*this);
4430 return Old;
4431 }
4432
4433 TemplateArgumentLoc operator*() const {
4434 return Container->getArgLoc(Index);
4435 }
4436
4437 pointer operator->() const {
4438 return pointer(Container->getArgLoc(Index));
4439 }
4440
4441 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004442 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004443 return X.Container == Y.Container && X.Index == Y.Index;
4444 }
4445
4446 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00004447 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004448 return !(X == Y);
4449 }
4450 };
4451}
4452
4453
John McCall43fed0d2010-11-12 08:19:04 +00004454template <typename Derived>
4455QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4456 TypeLocBuilder &TLB,
4457 TemplateSpecializationTypeLoc TL,
4458 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004459 TemplateArgumentListInfo NewTemplateArgs;
4460 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4461 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004462 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4463 ArgIterator;
4464 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4465 ArgIterator(TL, TL.getNumArgs()),
4466 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004467 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004468
John McCall833ca992009-10-29 08:12:44 +00004469 // FIXME: maybe don't rebuild if all the template arguments are the same.
4470
4471 QualType Result =
4472 getDerived().RebuildTemplateSpecializationType(Template,
4473 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004474 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004475
4476 if (!Result.isNull()) {
Richard Smith3e4c6c42011-05-05 21:57:07 +00004477 // Specializations of template template parameters are represented as
4478 // TemplateSpecializationTypes, and substitution of type alias templates
4479 // within a dependent context can transform them into
4480 // DependentTemplateSpecializationTypes.
4481 if (isa<DependentTemplateSpecializationType>(Result)) {
4482 DependentTemplateSpecializationTypeLoc NewTL
4483 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4484 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4485 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4486 NewTL.setNameLoc(TL.getTemplateNameLoc());
4487 NewTL.setLAngleLoc(TL.getLAngleLoc());
4488 NewTL.setRAngleLoc(TL.getRAngleLoc());
4489 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4490 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4491 return Result;
4492 }
4493
John McCall833ca992009-10-29 08:12:44 +00004494 TemplateSpecializationTypeLoc NewTL
4495 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4496 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4497 NewTL.setLAngleLoc(TL.getLAngleLoc());
4498 NewTL.setRAngleLoc(TL.getRAngleLoc());
4499 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4500 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004501 }
Mike Stump1eb44332009-09-09 15:08:12 +00004502
John McCall833ca992009-10-29 08:12:44 +00004503 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004504}
Mike Stump1eb44332009-09-09 15:08:12 +00004505
Douglas Gregora88f09f2011-02-28 17:23:35 +00004506template <typename Derived>
4507QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4508 TypeLocBuilder &TLB,
4509 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor087eb5a2011-03-04 18:53:13 +00004510 TemplateName Template,
4511 CXXScopeSpec &SS) {
Douglas Gregora88f09f2011-02-28 17:23:35 +00004512 TemplateArgumentListInfo NewTemplateArgs;
4513 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4514 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4515 typedef TemplateArgumentLocContainerIterator<
4516 DependentTemplateSpecializationTypeLoc> ArgIterator;
4517 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4518 ArgIterator(TL, TL.getNumArgs()),
4519 NewTemplateArgs))
4520 return QualType();
4521
4522 // FIXME: maybe don't rebuild if all the template arguments are the same.
4523
4524 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4525 QualType Result
4526 = getSema().Context.getDependentTemplateSpecializationType(
4527 TL.getTypePtr()->getKeyword(),
4528 DTN->getQualifier(),
4529 DTN->getIdentifier(),
4530 NewTemplateArgs);
4531
4532 DependentTemplateSpecializationTypeLoc NewTL
4533 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4534 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004535
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004536 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregora88f09f2011-02-28 17:23:35 +00004537 NewTL.setNameLoc(TL.getNameLoc());
4538 NewTL.setLAngleLoc(TL.getLAngleLoc());
4539 NewTL.setRAngleLoc(TL.getRAngleLoc());
4540 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4541 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4542 return Result;
4543 }
4544
4545 QualType Result
4546 = getDerived().RebuildTemplateSpecializationType(Template,
4547 TL.getNameLoc(),
4548 NewTemplateArgs);
4549
4550 if (!Result.isNull()) {
4551 /// FIXME: Wrap this in an elaborated-type-specifier?
4552 TemplateSpecializationTypeLoc NewTL
4553 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4554 NewTL.setTemplateNameLoc(TL.getNameLoc());
4555 NewTL.setLAngleLoc(TL.getLAngleLoc());
4556 NewTL.setRAngleLoc(TL.getRAngleLoc());
4557 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4558 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4559 }
4560
4561 return Result;
4562}
4563
Mike Stump1eb44332009-09-09 15:08:12 +00004564template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004565QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004566TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004567 ElaboratedTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004568 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004569
Douglas Gregor9e876872011-03-01 18:12:44 +00004570 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004571 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor9e876872011-03-01 18:12:44 +00004572 if (TL.getQualifierLoc()) {
4573 QualifierLoc
4574 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4575 if (!QualifierLoc)
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004576 return QualType();
4577 }
Mike Stump1eb44332009-09-09 15:08:12 +00004578
John McCall43fed0d2010-11-12 08:19:04 +00004579 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4580 if (NamedT.isNull())
4581 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004582
Richard Smith3e4c6c42011-05-05 21:57:07 +00004583 // C++0x [dcl.type.elab]p2:
4584 // If the identifier resolves to a typedef-name or the simple-template-id
4585 // resolves to an alias template specialization, the
4586 // elaborated-type-specifier is ill-formed.
Richard Smith18041742011-05-14 15:04:18 +00004587 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4588 if (const TemplateSpecializationType *TST =
4589 NamedT->getAs<TemplateSpecializationType>()) {
4590 TemplateName Template = TST->getTemplateName();
4591 if (TypeAliasTemplateDecl *TAT =
4592 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4593 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4594 diag::err_tag_reference_non_tag) << 4;
4595 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4596 }
Richard Smith3e4c6c42011-05-05 21:57:07 +00004597 }
4598 }
4599
John McCalla2becad2009-10-21 00:40:46 +00004600 QualType Result = TL.getType();
4601 if (getDerived().AlwaysRebuild() ||
Douglas Gregor9e876872011-03-01 18:12:44 +00004602 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004603 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004604 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor9e876872011-03-01 18:12:44 +00004605 T->getKeyword(),
4606 QualifierLoc, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004607 if (Result.isNull())
4608 return QualType();
4609 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004610
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004611 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004612 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004613 NewTL.setQualifierLoc(QualifierLoc);
John McCalla2becad2009-10-21 00:40:46 +00004614 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004615}
Mike Stump1eb44332009-09-09 15:08:12 +00004616
4617template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004618QualType TreeTransform<Derived>::TransformAttributedType(
4619 TypeLocBuilder &TLB,
4620 AttributedTypeLoc TL) {
4621 const AttributedType *oldType = TL.getTypePtr();
4622 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4623 if (modifiedType.isNull())
4624 return QualType();
4625
4626 QualType result = TL.getType();
4627
4628 // FIXME: dependent operand expressions?
4629 if (getDerived().AlwaysRebuild() ||
4630 modifiedType != oldType->getModifiedType()) {
4631 // TODO: this is really lame; we should really be rebuilding the
4632 // equivalent type from first principles.
4633 QualType equivalentType
4634 = getDerived().TransformType(oldType->getEquivalentType());
4635 if (equivalentType.isNull())
4636 return QualType();
4637 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4638 modifiedType,
4639 equivalentType);
4640 }
4641
4642 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4643 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4644 if (TL.hasAttrOperand())
4645 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4646 if (TL.hasAttrExprOperand())
4647 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4648 else if (TL.hasAttrEnumOperand())
4649 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4650
4651 return result;
4652}
4653
4654template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004655QualType
4656TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4657 ParenTypeLoc TL) {
4658 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4659 if (Inner.isNull())
4660 return QualType();
4661
4662 QualType Result = TL.getType();
4663 if (getDerived().AlwaysRebuild() ||
4664 Inner != TL.getInnerLoc().getType()) {
4665 Result = getDerived().RebuildParenType(Inner);
4666 if (Result.isNull())
4667 return QualType();
4668 }
4669
4670 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4671 NewTL.setLParenLoc(TL.getLParenLoc());
4672 NewTL.setRParenLoc(TL.getRParenLoc());
4673 return Result;
4674}
4675
4676template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004677QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004678 DependentNameTypeLoc TL) {
John McCallf4c73712011-01-19 06:33:43 +00004679 const DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004680
Douglas Gregor2494dd02011-03-01 01:34:45 +00004681 NestedNameSpecifierLoc QualifierLoc
4682 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4683 if (!QualifierLoc)
Douglas Gregor577f75a2009-08-04 16:50:30 +00004684 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004685
John McCall33500952010-06-11 00:33:02 +00004686 QualType Result
Douglas Gregor2494dd02011-03-01 01:34:45 +00004687 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCall33500952010-06-11 00:33:02 +00004688 TL.getKeywordLoc(),
Douglas Gregor2494dd02011-03-01 01:34:45 +00004689 QualifierLoc,
4690 T->getIdentifier(),
John McCall33500952010-06-11 00:33:02 +00004691 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004692 if (Result.isNull())
4693 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004694
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004695 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4696 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004697 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4698
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004699 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4700 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor9e876872011-03-01 18:12:44 +00004701 NewTL.setQualifierLoc(QualifierLoc);
John McCall33500952010-06-11 00:33:02 +00004702 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004703 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4704 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor2494dd02011-03-01 01:34:45 +00004705 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004706 NewTL.setNameLoc(TL.getNameLoc());
4707 }
John McCalla2becad2009-10-21 00:40:46 +00004708 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004709}
Mike Stump1eb44332009-09-09 15:08:12 +00004710
Douglas Gregor577f75a2009-08-04 16:50:30 +00004711template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004712QualType TreeTransform<Derived>::
4713 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004714 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004715 NestedNameSpecifierLoc QualifierLoc;
4716 if (TL.getQualifierLoc()) {
4717 QualifierLoc
4718 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4719 if (!QualifierLoc)
Douglas Gregora88f09f2011-02-28 17:23:35 +00004720 return QualType();
4721 }
4722
John McCall43fed0d2010-11-12 08:19:04 +00004723 return getDerived()
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004724 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall43fed0d2010-11-12 08:19:04 +00004725}
4726
4727template<typename Derived>
4728QualType TreeTransform<Derived>::
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004729TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4730 DependentTemplateSpecializationTypeLoc TL,
4731 NestedNameSpecifierLoc QualifierLoc) {
4732 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4733
4734 TemplateArgumentListInfo NewTemplateArgs;
4735 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4736 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4737
4738 typedef TemplateArgumentLocContainerIterator<
4739 DependentTemplateSpecializationTypeLoc> ArgIterator;
4740 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4741 ArgIterator(TL, TL.getNumArgs()),
4742 NewTemplateArgs))
4743 return QualType();
4744
4745 QualType Result
4746 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4747 QualifierLoc,
4748 T->getIdentifier(),
4749 TL.getNameLoc(),
4750 NewTemplateArgs);
4751 if (Result.isNull())
4752 return QualType();
4753
4754 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4755 QualType NamedT = ElabT->getNamedType();
4756
4757 // Copy information relevant to the template specialization.
4758 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004759 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004760 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004761 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4762 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004763 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004764 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004765
4766 // Copy information relevant to the elaborated type.
4767 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4768 NewTL.setKeywordLoc(TL.getKeywordLoc());
4769 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004770 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4771 DependentTemplateSpecializationTypeLoc SpecTL
4772 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor944cdae2011-03-07 15:13:34 +00004773 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004774 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004775 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004776 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4777 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004778 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004779 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004780 } else {
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004781 TemplateSpecializationTypeLoc SpecTL
4782 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carrutha35d5d72011-04-01 02:03:23 +00004783 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004784 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4785 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor944cdae2011-03-07 15:13:34 +00004786 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor0a0367a2011-03-07 02:33:33 +00004787 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregor94fdffa2011-03-01 20:11:18 +00004788 }
4789 return Result;
4790}
4791
4792template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004793QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4794 PackExpansionTypeLoc TL) {
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004795 QualType Pattern
4796 = getDerived().TransformType(TLB, TL.getPatternLoc());
4797 if (Pattern.isNull())
4798 return QualType();
4799
4800 QualType Result = TL.getType();
4801 if (getDerived().AlwaysRebuild() ||
4802 Pattern != TL.getPatternLoc().getType()) {
4803 Result = getDerived().RebuildPackExpansionType(Pattern,
4804 TL.getPatternLoc().getSourceRange(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00004805 TL.getEllipsisLoc(),
4806 TL.getTypePtr()->getNumExpansions());
Douglas Gregor2fc1bb72011-01-12 17:07:58 +00004807 if (Result.isNull())
4808 return QualType();
4809 }
4810
4811 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4812 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4813 return Result;
Douglas Gregor7536dd52010-12-20 02:24:11 +00004814}
4815
4816template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004817QualType
4818TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004819 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004820 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004821 TLB.pushFullCopy(TL);
4822 return TL.getType();
4823}
4824
4825template<typename Derived>
4826QualType
4827TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004828 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004829 // ObjCObjectType is never dependent.
4830 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004831 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004832}
Mike Stump1eb44332009-09-09 15:08:12 +00004833
4834template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004835QualType
4836TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004837 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004838 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004839 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004840 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004841}
4842
Douglas Gregor577f75a2009-08-04 16:50:30 +00004843//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004844// Statement transformation
4845//===----------------------------------------------------------------------===//
4846template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004847StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004848TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004849 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004850}
4851
4852template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004853StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004854TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4855 return getDerived().TransformCompoundStmt(S, false);
4856}
4857
4858template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004859StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004860TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004861 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004862 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004863 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004864 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004865 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4866 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004867 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004868 if (Result.isInvalid()) {
4869 // Immediately fail if this was a DeclStmt, since it's very
4870 // likely that this will cause problems for future statements.
4871 if (isa<DeclStmt>(*B))
4872 return StmtError();
4873
4874 // Otherwise, just keep processing substatements and fail later.
4875 SubStmtInvalid = true;
4876 continue;
4877 }
Mike Stump1eb44332009-09-09 15:08:12 +00004878
Douglas Gregor43959a92009-08-20 07:17:43 +00004879 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4880 Statements.push_back(Result.takeAs<Stmt>());
4881 }
Mike Stump1eb44332009-09-09 15:08:12 +00004882
John McCall7114cba2010-08-27 19:56:05 +00004883 if (SubStmtInvalid)
4884 return StmtError();
4885
Douglas Gregor43959a92009-08-20 07:17:43 +00004886 if (!getDerived().AlwaysRebuild() &&
4887 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004888 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004889
4890 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4891 move_arg(Statements),
4892 S->getRBracLoc(),
4893 IsStmtExpr);
4894}
Mike Stump1eb44332009-09-09 15:08:12 +00004895
Douglas Gregor43959a92009-08-20 07:17:43 +00004896template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004897StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004898TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004899 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004900 {
4901 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004902 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004903
Eli Friedman264c1f82009-11-19 03:14:00 +00004904 // Transform the left-hand case value.
4905 LHS = getDerived().TransformExpr(S->getLHS());
4906 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004907 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004908
Eli Friedman264c1f82009-11-19 03:14:00 +00004909 // Transform the right-hand case value (for the GNU case-range extension).
4910 RHS = getDerived().TransformExpr(S->getRHS());
4911 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004912 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004913 }
Mike Stump1eb44332009-09-09 15:08:12 +00004914
Douglas Gregor43959a92009-08-20 07:17:43 +00004915 // Build the case statement.
4916 // Case statements are always rebuilt so that they will attached to their
4917 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004918 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004919 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004920 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004921 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004922 S->getColonLoc());
4923 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004924 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004925
Douglas Gregor43959a92009-08-20 07:17:43 +00004926 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004927 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004928 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004929 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004930
Douglas Gregor43959a92009-08-20 07:17:43 +00004931 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004932 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004933}
4934
4935template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004936StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004937TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004938 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00004939 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004940 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004941 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004942
Douglas Gregor43959a92009-08-20 07:17:43 +00004943 // Default statements are always rebuilt
4944 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004945 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004946}
Mike Stump1eb44332009-09-09 15:08:12 +00004947
Douglas Gregor43959a92009-08-20 07:17:43 +00004948template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004949StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004950TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004951 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004952 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004953 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004954
Chris Lattner57ad3782011-02-17 20:34:02 +00004955 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4956 S->getDecl());
4957 if (!LD)
4958 return StmtError();
4959
4960
Douglas Gregor43959a92009-08-20 07:17:43 +00004961 // FIXME: Pass the real colon location in.
Chris Lattnerad8dcf42011-02-17 07:39:24 +00004962 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00004963 cast<LabelDecl>(LD), SourceLocation(),
4964 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004965}
Mike Stump1eb44332009-09-09 15:08:12 +00004966
Douglas Gregor43959a92009-08-20 07:17:43 +00004967template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004968StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004969TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004970 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004971 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004972 VarDecl *ConditionVar = 0;
4973 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004974 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004975 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004976 getDerived().TransformDefinition(
4977 S->getConditionVariable()->getLocation(),
4978 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004979 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004980 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004981 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004982 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004983
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004984 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004985 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004986
4987 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004988 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004989 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4990 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004991 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004992 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004993
John McCall9ae2f072010-08-23 23:25:46 +00004994 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004995 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004996 }
Sean Huntc3021132010-05-05 15:23:54 +00004997
John McCall9ae2f072010-08-23 23:25:46 +00004998 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4999 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005000 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005001
Douglas Gregor43959a92009-08-20 07:17:43 +00005002 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005003 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00005004 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005005 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005006
Douglas Gregor43959a92009-08-20 07:17:43 +00005007 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00005008 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00005009 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005010 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005011
Douglas Gregor43959a92009-08-20 07:17:43 +00005012 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005013 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005014 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005015 Then.get() == S->getThen() &&
5016 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00005017 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005018
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005019 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00005020 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00005021 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005022}
5023
5024template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005025StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005026TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005027 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00005028 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00005029 VarDecl *ConditionVar = 0;
5030 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005031 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00005032 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005033 getDerived().TransformDefinition(
5034 S->getConditionVariable()->getLocation(),
5035 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00005036 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005037 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005038 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00005039 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005040
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005041 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005042 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005043 }
Mike Stump1eb44332009-09-09 15:08:12 +00005044
Douglas Gregor43959a92009-08-20 07:17:43 +00005045 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005046 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00005047 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00005048 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00005049 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005050 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005051
Douglas Gregor43959a92009-08-20 07:17:43 +00005052 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005053 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005054 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005055 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005056
Douglas Gregor43959a92009-08-20 07:17:43 +00005057 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00005058 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5059 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005060}
Mike Stump1eb44332009-09-09 15:08:12 +00005061
Douglas Gregor43959a92009-08-20 07:17:43 +00005062template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005063StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005064TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005065 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005066 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00005067 VarDecl *ConditionVar = 0;
5068 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005069 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00005070 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005071 getDerived().TransformDefinition(
5072 S->getConditionVariable()->getLocation(),
5073 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00005074 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005075 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005076 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00005077 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005078
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005079 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005080 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005081
5082 if (S->getCond()) {
5083 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005084 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5085 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005086 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005087 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00005088 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005089 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005090 }
Mike Stump1eb44332009-09-09 15:08:12 +00005091
John McCall9ae2f072010-08-23 23:25:46 +00005092 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5093 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005094 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005095
Douglas Gregor43959a92009-08-20 07:17:43 +00005096 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005097 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005098 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005099 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005100
Douglas Gregor43959a92009-08-20 07:17:43 +00005101 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00005102 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005103 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005104 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00005105 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005106
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005107 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00005108 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005109}
Mike Stump1eb44332009-09-09 15:08:12 +00005110
Douglas Gregor43959a92009-08-20 07:17:43 +00005111template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005112StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005113TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005114 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005115 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005116 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005117 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005118
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005119 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005120 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005121 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005122 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005123
Douglas Gregor43959a92009-08-20 07:17:43 +00005124 if (!getDerived().AlwaysRebuild() &&
5125 Cond.get() == S->getCond() &&
5126 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005127 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005128
John McCall9ae2f072010-08-23 23:25:46 +00005129 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5130 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005131 S->getRParenLoc());
5132}
Mike Stump1eb44332009-09-09 15:08:12 +00005133
Douglas Gregor43959a92009-08-20 07:17:43 +00005134template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005135StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005136TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005137 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00005138 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00005139 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005140 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005141
Douglas Gregor43959a92009-08-20 07:17:43 +00005142 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00005143 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005144 VarDecl *ConditionVar = 0;
5145 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00005146 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005147 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00005148 getDerived().TransformDefinition(
5149 S->getConditionVariable()->getLocation(),
5150 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005151 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00005152 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005153 } else {
5154 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00005155
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005156 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005157 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005158
5159 if (S->getCond()) {
5160 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00005161 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5162 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005163 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005164 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005165
John McCall9ae2f072010-08-23 23:25:46 +00005166 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00005167 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00005168 }
Mike Stump1eb44332009-09-09 15:08:12 +00005169
John McCall9ae2f072010-08-23 23:25:46 +00005170 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5171 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00005172 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005173
Douglas Gregor43959a92009-08-20 07:17:43 +00005174 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00005175 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00005176 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005177 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005178
John McCall9ae2f072010-08-23 23:25:46 +00005179 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5180 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00005181 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00005182
Douglas Gregor43959a92009-08-20 07:17:43 +00005183 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00005184 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00005185 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005186 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005187
Douglas Gregor43959a92009-08-20 07:17:43 +00005188 if (!getDerived().AlwaysRebuild() &&
5189 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00005190 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00005191 Inc.get() == S->getInc() &&
5192 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005193 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005194
Douglas Gregor43959a92009-08-20 07:17:43 +00005195 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005196 Init.get(), FullCond, ConditionVar,
5197 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005198}
5199
5200template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005201StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005202TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattner57ad3782011-02-17 20:34:02 +00005203 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5204 S->getLabel());
5205 if (!LD)
5206 return StmtError();
5207
Douglas Gregor43959a92009-08-20 07:17:43 +00005208 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00005209 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00005210 cast<LabelDecl>(LD));
Douglas Gregor43959a92009-08-20 07:17:43 +00005211}
5212
5213template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005214StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005215TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005216 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00005217 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005218 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005219
Douglas Gregor43959a92009-08-20 07:17:43 +00005220 if (!getDerived().AlwaysRebuild() &&
5221 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00005222 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005223
5224 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005225 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005226}
5227
5228template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005229StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005230TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005231 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005232}
Mike Stump1eb44332009-09-09 15:08:12 +00005233
Douglas Gregor43959a92009-08-20 07:17:43 +00005234template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005235StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005236TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00005237 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005238}
Mike Stump1eb44332009-09-09 15:08:12 +00005239
Douglas Gregor43959a92009-08-20 07:17:43 +00005240template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005241StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005242TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005243 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00005244 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005245 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005246
Mike Stump1eb44332009-09-09 15:08:12 +00005247 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00005248 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00005249 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005250}
Mike Stump1eb44332009-09-09 15:08:12 +00005251
Douglas Gregor43959a92009-08-20 07:17:43 +00005252template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005253StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005254TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00005255 bool DeclChanged = false;
5256 llvm::SmallVector<Decl *, 4> Decls;
5257 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5258 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00005259 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5260 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00005261 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00005262 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005263
Douglas Gregor43959a92009-08-20 07:17:43 +00005264 if (Transformed != *D)
5265 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00005266
Douglas Gregor43959a92009-08-20 07:17:43 +00005267 Decls.push_back(Transformed);
5268 }
Mike Stump1eb44332009-09-09 15:08:12 +00005269
Douglas Gregor43959a92009-08-20 07:17:43 +00005270 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005271 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00005272
5273 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00005274 S->getStartLoc(), S->getEndLoc());
5275}
Mike Stump1eb44332009-09-09 15:08:12 +00005276
Douglas Gregor43959a92009-08-20 07:17:43 +00005277template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005278StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005279TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00005280
John McCallca0408f2010-08-23 06:44:23 +00005281 ASTOwningVector<Expr*> Constraints(getSema());
5282 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005283 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00005284
John McCall60d7b3a2010-08-24 06:29:42 +00005285 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00005286 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00005287
5288 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00005289
Anders Carlsson703e3942010-01-24 05:50:09 +00005290 // Go through the outputs.
5291 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005292 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005293
Anders Carlsson703e3942010-01-24 05:50:09 +00005294 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005295 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005296
Anders Carlsson703e3942010-01-24 05:50:09 +00005297 // Transform the output expr.
5298 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005299 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005300 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005301 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005302
Anders Carlsson703e3942010-01-24 05:50:09 +00005303 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005304
John McCall9ae2f072010-08-23 23:25:46 +00005305 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005306 }
Sean Huntc3021132010-05-05 15:23:54 +00005307
Anders Carlsson703e3942010-01-24 05:50:09 +00005308 // Go through the inputs.
5309 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00005310 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00005311
Anders Carlsson703e3942010-01-24 05:50:09 +00005312 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00005313 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00005314
Anders Carlsson703e3942010-01-24 05:50:09 +00005315 // Transform the input expr.
5316 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00005317 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00005318 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005319 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005320
Anders Carlsson703e3942010-01-24 05:50:09 +00005321 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00005322
John McCall9ae2f072010-08-23 23:25:46 +00005323 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00005324 }
Sean Huntc3021132010-05-05 15:23:54 +00005325
Anders Carlsson703e3942010-01-24 05:50:09 +00005326 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005327 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00005328
5329 // Go through the clobbers.
5330 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00005331 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00005332
5333 // No need to transform the asm string literal.
5334 AsmString = SemaRef.Owned(S->getAsmString());
5335
5336 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5337 S->isSimple(),
5338 S->isVolatile(),
5339 S->getNumOutputs(),
5340 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00005341 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005342 move_arg(Constraints),
5343 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00005344 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00005345 move_arg(Clobbers),
5346 S->getRParenLoc(),
5347 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00005348}
5349
5350
5351template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005352StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005353TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005354 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00005355 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005356 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005357 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005358
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005359 // Transform the @catch statements (if present).
5360 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005361 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005362 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005363 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005364 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005365 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005366 if (Catch.get() != S->getCatchStmt(I))
5367 AnyCatchChanged = true;
5368 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005369 }
Sean Huntc3021132010-05-05 15:23:54 +00005370
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005371 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00005372 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005373 if (S->getFinallyStmt()) {
5374 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5375 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005376 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005377 }
5378
5379 // If nothing changed, just retain this statement.
5380 if (!getDerived().AlwaysRebuild() &&
5381 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00005382 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005383 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005384 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005385
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005386 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00005387 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5388 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005389}
Mike Stump1eb44332009-09-09 15:08:12 +00005390
Douglas Gregor43959a92009-08-20 07:17:43 +00005391template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005392StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005393TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00005394 // Transform the @catch parameter, if there is one.
5395 VarDecl *Var = 0;
5396 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5397 TypeSourceInfo *TSInfo = 0;
5398 if (FromVar->getTypeSourceInfo()) {
5399 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5400 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005401 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005402 }
Sean Huntc3021132010-05-05 15:23:54 +00005403
Douglas Gregorbe270a02010-04-26 17:57:08 +00005404 QualType T;
5405 if (TSInfo)
5406 T = TSInfo->getType();
5407 else {
5408 T = getDerived().TransformType(FromVar->getType());
5409 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005410 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005411 }
Sean Huntc3021132010-05-05 15:23:54 +00005412
Douglas Gregorbe270a02010-04-26 17:57:08 +00005413 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5414 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00005415 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00005416 }
Sean Huntc3021132010-05-05 15:23:54 +00005417
John McCall60d7b3a2010-08-24 06:29:42 +00005418 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00005419 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005420 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005421
5422 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00005423 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005424 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005425}
Mike Stump1eb44332009-09-09 15:08:12 +00005426
Douglas Gregor43959a92009-08-20 07:17:43 +00005427template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005428StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005429TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005430 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005431 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005432 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005433 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005434
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005435 // If nothing changed, just retain this statement.
5436 if (!getDerived().AlwaysRebuild() &&
5437 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005438 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00005439
5440 // Build a new statement.
5441 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005442 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005443}
Mike Stump1eb44332009-09-09 15:08:12 +00005444
Douglas Gregor43959a92009-08-20 07:17:43 +00005445template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005446StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00005447TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00005448 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00005449 if (S->getThrowExpr()) {
5450 Operand = getDerived().TransformExpr(S->getThrowExpr());
5451 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005452 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00005453 }
Sean Huntc3021132010-05-05 15:23:54 +00005454
Douglas Gregord1377b22010-04-22 21:44:01 +00005455 if (!getDerived().AlwaysRebuild() &&
5456 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005457 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005458
John McCall9ae2f072010-08-23 23:25:46 +00005459 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005460}
Mike Stump1eb44332009-09-09 15:08:12 +00005461
Douglas Gregor43959a92009-08-20 07:17:43 +00005462template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005463StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005464TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005465 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005466 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00005467 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005468 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005469 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005470
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005471 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005472 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005473 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005474 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005475
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005476 // If nothing change, just retain the current statement.
5477 if (!getDerived().AlwaysRebuild() &&
5478 Object.get() == S->getSynchExpr() &&
5479 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005480 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00005481
5482 // Build a new statement.
5483 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005484 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005485}
5486
5487template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005488StmtResult
John McCallf85e1932011-06-15 23:02:42 +00005489TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5490 ObjCAutoreleasePoolStmt *S) {
5491 // Transform the body.
5492 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5493 if (Body.isInvalid())
5494 return StmtError();
5495
5496 // If nothing changed, just retain this statement.
5497 if (!getDerived().AlwaysRebuild() &&
5498 Body.get() == S->getSubStmt())
5499 return SemaRef.Owned(S);
5500
5501 // Build a new statement.
5502 return getDerived().RebuildObjCAutoreleasePoolStmt(
5503 S->getAtLoc(), Body.get());
5504}
5505
5506template<typename Derived>
5507StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005508TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00005509 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00005510 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00005511 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005512 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005513 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005514
Douglas Gregorc3203e72010-04-22 23:10:45 +00005515 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00005516 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005517 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005518 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005519
Douglas Gregorc3203e72010-04-22 23:10:45 +00005520 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00005521 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00005522 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005523 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00005524
Douglas Gregorc3203e72010-04-22 23:10:45 +00005525 // If nothing changed, just retain this statement.
5526 if (!getDerived().AlwaysRebuild() &&
5527 Element.get() == S->getElement() &&
5528 Collection.get() == S->getCollection() &&
5529 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00005530 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00005531
Douglas Gregorc3203e72010-04-22 23:10:45 +00005532 // Build a new statement.
5533 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5534 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005535 Element.get(),
5536 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00005537 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005538 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005539}
5540
5541
5542template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005543StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005544TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5545 // Transform the exception declaration, if any.
5546 VarDecl *Var = 0;
5547 if (S->getExceptionDecl()) {
5548 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00005549 TypeSourceInfo *T = getDerived().TransformType(
5550 ExceptionDecl->getTypeSourceInfo());
5551 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005552 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005553
Douglas Gregor83cb9422010-09-09 17:09:21 +00005554 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaraff676cb2011-03-08 08:55:46 +00005555 ExceptionDecl->getInnerLocStart(),
5556 ExceptionDecl->getLocation(),
5557 ExceptionDecl->getIdentifier());
Douglas Gregorff331c12010-07-25 18:17:45 +00005558 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00005559 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00005560 }
Mike Stump1eb44332009-09-09 15:08:12 +00005561
Douglas Gregor43959a92009-08-20 07:17:43 +00005562 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00005563 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00005564 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005565 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005566
Douglas Gregor43959a92009-08-20 07:17:43 +00005567 if (!getDerived().AlwaysRebuild() &&
5568 !Var &&
5569 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00005570 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005571
5572 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5573 Var,
John McCall9ae2f072010-08-23 23:25:46 +00005574 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00005575}
Mike Stump1eb44332009-09-09 15:08:12 +00005576
Douglas Gregor43959a92009-08-20 07:17:43 +00005577template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005578StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00005579TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5580 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005581 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00005582 = getDerived().TransformCompoundStmt(S->getTryBlock());
5583 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005584 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005585
Douglas Gregor43959a92009-08-20 07:17:43 +00005586 // Transform the handlers.
5587 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005588 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00005589 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00005590 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00005591 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5592 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005593 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00005594
Douglas Gregor43959a92009-08-20 07:17:43 +00005595 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5596 Handlers.push_back(Handler.takeAs<Stmt>());
5597 }
Mike Stump1eb44332009-09-09 15:08:12 +00005598
Douglas Gregor43959a92009-08-20 07:17:43 +00005599 if (!getDerived().AlwaysRebuild() &&
5600 TryBlock.get() == S->getTryBlock() &&
5601 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005602 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005603
John McCall9ae2f072010-08-23 23:25:46 +00005604 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005605 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005606}
Mike Stump1eb44332009-09-09 15:08:12 +00005607
Richard Smithad762fc2011-04-14 22:09:26 +00005608template<typename Derived>
5609StmtResult
5610TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5611 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5612 if (Range.isInvalid())
5613 return StmtError();
5614
5615 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5616 if (BeginEnd.isInvalid())
5617 return StmtError();
5618
5619 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5620 if (Cond.isInvalid())
5621 return StmtError();
5622
5623 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5624 if (Inc.isInvalid())
5625 return StmtError();
5626
5627 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5628 if (LoopVar.isInvalid())
5629 return StmtError();
5630
5631 StmtResult NewStmt = S;
5632 if (getDerived().AlwaysRebuild() ||
5633 Range.get() != S->getRangeStmt() ||
5634 BeginEnd.get() != S->getBeginEndStmt() ||
5635 Cond.get() != S->getCond() ||
5636 Inc.get() != S->getInc() ||
5637 LoopVar.get() != S->getLoopVarStmt())
5638 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5639 S->getColonLoc(), Range.get(),
5640 BeginEnd.get(), Cond.get(),
5641 Inc.get(), LoopVar.get(),
5642 S->getRParenLoc());
5643
5644 StmtResult Body = getDerived().TransformStmt(S->getBody());
5645 if (Body.isInvalid())
5646 return StmtError();
5647
5648 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5649 // it now so we have a new statement to attach the body to.
5650 if (Body.get() != S->getBody() && NewStmt.get() == S)
5651 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5652 S->getColonLoc(), Range.get(),
5653 BeginEnd.get(), Cond.get(),
5654 Inc.get(), LoopVar.get(),
5655 S->getRParenLoc());
5656
5657 if (NewStmt.get() == S)
5658 return SemaRef.Owned(S);
5659
5660 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5661}
5662
John Wiegley28bbe4b2011-04-28 01:08:34 +00005663template<typename Derived>
5664StmtResult
5665TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5666 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5667 if(TryBlock.isInvalid()) return StmtError();
5668
5669 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5670 if(!getDerived().AlwaysRebuild() &&
5671 TryBlock.get() == S->getTryBlock() &&
5672 Handler.get() == S->getHandler())
5673 return SemaRef.Owned(S);
5674
5675 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5676 S->getTryLoc(),
5677 TryBlock.take(),
5678 Handler.take());
5679}
5680
5681template<typename Derived>
5682StmtResult
5683TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5684 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5685 if(Block.isInvalid()) return StmtError();
5686
5687 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5688 Block.take());
5689}
5690
5691template<typename Derived>
5692StmtResult
5693TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5694 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5695 if(FilterExpr.isInvalid()) return StmtError();
5696
5697 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5698 if(Block.isInvalid()) return StmtError();
5699
5700 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5701 FilterExpr.take(),
5702 Block.take());
5703}
5704
5705template<typename Derived>
5706StmtResult
5707TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5708 if(isa<SEHFinallyStmt>(Handler))
5709 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5710 else
5711 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5712}
5713
Douglas Gregor43959a92009-08-20 07:17:43 +00005714//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005715// Expression transformation
5716//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005717template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005718ExprResult
John McCall454feb92009-12-08 09:21:05 +00005719TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005720 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005721}
Mike Stump1eb44332009-09-09 15:08:12 +00005722
5723template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005724ExprResult
John McCall454feb92009-12-08 09:21:05 +00005725TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00005726 NestedNameSpecifierLoc QualifierLoc;
5727 if (E->getQualifierLoc()) {
5728 QualifierLoc
5729 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5730 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00005731 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005732 }
John McCalldbd872f2009-12-08 09:08:17 +00005733
5734 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005735 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5736 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005737 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005738 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005739
John McCallec8045d2010-08-17 21:27:17 +00005740 DeclarationNameInfo NameInfo = E->getNameInfo();
5741 if (NameInfo.getName()) {
5742 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5743 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005744 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005745 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005746
5747 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00005748 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005749 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005750 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005751 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005752
5753 // Mark it referenced in the new context regardless.
5754 // FIXME: this is a bit instantiation-specific.
5755 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5756
John McCall3fa5cae2010-10-26 07:05:15 +00005757 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005758 }
John McCalldbd872f2009-12-08 09:08:17 +00005759
5760 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005761 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005762 TemplateArgs = &TransArgs;
5763 TransArgs.setLAngleLoc(E->getLAngleLoc());
5764 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005765 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5766 E->getNumTemplateArgs(),
5767 TransArgs))
5768 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005769 }
5770
Douglas Gregor40d96a62011-02-28 21:54:11 +00005771 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5772 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005773}
Mike Stump1eb44332009-09-09 15:08:12 +00005774
Douglas Gregorb98b1992009-08-11 05:31:07 +00005775template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005776ExprResult
John McCall454feb92009-12-08 09:21:05 +00005777TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005778 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005779}
Mike Stump1eb44332009-09-09 15:08:12 +00005780
Douglas Gregorb98b1992009-08-11 05:31:07 +00005781template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005782ExprResult
John McCall454feb92009-12-08 09:21:05 +00005783TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005784 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005785}
Mike Stump1eb44332009-09-09 15:08:12 +00005786
Douglas Gregorb98b1992009-08-11 05:31:07 +00005787template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005788ExprResult
John McCall454feb92009-12-08 09:21:05 +00005789TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005790 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005791}
Mike Stump1eb44332009-09-09 15:08:12 +00005792
Douglas Gregorb98b1992009-08-11 05:31:07 +00005793template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005794ExprResult
John McCall454feb92009-12-08 09:21:05 +00005795TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005796 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005797}
Mike Stump1eb44332009-09-09 15:08:12 +00005798
Douglas Gregorb98b1992009-08-11 05:31:07 +00005799template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005800ExprResult
John McCall454feb92009-12-08 09:21:05 +00005801TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005802 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005803}
5804
5805template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005806ExprResult
Peter Collingbournef111d932011-04-15 00:35:48 +00005807TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5808 ExprResult ControllingExpr =
5809 getDerived().TransformExpr(E->getControllingExpr());
5810 if (ControllingExpr.isInvalid())
5811 return ExprError();
5812
5813 llvm::SmallVector<Expr *, 4> AssocExprs;
5814 llvm::SmallVector<TypeSourceInfo *, 4> AssocTypes;
5815 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5816 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5817 if (TS) {
5818 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5819 if (!AssocType)
5820 return ExprError();
5821 AssocTypes.push_back(AssocType);
5822 } else {
5823 AssocTypes.push_back(0);
5824 }
5825
5826 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5827 if (AssocExpr.isInvalid())
5828 return ExprError();
5829 AssocExprs.push_back(AssocExpr.release());
5830 }
5831
5832 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5833 E->getDefaultLoc(),
5834 E->getRParenLoc(),
5835 ControllingExpr.release(),
5836 AssocTypes.data(),
5837 AssocExprs.data(),
5838 E->getNumAssocs());
5839}
5840
5841template<typename Derived>
5842ExprResult
John McCall454feb92009-12-08 09:21:05 +00005843TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005844 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005845 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005846 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005847
Douglas Gregorb98b1992009-08-11 05:31:07 +00005848 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005849 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005850
John McCall9ae2f072010-08-23 23:25:46 +00005851 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005852 E->getRParen());
5853}
5854
Mike Stump1eb44332009-09-09 15:08:12 +00005855template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005856ExprResult
John McCall454feb92009-12-08 09:21:05 +00005857TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005858 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005859 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005860 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005861
Douglas Gregorb98b1992009-08-11 05:31:07 +00005862 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005863 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005864
Douglas Gregorb98b1992009-08-11 05:31:07 +00005865 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5866 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005867 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005868}
Mike Stump1eb44332009-09-09 15:08:12 +00005869
Douglas Gregorb98b1992009-08-11 05:31:07 +00005870template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005871ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005872TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5873 // Transform the type.
5874 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5875 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005876 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005877
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005878 // Transform all of the components into components similar to what the
5879 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005880 // FIXME: It would be slightly more efficient in the non-dependent case to
5881 // just map FieldDecls, rather than requiring the rebuilder to look for
5882 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005883 // template code that we don't care.
5884 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005885 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005886 typedef OffsetOfExpr::OffsetOfNode Node;
5887 llvm::SmallVector<Component, 4> Components;
5888 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5889 const Node &ON = E->getComponent(I);
5890 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005891 Comp.isBrackets = true;
Abramo Bagnara06dec892011-03-12 09:45:03 +00005892 Comp.LocStart = ON.getSourceRange().getBegin();
5893 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005894 switch (ON.getKind()) {
5895 case Node::Array: {
5896 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005897 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005898 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005899 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005900
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005901 ExprChanged = ExprChanged || Index.get() != FromIndex;
5902 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005903 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005904 break;
5905 }
Sean Huntc3021132010-05-05 15:23:54 +00005906
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005907 case Node::Field:
5908 case Node::Identifier:
5909 Comp.isBrackets = false;
5910 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005911 if (!Comp.U.IdentInfo)
5912 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005913
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005914 break;
Sean Huntc3021132010-05-05 15:23:54 +00005915
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005916 case Node::Base:
5917 // Will be recomputed during the rebuild.
5918 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005919 }
Sean Huntc3021132010-05-05 15:23:54 +00005920
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005921 Components.push_back(Comp);
5922 }
Sean Huntc3021132010-05-05 15:23:54 +00005923
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005924 // If nothing changed, retain the existing expression.
5925 if (!getDerived().AlwaysRebuild() &&
5926 Type == E->getTypeSourceInfo() &&
5927 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005928 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00005929
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005930 // Build a new offsetof expression.
5931 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5932 Components.data(), Components.size(),
5933 E->getRParenLoc());
5934}
5935
5936template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005937ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00005938TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5939 assert(getDerived().AlreadyTransformed(E->getType()) &&
5940 "opaque value expression requires transformation");
5941 return SemaRef.Owned(E);
5942}
5943
5944template<typename Derived>
5945ExprResult
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005946TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5947 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005948 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00005949 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00005950
John McCalla93c9342009-12-07 02:54:59 +00005951 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00005952 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005953 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005954
John McCall5ab75172009-11-04 07:28:41 +00005955 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00005956 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005957
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005958 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5959 E->getKind(),
5960 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005961 }
Mike Stump1eb44332009-09-09 15:08:12 +00005962
John McCall60d7b3a2010-08-24 06:29:42 +00005963 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00005964 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005965 // C++0x [expr.sizeof]p1:
5966 // The operand is either an expression, which is an unevaluated operand
5967 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00005968 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005969
Douglas Gregorb98b1992009-08-11 05:31:07 +00005970 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5971 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005972 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005973
Douglas Gregorb98b1992009-08-11 05:31:07 +00005974 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005975 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005976 }
Mike Stump1eb44332009-09-09 15:08:12 +00005977
Peter Collingbournef4e3cfb2011-03-11 19:24:49 +00005978 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
5979 E->getOperatorLoc(),
5980 E->getKind(),
5981 E->getSourceRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005982}
Mike Stump1eb44332009-09-09 15:08:12 +00005983
Douglas Gregorb98b1992009-08-11 05:31:07 +00005984template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005985ExprResult
John McCall454feb92009-12-08 09:21:05 +00005986TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005987 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005988 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005989 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005990
John McCall60d7b3a2010-08-24 06:29:42 +00005991 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005992 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005993 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005994
5995
Douglas Gregorb98b1992009-08-11 05:31:07 +00005996 if (!getDerived().AlwaysRebuild() &&
5997 LHS.get() == E->getLHS() &&
5998 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005999 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006000
John McCall9ae2f072010-08-23 23:25:46 +00006001 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006002 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006003 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006004 E->getRBracketLoc());
6005}
Mike Stump1eb44332009-09-09 15:08:12 +00006006
6007template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006008ExprResult
John McCall454feb92009-12-08 09:21:05 +00006009TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006010 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00006011 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006012 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006013 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006014
6015 // Transform arguments.
6016 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006017 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006018 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6019 &ArgChanged))
6020 return ExprError();
6021
Douglas Gregorb98b1992009-08-11 05:31:07 +00006022 if (!getDerived().AlwaysRebuild() &&
6023 Callee.get() == E->getCallee() &&
6024 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006025 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006026
Douglas Gregorb98b1992009-08-11 05:31:07 +00006027 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00006028 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006029 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00006030 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006031 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006032 E->getRParenLoc());
6033}
Mike Stump1eb44332009-09-09 15:08:12 +00006034
6035template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006036ExprResult
John McCall454feb92009-12-08 09:21:05 +00006037TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006038 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006039 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006040 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006041
Douglas Gregor40d96a62011-02-28 21:54:11 +00006042 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006043 if (E->hasQualifier()) {
Douglas Gregor40d96a62011-02-28 21:54:11 +00006044 QualifierLoc
6045 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6046
6047 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00006048 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00006049 }
Mike Stump1eb44332009-09-09 15:08:12 +00006050
Eli Friedmanf595cc42009-12-04 06:40:45 +00006051 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006052 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6053 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006054 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00006055 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006056
John McCall6bb80172010-03-30 21:47:33 +00006057 NamedDecl *FoundDecl = E->getFoundDecl();
6058 if (FoundDecl == E->getMemberDecl()) {
6059 FoundDecl = Member;
6060 } else {
6061 FoundDecl = cast_or_null<NamedDecl>(
6062 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6063 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00006064 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00006065 }
6066
Douglas Gregorb98b1992009-08-11 05:31:07 +00006067 if (!getDerived().AlwaysRebuild() &&
6068 Base.get() == E->getBase() &&
Douglas Gregor40d96a62011-02-28 21:54:11 +00006069 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006070 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00006071 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00006072 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00006073
Anders Carlsson1f240322009-12-22 05:24:09 +00006074 // Mark it referenced in the new context regardless.
6075 // FIXME: this is a bit instantiation-specific.
6076 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00006077 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00006078 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00006079
John McCalld5532b62009-11-23 01:53:49 +00006080 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00006081 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00006082 TransArgs.setLAngleLoc(E->getLAngleLoc());
6083 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006084 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6085 E->getNumTemplateArgs(),
6086 TransArgs))
6087 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006088 }
Sean Huntc3021132010-05-05 15:23:54 +00006089
Douglas Gregorb98b1992009-08-11 05:31:07 +00006090 // FIXME: Bogus source location for the operator
6091 SourceLocation FakeOperatorLoc
6092 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6093
John McCallc2233c52010-01-15 08:34:02 +00006094 // FIXME: to do this check properly, we will need to preserve the
6095 // first-qualifier-in-scope here, just in case we had a dependent
6096 // base (and therefore couldn't do the check) and a
6097 // nested-name-qualifier (and therefore could do the lookup).
6098 NamedDecl *FirstQualifierInScope = 0;
6099
John McCall9ae2f072010-08-23 23:25:46 +00006100 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006101 E->isArrow(),
Douglas Gregor40d96a62011-02-28 21:54:11 +00006102 QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00006103 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00006104 Member,
John McCall6bb80172010-03-30 21:47:33 +00006105 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00006106 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00006107 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00006108 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006109}
Mike Stump1eb44332009-09-09 15:08:12 +00006110
Douglas Gregorb98b1992009-08-11 05:31:07 +00006111template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006112ExprResult
John McCall454feb92009-12-08 09:21:05 +00006113TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006114 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006115 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006116 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006117
John McCall60d7b3a2010-08-24 06:29:42 +00006118 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006119 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006120 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006121
Douglas Gregorb98b1992009-08-11 05:31:07 +00006122 if (!getDerived().AlwaysRebuild() &&
6123 LHS.get() == E->getLHS() &&
6124 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006125 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006126
Douglas Gregorb98b1992009-08-11 05:31:07 +00006127 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00006128 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006129}
6130
Mike Stump1eb44332009-09-09 15:08:12 +00006131template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006132ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006133TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00006134 CompoundAssignOperator *E) {
6135 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006136}
Mike Stump1eb44332009-09-09 15:08:12 +00006137
Douglas Gregorb98b1992009-08-11 05:31:07 +00006138template<typename Derived>
John McCall56ca35d2011-02-17 10:25:35 +00006139ExprResult TreeTransform<Derived>::
6140TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6141 // Just rebuild the common and RHS expressions and see whether we
6142 // get any changes.
6143
6144 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6145 if (commonExpr.isInvalid())
6146 return ExprError();
6147
6148 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6149 if (rhs.isInvalid())
6150 return ExprError();
6151
6152 if (!getDerived().AlwaysRebuild() &&
6153 commonExpr.get() == e->getCommon() &&
6154 rhs.get() == e->getFalseExpr())
6155 return SemaRef.Owned(e);
6156
6157 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6158 e->getQuestionLoc(),
6159 0,
6160 e->getColonLoc(),
6161 rhs.get());
6162}
6163
6164template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006165ExprResult
John McCall454feb92009-12-08 09:21:05 +00006166TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006167 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006168 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006169 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006170
John McCall60d7b3a2010-08-24 06:29:42 +00006171 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006172 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006173 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006174
John McCall60d7b3a2010-08-24 06:29:42 +00006175 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006176 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006177 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006178
Douglas Gregorb98b1992009-08-11 05:31:07 +00006179 if (!getDerived().AlwaysRebuild() &&
6180 Cond.get() == E->getCond() &&
6181 LHS.get() == E->getLHS() &&
6182 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006183 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006184
John McCall9ae2f072010-08-23 23:25:46 +00006185 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006186 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006187 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00006188 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006189 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006190}
Mike Stump1eb44332009-09-09 15:08:12 +00006191
6192template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006193ExprResult
John McCall454feb92009-12-08 09:21:05 +00006194TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00006195 // Implicit casts are eliminated during transformation, since they
6196 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00006197 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006198}
Mike Stump1eb44332009-09-09 15:08:12 +00006199
Douglas Gregorb98b1992009-08-11 05:31:07 +00006200template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006201ExprResult
John McCall454feb92009-12-08 09:21:05 +00006202TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006203 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6204 if (!Type)
6205 return ExprError();
6206
John McCall60d7b3a2010-08-24 06:29:42 +00006207 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006208 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006209 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006210 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006211
Douglas Gregorb98b1992009-08-11 05:31:07 +00006212 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006213 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006214 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006215 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006216
John McCall9d125032010-01-15 18:39:57 +00006217 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006218 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006219 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006220 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006221}
Mike Stump1eb44332009-09-09 15:08:12 +00006222
Douglas Gregorb98b1992009-08-11 05:31:07 +00006223template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006224ExprResult
John McCall454feb92009-12-08 09:21:05 +00006225TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00006226 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6227 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6228 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00006229 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006230
John McCall60d7b3a2010-08-24 06:29:42 +00006231 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006232 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006233 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006234
Douglas Gregorb98b1992009-08-11 05:31:07 +00006235 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00006236 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006237 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00006238 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006239
John McCall1d7d8d62010-01-19 22:33:45 +00006240 // Note: the expression type doesn't necessarily match the
6241 // type-as-written, but that's okay, because it should always be
6242 // derivable from the initializer.
6243
John McCall42f56b52010-01-18 19:35:47 +00006244 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006245 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00006246 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006247}
Mike Stump1eb44332009-09-09 15:08:12 +00006248
Douglas Gregorb98b1992009-08-11 05:31:07 +00006249template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006250ExprResult
John McCall454feb92009-12-08 09:21:05 +00006251TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006252 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006253 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006254 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006255
Douglas Gregorb98b1992009-08-11 05:31:07 +00006256 if (!getDerived().AlwaysRebuild() &&
6257 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006258 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006259
Douglas Gregorb98b1992009-08-11 05:31:07 +00006260 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00006261 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006262 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00006263 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006264 E->getAccessorLoc(),
6265 E->getAccessor());
6266}
Mike Stump1eb44332009-09-09 15:08:12 +00006267
Douglas Gregorb98b1992009-08-11 05:31:07 +00006268template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006269ExprResult
John McCall454feb92009-12-08 09:21:05 +00006270TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006271 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00006272
John McCallca0408f2010-08-23 06:44:23 +00006273 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006274 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6275 Inits, &InitChanged))
6276 return ExprError();
6277
Douglas Gregorb98b1992009-08-11 05:31:07 +00006278 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006279 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006280
Douglas Gregorb98b1992009-08-11 05:31:07 +00006281 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00006282 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006283}
Mike Stump1eb44332009-09-09 15:08:12 +00006284
Douglas Gregorb98b1992009-08-11 05:31:07 +00006285template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006286ExprResult
John McCall454feb92009-12-08 09:21:05 +00006287TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006288 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00006289
Douglas Gregor43959a92009-08-20 07:17:43 +00006290 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00006291 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006292 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006293 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006294
Douglas Gregor43959a92009-08-20 07:17:43 +00006295 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00006296 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006297 bool ExprChanged = false;
6298 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6299 DEnd = E->designators_end();
6300 D != DEnd; ++D) {
6301 if (D->isFieldDesignator()) {
6302 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6303 D->getDotLoc(),
6304 D->getFieldLoc()));
6305 continue;
6306 }
Mike Stump1eb44332009-09-09 15:08:12 +00006307
Douglas Gregorb98b1992009-08-11 05:31:07 +00006308 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00006309 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006310 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006311 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006312
6313 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006314 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006315
Douglas Gregorb98b1992009-08-11 05:31:07 +00006316 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6317 ArrayExprs.push_back(Index.release());
6318 continue;
6319 }
Mike Stump1eb44332009-09-09 15:08:12 +00006320
Douglas Gregorb98b1992009-08-11 05:31:07 +00006321 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00006322 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00006323 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6324 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006325 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006326
John McCall60d7b3a2010-08-24 06:29:42 +00006327 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006328 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006329 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006330
6331 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006332 End.get(),
6333 D->getLBracketLoc(),
6334 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00006335
Douglas Gregorb98b1992009-08-11 05:31:07 +00006336 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6337 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00006338
Douglas Gregorb98b1992009-08-11 05:31:07 +00006339 ArrayExprs.push_back(Start.release());
6340 ArrayExprs.push_back(End.release());
6341 }
Mike Stump1eb44332009-09-09 15:08:12 +00006342
Douglas Gregorb98b1992009-08-11 05:31:07 +00006343 if (!getDerived().AlwaysRebuild() &&
6344 Init.get() == E->getInit() &&
6345 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006346 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006347
Douglas Gregorb98b1992009-08-11 05:31:07 +00006348 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6349 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006350 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006351}
Mike Stump1eb44332009-09-09 15:08:12 +00006352
Douglas Gregorb98b1992009-08-11 05:31:07 +00006353template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006354ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006355TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00006356 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00006357 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00006358
Douglas Gregor5557b252009-10-28 00:29:27 +00006359 // FIXME: Will we ever have proper type location here? Will we actually
6360 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00006361 QualType T = getDerived().TransformType(E->getType());
6362 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006363 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006364
Douglas Gregorb98b1992009-08-11 05:31:07 +00006365 if (!getDerived().AlwaysRebuild() &&
6366 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006367 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006368
Douglas Gregorb98b1992009-08-11 05:31:07 +00006369 return getDerived().RebuildImplicitValueInitExpr(T);
6370}
Mike Stump1eb44332009-09-09 15:08:12 +00006371
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006373ExprResult
John McCall454feb92009-12-08 09:21:05 +00006374TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00006375 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6376 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006377 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006378
John McCall60d7b3a2010-08-24 06:29:42 +00006379 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006380 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006381 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006382
Douglas Gregorb98b1992009-08-11 05:31:07 +00006383 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006384 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006385 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006386 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006387
John McCall9ae2f072010-08-23 23:25:46 +00006388 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00006389 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006390}
6391
6392template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006393ExprResult
John McCall454feb92009-12-08 09:21:05 +00006394TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006395 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006396 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006397 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6398 &ArgumentChanged))
6399 return ExprError();
6400
Douglas Gregorb98b1992009-08-11 05:31:07 +00006401 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6402 move_arg(Inits),
6403 E->getRParenLoc());
6404}
Mike Stump1eb44332009-09-09 15:08:12 +00006405
Douglas Gregorb98b1992009-08-11 05:31:07 +00006406/// \brief Transform an address-of-label expression.
6407///
6408/// By default, the transformation of an address-of-label expression always
6409/// rebuilds the expression, so that the label identifier can be resolved to
6410/// the corresponding label statement by semantic analysis.
6411template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006412ExprResult
John McCall454feb92009-12-08 09:21:05 +00006413TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattner57ad3782011-02-17 20:34:02 +00006414 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6415 E->getLabel());
6416 if (!LD)
6417 return ExprError();
6418
Douglas Gregorb98b1992009-08-11 05:31:07 +00006419 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattner57ad3782011-02-17 20:34:02 +00006420 cast<LabelDecl>(LD));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006421}
Mike Stump1eb44332009-09-09 15:08:12 +00006422
6423template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006424ExprResult
John McCall454feb92009-12-08 09:21:05 +00006425TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006426 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00006427 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6428 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006429 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006430
Douglas Gregorb98b1992009-08-11 05:31:07 +00006431 if (!getDerived().AlwaysRebuild() &&
6432 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00006433 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006434
6435 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006436 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006437 E->getRParenLoc());
6438}
Mike Stump1eb44332009-09-09 15:08:12 +00006439
Douglas Gregorb98b1992009-08-11 05:31:07 +00006440template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006441ExprResult
John McCall454feb92009-12-08 09:21:05 +00006442TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006443 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006444 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006445 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006446
John McCall60d7b3a2010-08-24 06:29:42 +00006447 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006448 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006449 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006450
John McCall60d7b3a2010-08-24 06:29:42 +00006451 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006452 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006453 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006454
Douglas Gregorb98b1992009-08-11 05:31:07 +00006455 if (!getDerived().AlwaysRebuild() &&
6456 Cond.get() == E->getCond() &&
6457 LHS.get() == E->getLHS() &&
6458 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00006459 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006460
Douglas Gregorb98b1992009-08-11 05:31:07 +00006461 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006462 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006463 E->getRParenLoc());
6464}
Mike Stump1eb44332009-09-09 15:08:12 +00006465
Douglas Gregorb98b1992009-08-11 05:31:07 +00006466template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006467ExprResult
John McCall454feb92009-12-08 09:21:05 +00006468TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006469 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006470}
6471
6472template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006473ExprResult
John McCall454feb92009-12-08 09:21:05 +00006474TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00006475 switch (E->getOperator()) {
6476 case OO_New:
6477 case OO_Delete:
6478 case OO_Array_New:
6479 case OO_Array_Delete:
6480 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00006481 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006482
Douglas Gregor668d6d92009-12-13 20:44:55 +00006483 case OO_Call: {
6484 // This is a call to an object's operator().
6485 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6486
6487 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00006488 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00006489 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006490 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006491
6492 // FIXME: Poor location information
6493 SourceLocation FakeLParenLoc
6494 = SemaRef.PP.getLocForEndOfToken(
6495 static_cast<Expr *>(Object.get())->getLocEnd());
6496
6497 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00006498 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006499 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6500 Args))
6501 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006502
John McCall9ae2f072010-08-23 23:25:46 +00006503 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00006504 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00006505 E->getLocEnd());
6506 }
6507
6508#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6509 case OO_##Name:
6510#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6511#include "clang/Basic/OperatorKinds.def"
6512 case OO_Subscript:
6513 // Handled below.
6514 break;
6515
6516 case OO_Conditional:
6517 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00006518 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006519
6520 case OO_None:
6521 case NUM_OVERLOADED_OPERATORS:
6522 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00006523 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00006524 }
6525
John McCall60d7b3a2010-08-24 06:29:42 +00006526 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006527 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006528 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006529
John McCall60d7b3a2010-08-24 06:29:42 +00006530 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006531 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006532 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006533
John McCall60d7b3a2010-08-24 06:29:42 +00006534 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00006535 if (E->getNumArgs() == 2) {
6536 Second = getDerived().TransformExpr(E->getArg(1));
6537 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006538 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006539 }
Mike Stump1eb44332009-09-09 15:08:12 +00006540
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541 if (!getDerived().AlwaysRebuild() &&
6542 Callee.get() == E->getCallee() &&
6543 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00006544 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00006545 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006546
Douglas Gregorb98b1992009-08-11 05:31:07 +00006547 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6548 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00006549 Callee.get(),
6550 First.get(),
6551 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006552}
Mike Stump1eb44332009-09-09 15:08:12 +00006553
Douglas Gregorb98b1992009-08-11 05:31:07 +00006554template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006555ExprResult
John McCall454feb92009-12-08 09:21:05 +00006556TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6557 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006558}
Mike Stump1eb44332009-09-09 15:08:12 +00006559
Douglas Gregorb98b1992009-08-11 05:31:07 +00006560template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006561ExprResult
Peter Collingbournee08ce652011-02-09 21:07:24 +00006562TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6563 // Transform the callee.
6564 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6565 if (Callee.isInvalid())
6566 return ExprError();
6567
6568 // Transform exec config.
6569 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6570 if (EC.isInvalid())
6571 return ExprError();
6572
6573 // Transform arguments.
6574 bool ArgChanged = false;
6575 ASTOwningVector<Expr*> Args(SemaRef);
6576 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6577 &ArgChanged))
6578 return ExprError();
6579
6580 if (!getDerived().AlwaysRebuild() &&
6581 Callee.get() == E->getCallee() &&
6582 !ArgChanged)
6583 return SemaRef.Owned(E);
6584
6585 // FIXME: Wrong source location information for the '('.
6586 SourceLocation FakeLParenLoc
6587 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6588 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6589 move_arg(Args),
6590 E->getRParenLoc(), EC.get());
6591}
6592
6593template<typename Derived>
6594ExprResult
John McCall454feb92009-12-08 09:21:05 +00006595TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006596 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6597 if (!Type)
6598 return ExprError();
6599
John McCall60d7b3a2010-08-24 06:29:42 +00006600 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006601 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006602 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006603 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006604
Douglas Gregorb98b1992009-08-11 05:31:07 +00006605 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006606 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006607 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006608 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006609
Douglas Gregorb98b1992009-08-11 05:31:07 +00006610 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00006611 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00006612 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6613 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6614 SourceLocation FakeRParenLoc
6615 = SemaRef.PP.getLocForEndOfToken(
6616 E->getSubExpr()->getSourceRange().getEnd());
6617 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00006618 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006619 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006620 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006621 FakeRAngleLoc,
6622 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00006623 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006624 FakeRParenLoc);
6625}
Mike Stump1eb44332009-09-09 15:08:12 +00006626
Douglas Gregorb98b1992009-08-11 05:31:07 +00006627template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006628ExprResult
John McCall454feb92009-12-08 09:21:05 +00006629TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6630 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631}
Mike Stump1eb44332009-09-09 15:08:12 +00006632
6633template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006634ExprResult
John McCall454feb92009-12-08 09:21:05 +00006635TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6636 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006637}
6638
Douglas Gregorb98b1992009-08-11 05:31:07 +00006639template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006640ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006641TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006642 CXXReinterpretCastExpr *E) {
6643 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006644}
Mike Stump1eb44332009-09-09 15:08:12 +00006645
Douglas Gregorb98b1992009-08-11 05:31:07 +00006646template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006647ExprResult
John McCall454feb92009-12-08 09:21:05 +00006648TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6649 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006650}
Mike Stump1eb44332009-09-09 15:08:12 +00006651
Douglas Gregorb98b1992009-08-11 05:31:07 +00006652template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006653ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006654TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00006655 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006656 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6657 if (!Type)
6658 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006659
John McCall60d7b3a2010-08-24 06:29:42 +00006660 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00006661 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006662 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006663 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006664
Douglas Gregorb98b1992009-08-11 05:31:07 +00006665 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006666 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006667 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006668 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006669
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006670 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006671 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006672 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006673 E->getRParenLoc());
6674}
Mike Stump1eb44332009-09-09 15:08:12 +00006675
Douglas Gregorb98b1992009-08-11 05:31:07 +00006676template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006677ExprResult
John McCall454feb92009-12-08 09:21:05 +00006678TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006679 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006680 TypeSourceInfo *TInfo
6681 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6682 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006683 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006684
Douglas Gregorb98b1992009-08-11 05:31:07 +00006685 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006686 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006687 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006688
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006689 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6690 E->getLocStart(),
6691 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006692 E->getLocEnd());
6693 }
Mike Stump1eb44332009-09-09 15:08:12 +00006694
Douglas Gregorb98b1992009-08-11 05:31:07 +00006695 // We don't know whether the expression is potentially evaluated until
6696 // after we perform semantic analysis, so the expression is potentially
6697 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00006698 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00006699 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00006700
John McCall60d7b3a2010-08-24 06:29:42 +00006701 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006702 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006703 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006704
Douglas Gregorb98b1992009-08-11 05:31:07 +00006705 if (!getDerived().AlwaysRebuild() &&
6706 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006707 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006708
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00006709 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6710 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00006711 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006712 E->getLocEnd());
6713}
6714
6715template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006716ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00006717TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6718 if (E->isTypeOperand()) {
6719 TypeSourceInfo *TInfo
6720 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6721 if (!TInfo)
6722 return ExprError();
6723
6724 if (!getDerived().AlwaysRebuild() &&
6725 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006726 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006727
Douglas Gregor3c52a212011-03-06 17:40:41 +00006728 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet01b7c302010-09-08 12:20:18 +00006729 E->getLocStart(),
6730 TInfo,
6731 E->getLocEnd());
6732 }
6733
6734 // We don't know whether the expression is potentially evaluated until
6735 // after we perform semantic analysis, so the expression is potentially
6736 // potentially evaluated.
6737 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6738
6739 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6740 if (SubExpr.isInvalid())
6741 return ExprError();
6742
6743 if (!getDerived().AlwaysRebuild() &&
6744 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006745 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00006746
6747 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6748 E->getLocStart(),
6749 SubExpr.get(),
6750 E->getLocEnd());
6751}
6752
6753template<typename Derived>
6754ExprResult
John McCall454feb92009-12-08 09:21:05 +00006755TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006756 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006757}
Mike Stump1eb44332009-09-09 15:08:12 +00006758
Douglas Gregorb98b1992009-08-11 05:31:07 +00006759template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006760ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006761TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00006762 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006763 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006764}
Mike Stump1eb44332009-09-09 15:08:12 +00006765
Douglas Gregorb98b1992009-08-11 05:31:07 +00006766template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006767ExprResult
John McCall454feb92009-12-08 09:21:05 +00006768TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006769 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith7a614d82011-06-11 17:19:42 +00006770 QualType T;
6771 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6772 T = MD->getThisType(getSema().Context);
6773 else
6774 T = getSema().Context.getPointerType(
6775 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump1eb44332009-09-09 15:08:12 +00006776
Douglas Gregorba48d6a2010-09-09 16:55:46 +00006777 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00006778 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006779
Douglas Gregor828a1972010-01-07 23:12:05 +00006780 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
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>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006786 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006787 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006788 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006789
Douglas Gregorb98b1992009-08-11 05:31:07 +00006790 if (!getDerived().AlwaysRebuild() &&
6791 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00006792 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006793
John McCall9ae2f072010-08-23 23:25:46 +00006794 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006795}
Mike Stump1eb44332009-09-09 15:08:12 +00006796
Douglas Gregorb98b1992009-08-11 05:31:07 +00006797template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006798ExprResult
John McCall454feb92009-12-08 09:21:05 +00006799TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00006800 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006801 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6802 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006803 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00006804 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006805
Chandler Carruth53cb6f82010-02-08 06:42:49 +00006806 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00006808 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006809
Douglas Gregor036aed12009-12-23 23:03:06 +00006810 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006811}
Mike Stump1eb44332009-09-09 15:08:12 +00006812
Douglas Gregorb98b1992009-08-11 05:31:07 +00006813template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006814ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006815TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6816 CXXScalarValueInitExpr *E) {
6817 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6818 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006819 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006820
Douglas Gregorb98b1992009-08-11 05:31:07 +00006821 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006822 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006823 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006824
Douglas Gregorab6677e2010-09-08 00:15:04 +00006825 return getDerived().RebuildCXXScalarValueInitExpr(T,
6826 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006827 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006828}
Mike Stump1eb44332009-09-09 15:08:12 +00006829
Douglas Gregorb98b1992009-08-11 05:31:07 +00006830template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006831ExprResult
John McCall454feb92009-12-08 09:21:05 +00006832TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006833 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006834 TypeSourceInfo *AllocTypeInfo
6835 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6836 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006837 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006838
Douglas Gregorb98b1992009-08-11 05:31:07 +00006839 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006840 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006841 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006842 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006843
Douglas Gregorb98b1992009-08-11 05:31:07 +00006844 // Transform the placement arguments (if any).
6845 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006846 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006847 if (getDerived().TransformExprs(E->getPlacementArgs(),
6848 E->getNumPlacementArgs(), true,
6849 PlacementArgs, &ArgumentChanged))
6850 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006851
Douglas Gregor43959a92009-08-20 07:17:43 +00006852 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00006853 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006854 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6855 ConstructorArgs, &ArgumentChanged))
6856 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006857
Douglas Gregor1af74512010-02-26 00:38:10 +00006858 // Transform constructor, new operator, and delete operator.
6859 CXXConstructorDecl *Constructor = 0;
6860 if (E->getConstructor()) {
6861 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006862 getDerived().TransformDecl(E->getLocStart(),
6863 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006864 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006865 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006866 }
6867
6868 FunctionDecl *OperatorNew = 0;
6869 if (E->getOperatorNew()) {
6870 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006871 getDerived().TransformDecl(E->getLocStart(),
6872 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006873 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006874 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006875 }
6876
6877 FunctionDecl *OperatorDelete = 0;
6878 if (E->getOperatorDelete()) {
6879 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006880 getDerived().TransformDecl(E->getLocStart(),
6881 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006882 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006883 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006884 }
Sean Huntc3021132010-05-05 15:23:54 +00006885
Douglas Gregorb98b1992009-08-11 05:31:07 +00006886 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006887 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006888 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006889 Constructor == E->getConstructor() &&
6890 OperatorNew == E->getOperatorNew() &&
6891 OperatorDelete == E->getOperatorDelete() &&
6892 !ArgumentChanged) {
6893 // Mark any declarations we need as referenced.
6894 // FIXME: instantiation-specific.
6895 if (Constructor)
6896 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6897 if (OperatorNew)
6898 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6899 if (OperatorDelete)
6900 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00006901 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006902 }
Mike Stump1eb44332009-09-09 15:08:12 +00006903
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006904 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006905 if (!ArraySize.get()) {
6906 // If no array size was specified, but the new expression was
6907 // instantiated with an array type (e.g., "new T" where T is
6908 // instantiated with "int[4]"), extract the outer bound from the
6909 // array type as our array size. We do this with constant and
6910 // dependently-sized array types.
6911 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6912 if (!ArrayT) {
6913 // Do nothing
6914 } else if (const ConstantArrayType *ConsArrayT
6915 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00006916 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006917 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6918 ConsArrayT->getSize(),
6919 SemaRef.Context.getSizeType(),
6920 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006921 AllocType = ConsArrayT->getElementType();
6922 } else if (const DependentSizedArrayType *DepArrayT
6923 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6924 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00006925 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006926 AllocType = DepArrayT->getElementType();
6927 }
6928 }
6929 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006930
Douglas Gregorb98b1992009-08-11 05:31:07 +00006931 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6932 E->isGlobalNew(),
6933 /*FIXME:*/E->getLocStart(),
6934 move_arg(PlacementArgs),
6935 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00006936 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006937 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006938 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00006939 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006940 /*FIXME:*/E->getLocStart(),
6941 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00006942 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006943}
Mike Stump1eb44332009-09-09 15:08:12 +00006944
Douglas Gregorb98b1992009-08-11 05:31:07 +00006945template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006946ExprResult
John McCall454feb92009-12-08 09:21:05 +00006947TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006948 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006949 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006950 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006951
Douglas Gregor1af74512010-02-26 00:38:10 +00006952 // Transform the delete operator, if known.
6953 FunctionDecl *OperatorDelete = 0;
6954 if (E->getOperatorDelete()) {
6955 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006956 getDerived().TransformDecl(E->getLocStart(),
6957 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006958 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006959 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006960 }
Sean Huntc3021132010-05-05 15:23:54 +00006961
Douglas Gregorb98b1992009-08-11 05:31:07 +00006962 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006963 Operand.get() == E->getArgument() &&
6964 OperatorDelete == E->getOperatorDelete()) {
6965 // Mark any declarations we need as referenced.
6966 // FIXME: instantiation-specific.
6967 if (OperatorDelete)
6968 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00006969
6970 if (!E->getArgument()->isTypeDependent()) {
6971 QualType Destroyed = SemaRef.Context.getBaseElementType(
6972 E->getDestroyedType());
6973 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6974 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6975 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6976 SemaRef.LookupDestructor(Record));
6977 }
6978 }
6979
John McCall3fa5cae2010-10-26 07:05:15 +00006980 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006981 }
Mike Stump1eb44332009-09-09 15:08:12 +00006982
Douglas Gregorb98b1992009-08-11 05:31:07 +00006983 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6984 E->isGlobalDelete(),
6985 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00006986 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006987}
Mike Stump1eb44332009-09-09 15:08:12 +00006988
Douglas Gregorb98b1992009-08-11 05:31:07 +00006989template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006990ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00006991TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00006992 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006993 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00006994 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006995 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006996
John McCallb3d87482010-08-24 05:47:05 +00006997 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006998 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006999 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007000 E->getOperatorLoc(),
7001 E->isArrow()? tok::arrow : tok::period,
7002 ObjectTypePtr,
7003 MayBePseudoDestructor);
7004 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007005 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007006
John McCallb3d87482010-08-24 05:47:05 +00007007 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007008 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7009 if (QualifierLoc) {
7010 QualifierLoc
7011 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7012 if (!QualifierLoc)
John McCall43fed0d2010-11-12 08:19:04 +00007013 return ExprError();
7014 }
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007015 CXXScopeSpec SS;
7016 SS.Adopt(QualifierLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00007017
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007018 PseudoDestructorTypeStorage Destroyed;
7019 if (E->getDestroyedTypeInfo()) {
7020 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00007021 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregorb71d8212011-03-02 18:32:08 +00007022 ObjectType, 0, SS);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007023 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007024 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007025 Destroyed = DestroyedTypeInfo;
7026 } else if (ObjectType->isDependentType()) {
7027 // We aren't likely to be able to resolve the identifier down to a type
7028 // now anyway, so just retain the identifier.
7029 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7030 E->getDestroyedTypeLoc());
7031 } else {
7032 // Look for a destructor known with the given name.
John McCallb3d87482010-08-24 05:47:05 +00007033 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007034 *E->getDestroyedTypeIdentifier(),
7035 E->getDestroyedTypeLoc(),
7036 /*Scope=*/0,
7037 SS, ObjectTypePtr,
7038 false);
7039 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007040 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007041
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007042 Destroyed
7043 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7044 E->getDestroyedTypeLoc());
7045 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007046
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007047 TypeSourceInfo *ScopeTypeInfo = 0;
7048 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00007049 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007050 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007051 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00007052 }
Sean Huntc3021132010-05-05 15:23:54 +00007053
John McCall9ae2f072010-08-23 23:25:46 +00007054 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00007055 E->getOperatorLoc(),
7056 E->isArrow(),
Douglas Gregorf3db29f2011-02-25 18:19:59 +00007057 SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007058 ScopeTypeInfo,
7059 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007060 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007061 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00007062}
Mike Stump1eb44332009-09-09 15:08:12 +00007063
Douglas Gregora71d8192009-09-04 17:36:40 +00007064template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007065ExprResult
John McCallba135432009-11-21 08:51:07 +00007066TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00007067 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00007068 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7069 Sema::LookupOrdinaryName);
7070
7071 // Transform all the decls.
7072 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7073 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007074 NamedDecl *InstD = static_cast<NamedDecl*>(
7075 getDerived().TransformDecl(Old->getNameLoc(),
7076 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007077 if (!InstD) {
7078 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7079 // This can happen because of dependent hiding.
7080 if (isa<UsingShadowDecl>(*I))
7081 continue;
7082 else
John McCallf312b1e2010-08-26 23:41:50 +00007083 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00007084 }
John McCallf7a1a742009-11-24 19:00:30 +00007085
7086 // Expand using declarations.
7087 if (isa<UsingDecl>(InstD)) {
7088 UsingDecl *UD = cast<UsingDecl>(InstD);
7089 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7090 E = UD->shadow_end(); I != E; ++I)
7091 R.addDecl(*I);
7092 continue;
7093 }
7094
7095 R.addDecl(InstD);
7096 }
7097
7098 // Resolve a kind, but don't do any further analysis. If it's
7099 // ambiguous, the callee needs to deal with it.
7100 R.resolveKind();
7101
7102 // Rebuild the nested-name qualifier, if present.
7103 CXXScopeSpec SS;
Douglas Gregor4c9be892011-02-28 20:01:57 +00007104 if (Old->getQualifierLoc()) {
7105 NestedNameSpecifierLoc QualifierLoc
7106 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7107 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007108 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007109
Douglas Gregor4c9be892011-02-28 20:01:57 +00007110 SS.Adopt(QualifierLoc);
Sean Huntc3021132010-05-05 15:23:54 +00007111 }
7112
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007113 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00007114 CXXRecordDecl *NamingClass
7115 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7116 Old->getNameLoc(),
7117 Old->getNamingClass()));
7118 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007119 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007120
Douglas Gregor66c45152010-04-27 16:10:10 +00007121 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00007122 }
7123
7124 // If we have no template arguments, it's a normal declaration name.
7125 if (!Old->hasExplicitTemplateArgs())
7126 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7127
7128 // If we have template arguments, rebuild them, then rebuild the
7129 // templateid expression.
7130 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007131 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7132 Old->getNumTemplateArgs(),
7133 TransArgs))
7134 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00007135
7136 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7137 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007138}
Mike Stump1eb44332009-09-09 15:08:12 +00007139
Douglas Gregorb98b1992009-08-11 05:31:07 +00007140template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007141ExprResult
John McCall454feb92009-12-08 09:21:05 +00007142TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007143 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7144 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007145 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007146
Douglas Gregorb98b1992009-08-11 05:31:07 +00007147 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00007148 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007149 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007150
Mike Stump1eb44332009-09-09 15:08:12 +00007151 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007152 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007153 T,
7154 E->getLocEnd());
7155}
Mike Stump1eb44332009-09-09 15:08:12 +00007156
Douglas Gregorb98b1992009-08-11 05:31:07 +00007157template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007158ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00007159TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7160 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7161 if (!LhsT)
7162 return ExprError();
7163
7164 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7165 if (!RhsT)
7166 return ExprError();
7167
7168 if (!getDerived().AlwaysRebuild() &&
7169 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7170 return SemaRef.Owned(E);
7171
7172 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7173 E->getLocStart(),
7174 LhsT, RhsT,
7175 E->getLocEnd());
7176}
7177
7178template<typename Derived>
7179ExprResult
John Wiegley21ff2e52011-04-28 00:16:57 +00007180TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7181 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7182 if (!T)
7183 return ExprError();
7184
7185 if (!getDerived().AlwaysRebuild() &&
7186 T == E->getQueriedTypeSourceInfo())
7187 return SemaRef.Owned(E);
7188
7189 ExprResult SubExpr;
7190 {
7191 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7192 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7193 if (SubExpr.isInvalid())
7194 return ExprError();
7195
7196 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7197 return SemaRef.Owned(E);
7198 }
7199
7200 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7201 E->getLocStart(),
7202 T,
7203 SubExpr.get(),
7204 E->getLocEnd());
7205}
7206
7207template<typename Derived>
7208ExprResult
John Wiegley55262202011-04-25 06:54:41 +00007209TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7210 ExprResult SubExpr;
7211 {
7212 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7213 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7214 if (SubExpr.isInvalid())
7215 return ExprError();
7216
7217 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7218 return SemaRef.Owned(E);
7219 }
7220
7221 return getDerived().RebuildExpressionTrait(
7222 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7223}
7224
7225template<typename Derived>
7226ExprResult
John McCall865d4472009-11-19 22:55:06 +00007227TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007228 DependentScopeDeclRefExpr *E) {
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007229 NestedNameSpecifierLoc QualifierLoc
7230 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7231 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007232 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007233
John McCall43fed0d2010-11-12 08:19:04 +00007234 // TODO: If this is a conversion-function-id, verify that the
7235 // destination type name (if present) resolves the same way after
7236 // instantiation as it did in the local scope.
7237
Abramo Bagnara25777432010-08-11 22:01:17 +00007238 DeclarationNameInfo NameInfo
7239 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7240 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007241 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007242
John McCallf7a1a742009-11-24 19:00:30 +00007243 if (!E->hasExplicitTemplateArgs()) {
7244 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007245 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007246 // Note: it is sufficient to compare the Name component of NameInfo:
7247 // if name has not changed, DNLoc has not changed either.
7248 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00007249 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007250
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007251 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007252 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007253 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00007254 }
John McCalld5532b62009-11-23 01:53:49 +00007255
7256 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007257 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7258 E->getNumTemplateArgs(),
7259 TransArgs))
7260 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007261
Douglas Gregor00cf3cc2011-02-25 20:49:16 +00007262 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnara25777432010-08-11 22:01:17 +00007263 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00007264 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007265}
7266
7267template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007268ExprResult
John McCall454feb92009-12-08 09:21:05 +00007269TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00007270 // CXXConstructExprs are always implicit, so when we have a
7271 // 1-argument construction we just transform that argument.
7272 if (E->getNumArgs() == 1 ||
7273 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7274 return getDerived().TransformExpr(E->getArg(0));
7275
Douglas Gregorb98b1992009-08-11 05:31:07 +00007276 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7277
7278 QualType T = getDerived().TransformType(E->getType());
7279 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00007280 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00007281
7282 CXXConstructorDecl *Constructor
7283 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007284 getDerived().TransformDecl(E->getLocStart(),
7285 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007286 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007287 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007288
Douglas Gregorb98b1992009-08-11 05:31:07 +00007289 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007290 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007291 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7292 &ArgumentChanged))
7293 return ExprError();
7294
Douglas Gregorb98b1992009-08-11 05:31:07 +00007295 if (!getDerived().AlwaysRebuild() &&
7296 T == E->getType() &&
7297 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00007298 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00007299 // Mark the constructor as referenced.
7300 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00007301 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007302 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00007303 }
Mike Stump1eb44332009-09-09 15:08:12 +00007304
Douglas Gregor4411d2e2009-12-14 16:27:04 +00007305 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7306 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00007307 move_arg(Args),
7308 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00007309 E->getConstructionKind(),
7310 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007311}
Mike Stump1eb44332009-09-09 15:08:12 +00007312
Douglas Gregorb98b1992009-08-11 05:31:07 +00007313/// \brief Transform a C++ temporary-binding expression.
7314///
Douglas Gregor51326552009-12-24 18:51:59 +00007315/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7316/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007317template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007318ExprResult
John McCall454feb92009-12-08 09:21:05 +00007319TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007320 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007321}
Mike Stump1eb44332009-09-09 15:08:12 +00007322
John McCall4765fa02010-12-06 08:20:24 +00007323/// \brief Transform a C++ expression that contains cleanups that should
7324/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007325///
John McCall4765fa02010-12-06 08:20:24 +00007326/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00007327/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00007328template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007329ExprResult
John McCall4765fa02010-12-06 08:20:24 +00007330TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00007331 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007332}
Mike Stump1eb44332009-09-09 15:08:12 +00007333
Douglas Gregorb98b1992009-08-11 05:31:07 +00007334template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007335ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007336TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00007337 CXXTemporaryObjectExpr *E) {
7338 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7339 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007340 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007341
Douglas Gregorb98b1992009-08-11 05:31:07 +00007342 CXXConstructorDecl *Constructor
7343 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00007344 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007345 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007346 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00007347 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007348
Douglas Gregorb98b1992009-08-11 05:31:07 +00007349 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007350 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007351 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00007352 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7353 &ArgumentChanged))
7354 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007355
Douglas Gregorb98b1992009-08-11 05:31:07 +00007356 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007357 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007358 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00007359 !ArgumentChanged) {
7360 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00007361 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00007362 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00007363 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00007364
7365 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7366 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007367 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007368 E->getLocEnd());
7369}
Mike Stump1eb44332009-09-09 15:08:12 +00007370
Douglas Gregorb98b1992009-08-11 05:31:07 +00007371template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007372ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007373TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00007374 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00007375 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7376 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00007377 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007378
Douglas Gregorb98b1992009-08-11 05:31:07 +00007379 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007380 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007381 Args.reserve(E->arg_size());
7382 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7383 &ArgumentChanged))
7384 return ExprError();
7385
Douglas Gregorb98b1992009-08-11 05:31:07 +00007386 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00007387 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00007388 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007389 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007390
Douglas Gregorb98b1992009-08-11 05:31:07 +00007391 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00007392 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007393 E->getLParenLoc(),
7394 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00007395 E->getRParenLoc());
7396}
Mike Stump1eb44332009-09-09 15:08:12 +00007397
Douglas Gregorb98b1992009-08-11 05:31:07 +00007398template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007399ExprResult
John McCall865d4472009-11-19 22:55:06 +00007400TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00007401 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007402 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007403 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007404 Expr *OldBase;
7405 QualType BaseType;
7406 QualType ObjectType;
7407 if (!E->isImplicitAccess()) {
7408 OldBase = E->getBase();
7409 Base = getDerived().TransformExpr(OldBase);
7410 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007411 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007412
John McCallaa81e162009-12-01 22:10:20 +00007413 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00007414 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00007415 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00007416 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007417 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00007418 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00007419 ObjectTy,
7420 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00007421 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007422 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007423
John McCallb3d87482010-08-24 05:47:05 +00007424 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00007425 BaseType = ((Expr*) Base.get())->getType();
7426 } else {
7427 OldBase = 0;
7428 BaseType = getDerived().TransformType(E->getBaseType());
7429 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7430 }
Mike Stump1eb44332009-09-09 15:08:12 +00007431
Douglas Gregor6cd21982009-10-20 05:58:46 +00007432 // Transform the first part of the nested-name-specifier that qualifies
7433 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00007434 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00007435 = getDerived().TransformFirstQualifierInScope(
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007436 E->getFirstQualifierFoundInScope(),
7437 E->getQualifierLoc().getBeginLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00007438
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007439 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregora38c6872009-09-03 16:14:30 +00007440 if (E->getQualifier()) {
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007441 QualifierLoc
7442 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7443 ObjectType,
7444 FirstQualifierInScope);
7445 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007446 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00007447 }
Mike Stump1eb44332009-09-09 15:08:12 +00007448
John McCall43fed0d2010-11-12 08:19:04 +00007449 // TODO: If this is a conversion-function-id, verify that the
7450 // destination type name (if present) resolves the same way after
7451 // instantiation as it did in the local scope.
7452
Abramo Bagnara25777432010-08-11 22:01:17 +00007453 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00007454 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00007455 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00007456 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007457
John McCallaa81e162009-12-01 22:10:20 +00007458 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007459 // This is a reference to a member without an explicitly-specified
7460 // template argument list. Optimize for this common case.
7461 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00007462 Base.get() == OldBase &&
7463 BaseType == E->getBaseType() &&
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007464 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00007465 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007466 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00007467 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007468
John McCall9ae2f072010-08-23 23:25:46 +00007469 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007470 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007471 E->isArrow(),
7472 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007473 QualifierLoc,
John McCall129e2df2009-11-30 22:42:35 +00007474 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007475 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007476 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007477 }
7478
John McCalld5532b62009-11-23 01:53:49 +00007479 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007480 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7481 E->getNumTemplateArgs(),
7482 TransArgs))
7483 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007484
John McCall9ae2f072010-08-23 23:25:46 +00007485 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007486 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007487 E->isArrow(),
7488 E->getOperatorLoc(),
Douglas Gregor7c3179c2011-02-28 18:50:33 +00007489 QualifierLoc,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007490 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00007491 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00007492 &TransArgs);
7493}
7494
7495template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007496ExprResult
John McCall454feb92009-12-08 09:21:05 +00007497TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00007498 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007499 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00007500 QualType BaseType;
7501 if (!Old->isImplicitAccess()) {
7502 Base = getDerived().TransformExpr(Old->getBase());
7503 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007504 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00007505 BaseType = ((Expr*) Base.get())->getType();
7506 } else {
7507 BaseType = getDerived().TransformType(Old->getBaseType());
7508 }
John McCall129e2df2009-11-30 22:42:35 +00007509
Douglas Gregor4c9be892011-02-28 20:01:57 +00007510 NestedNameSpecifierLoc QualifierLoc;
7511 if (Old->getQualifierLoc()) {
7512 QualifierLoc
7513 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7514 if (!QualifierLoc)
John McCallf312b1e2010-08-26 23:41:50 +00007515 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007516 }
7517
Abramo Bagnara25777432010-08-11 22:01:17 +00007518 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00007519 Sema::LookupOrdinaryName);
7520
7521 // Transform all the decls.
7522 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7523 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00007524 NamedDecl *InstD = static_cast<NamedDecl*>(
7525 getDerived().TransformDecl(Old->getMemberLoc(),
7526 *I));
John McCall9f54ad42009-12-10 09:41:52 +00007527 if (!InstD) {
7528 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7529 // This can happen because of dependent hiding.
7530 if (isa<UsingShadowDecl>(*I))
7531 continue;
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007532 else {
7533 R.clear();
John McCallf312b1e2010-08-26 23:41:50 +00007534 return ExprError();
Argyrios Kyrtzidis34f52d12011-04-22 01:18:40 +00007535 }
John McCall9f54ad42009-12-10 09:41:52 +00007536 }
John McCall129e2df2009-11-30 22:42:35 +00007537
7538 // Expand using declarations.
7539 if (isa<UsingDecl>(InstD)) {
7540 UsingDecl *UD = cast<UsingDecl>(InstD);
7541 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7542 E = UD->shadow_end(); I != E; ++I)
7543 R.addDecl(*I);
7544 continue;
7545 }
7546
7547 R.addDecl(InstD);
7548 }
7549
7550 R.resolveKind();
7551
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007552 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00007553 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00007554 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007555 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00007556 Old->getMemberLoc(),
7557 Old->getNamingClass()));
7558 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00007559 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007560
Douglas Gregor66c45152010-04-27 16:10:10 +00007561 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00007562 }
Sean Huntc3021132010-05-05 15:23:54 +00007563
John McCall129e2df2009-11-30 22:42:35 +00007564 TemplateArgumentListInfo TransArgs;
7565 if (Old->hasExplicitTemplateArgs()) {
7566 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7567 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00007568 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7569 Old->getNumTemplateArgs(),
7570 TransArgs))
7571 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00007572 }
John McCallc2233c52010-01-15 08:34:02 +00007573
7574 // FIXME: to do this check properly, we will need to preserve the
7575 // first-qualifier-in-scope here, just in case we had a dependent
7576 // base (and therefore couldn't do the check) and a
7577 // nested-name-qualifier (and therefore could do the lookup).
7578 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00007579
John McCall9ae2f072010-08-23 23:25:46 +00007580 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00007581 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00007582 Old->getOperatorLoc(),
7583 Old->isArrow(),
Douglas Gregor4c9be892011-02-28 20:01:57 +00007584 QualifierLoc,
John McCallc2233c52010-01-15 08:34:02 +00007585 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00007586 R,
7587 (Old->hasExplicitTemplateArgs()
7588 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00007589}
7590
7591template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007592ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00007593TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Sean Hunteea06c62011-05-31 19:54:49 +00007594 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl2e156222010-09-10 20:55:43 +00007595 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7596 if (SubExpr.isInvalid())
7597 return ExprError();
7598
7599 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00007600 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00007601
7602 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7603}
7604
7605template<typename Derived>
7606ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00007607TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor4f1d2822011-01-13 00:19:55 +00007608 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7609 if (Pattern.isInvalid())
7610 return ExprError();
7611
7612 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7613 return SemaRef.Owned(E);
7614
Douglas Gregor67fd1252011-01-14 21:20:45 +00007615 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7616 E->getNumExpansions());
Douglas Gregorbe230c32011-01-03 17:17:50 +00007617}
Douglas Gregoree8aff02011-01-04 17:33:58 +00007618
7619template<typename Derived>
7620ExprResult
7621TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7622 // If E is not value-dependent, then nothing will change when we transform it.
7623 // Note: This is an instantiation-centric view.
7624 if (!E->isValueDependent())
7625 return SemaRef.Owned(E);
7626
7627 // Note: None of the implementations of TryExpandParameterPacks can ever
7628 // produce a diagnostic when given only a single unexpanded parameter pack,
7629 // so
7630 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7631 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00007632 bool RetainExpansion = false;
Douglas Gregorcded4f62011-01-14 17:04:44 +00007633 llvm::Optional<unsigned> NumExpansions;
Douglas Gregoree8aff02011-01-04 17:33:58 +00007634 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7635 &Unexpanded, 1,
Douglas Gregord3731192011-01-10 07:32:04 +00007636 ShouldExpand, RetainExpansion,
7637 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00007638 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00007639
Douglas Gregord3731192011-01-10 07:32:04 +00007640 if (!ShouldExpand || RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00007641 return SemaRef.Owned(E);
7642
7643 // We now know the length of the parameter pack, so build a new expression
7644 // that stores that length.
7645 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7646 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorcded4f62011-01-14 17:04:44 +00007647 *NumExpansions);
Douglas Gregoree8aff02011-01-04 17:33:58 +00007648}
7649
Douglas Gregorbe230c32011-01-03 17:17:50 +00007650template<typename Derived>
7651ExprResult
Douglas Gregorc7793c72011-01-15 01:15:58 +00007652TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7653 SubstNonTypeTemplateParmPackExpr *E) {
7654 // Default behavior is to do nothing with this transformation.
7655 return SemaRef.Owned(E);
7656}
7657
7658template<typename Derived>
7659ExprResult
Douglas Gregor03e80032011-06-21 17:03:29 +00007660TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7661 MaterializeTemporaryExpr *E) {
7662 return getDerived().TransformExpr(E->GetTemporaryExpr());
7663}
7664
7665template<typename Derived>
7666ExprResult
John McCall454feb92009-12-08 09:21:05 +00007667TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007668 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007669}
7670
Mike Stump1eb44332009-09-09 15:08:12 +00007671template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007672ExprResult
John McCall454feb92009-12-08 09:21:05 +00007673TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00007674 TypeSourceInfo *EncodedTypeInfo
7675 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7676 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007677 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007678
Douglas Gregorb98b1992009-08-11 05:31:07 +00007679 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00007680 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00007681 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007682
7683 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00007684 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00007685 E->getRParenLoc());
7686}
Mike Stump1eb44332009-09-09 15:08:12 +00007687
Douglas Gregorb98b1992009-08-11 05:31:07 +00007688template<typename Derived>
John McCallf85e1932011-06-15 23:02:42 +00007689ExprResult TreeTransform<Derived>::
7690TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7691 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7692 if (result.isInvalid()) return ExprError();
7693 Expr *subExpr = result.take();
7694
7695 if (!getDerived().AlwaysRebuild() &&
7696 subExpr == E->getSubExpr())
7697 return SemaRef.Owned(E);
7698
7699 return SemaRef.Owned(new(SemaRef.Context)
7700 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7701}
7702
7703template<typename Derived>
7704ExprResult TreeTransform<Derived>::
7705TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7706 TypeSourceInfo *TSInfo
7707 = getDerived().TransformType(E->getTypeInfoAsWritten());
7708 if (!TSInfo)
7709 return ExprError();
7710
7711 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7712 if (Result.isInvalid())
7713 return ExprError();
7714
7715 if (!getDerived().AlwaysRebuild() &&
7716 TSInfo == E->getTypeInfoAsWritten() &&
7717 Result.get() == E->getSubExpr())
7718 return SemaRef.Owned(E);
7719
7720 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7721 E->getBridgeKeywordLoc(), TSInfo,
7722 Result.get());
7723}
7724
7725template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007726ExprResult
John McCall454feb92009-12-08 09:21:05 +00007727TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00007728 // Transform arguments.
7729 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007730 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007731 Args.reserve(E->getNumArgs());
7732 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7733 &ArgChanged))
7734 return ExprError();
7735
Douglas Gregor92e986e2010-04-22 16:44:27 +00007736 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7737 // Class message: transform the receiver type.
7738 TypeSourceInfo *ReceiverTypeInfo
7739 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7740 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00007741 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007742
Douglas Gregor92e986e2010-04-22 16:44:27 +00007743 // If nothing changed, just retain the existing message send.
7744 if (!getDerived().AlwaysRebuild() &&
7745 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007746 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00007747
7748 // Build a new class message send.
7749 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7750 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007751 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007752 E->getMethodDecl(),
7753 E->getLeftLoc(),
7754 move_arg(Args),
7755 E->getRightLoc());
7756 }
7757
7758 // Instance message: transform the receiver
7759 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7760 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00007761 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00007762 = getDerived().TransformExpr(E->getInstanceReceiver());
7763 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007764 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00007765
7766 // If nothing changed, just retain the existing message send.
7767 if (!getDerived().AlwaysRebuild() &&
7768 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007769 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007770
Douglas Gregor92e986e2010-04-22 16:44:27 +00007771 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00007772 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007773 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00007774 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00007775 E->getMethodDecl(),
7776 E->getLeftLoc(),
7777 move_arg(Args),
7778 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007779}
7780
Mike Stump1eb44332009-09-09 15:08:12 +00007781template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007782ExprResult
John McCall454feb92009-12-08 09:21:05 +00007783TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007784 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007785}
7786
Mike Stump1eb44332009-09-09 15:08:12 +00007787template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007788ExprResult
John McCall454feb92009-12-08 09:21:05 +00007789TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00007790 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007791}
7792
Mike Stump1eb44332009-09-09 15:08:12 +00007793template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007794ExprResult
John McCall454feb92009-12-08 09:21:05 +00007795TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007796 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007797 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007798 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007799 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007800
7801 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007802
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007803 // If nothing changed, just retain the existing expression.
7804 if (!getDerived().AlwaysRebuild() &&
7805 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007806 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007807
John McCall9ae2f072010-08-23 23:25:46 +00007808 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007809 E->getLocation(),
7810 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007811}
7812
Mike Stump1eb44332009-09-09 15:08:12 +00007813template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007814ExprResult
John McCall454feb92009-12-08 09:21:05 +00007815TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00007816 // 'super' and types never change. Property never changes. Just
7817 // retain the existing expression.
7818 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00007819 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00007820
Douglas Gregore3303542010-04-26 20:47:02 +00007821 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007822 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00007823 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007824 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007825
Douglas Gregore3303542010-04-26 20:47:02 +00007826 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00007827
Douglas Gregore3303542010-04-26 20:47:02 +00007828 // If nothing changed, just retain the existing expression.
7829 if (!getDerived().AlwaysRebuild() &&
7830 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007831 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007832
John McCall12f78a62010-12-02 01:19:52 +00007833 if (E->isExplicitProperty())
7834 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7835 E->getExplicitProperty(),
7836 E->getLocation());
7837
7838 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7839 E->getType(),
7840 E->getImplicitPropertyGetter(),
7841 E->getImplicitPropertySetter(),
7842 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007843}
7844
Mike Stump1eb44332009-09-09 15:08:12 +00007845template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007846ExprResult
John McCall454feb92009-12-08 09:21:05 +00007847TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007848 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00007849 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007850 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007851 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00007852
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007853 // If nothing changed, just retain the existing expression.
7854 if (!getDerived().AlwaysRebuild() &&
7855 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00007856 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00007857
John McCall9ae2f072010-08-23 23:25:46 +00007858 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00007859 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00007860}
7861
Mike Stump1eb44332009-09-09 15:08:12 +00007862template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007863ExprResult
John McCall454feb92009-12-08 09:21:05 +00007864TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007865 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00007866 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00007867 SubExprs.reserve(E->getNumSubExprs());
7868 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7869 SubExprs, &ArgumentChanged))
7870 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007871
Douglas Gregorb98b1992009-08-11 05:31:07 +00007872 if (!getDerived().AlwaysRebuild() &&
7873 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00007874 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00007875
Douglas Gregorb98b1992009-08-11 05:31:07 +00007876 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7877 move_arg(SubExprs),
7878 E->getRParenLoc());
7879}
7880
Mike Stump1eb44332009-09-09 15:08:12 +00007881template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007882ExprResult
John McCall454feb92009-12-08 09:21:05 +00007883TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCallc6ac9c32011-02-04 18:33:18 +00007884 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007885
John McCallc6ac9c32011-02-04 18:33:18 +00007886 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7887 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7888
7889 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanianff365592011-05-05 17:18:12 +00007890 // We built a new blockScopeInfo in call to ActOnBlockStart
7891 // in above, CapturesCXXThis need be set here from the block
7892 // expression.
7893 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7894
John McCallc6ac9c32011-02-04 18:33:18 +00007895 llvm::SmallVector<ParmVarDecl*, 4> params;
7896 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007897
7898 // Parameter substitution.
John McCallc6ac9c32011-02-04 18:33:18 +00007899 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7900 oldBlock->param_begin(),
7901 oldBlock->param_size(),
7902 0, paramTypes, &params))
Douglas Gregora779d9c2011-01-19 21:32:01 +00007903 return true;
John McCallc6ac9c32011-02-04 18:33:18 +00007904
7905 const FunctionType *exprFunctionType = E->getFunctionType();
7906 QualType exprResultType = exprFunctionType->getResultType();
7907 if (!exprResultType.isNull()) {
7908 if (!exprResultType->isDependentType())
7909 blockScope->ReturnType = exprResultType;
7910 else if (exprResultType != getSema().Context.DependentTy)
7911 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007912 }
Douglas Gregora779d9c2011-01-19 21:32:01 +00007913
7914 // If the return type has not been determined yet, leave it as a dependent
7915 // type; it'll get set when we process the body.
John McCallc6ac9c32011-02-04 18:33:18 +00007916 if (blockScope->ReturnType.isNull())
7917 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007918
7919 // Don't allow returning a objc interface by value.
John McCallc6ac9c32011-02-04 18:33:18 +00007920 if (blockScope->ReturnType->isObjCObjectType()) {
7921 getSema().Diag(E->getCaretLocation(),
Douglas Gregora779d9c2011-01-19 21:32:01 +00007922 diag::err_object_cannot_be_passed_returned_by_value)
John McCallc6ac9c32011-02-04 18:33:18 +00007923 << 0 << blockScope->ReturnType;
Douglas Gregora779d9c2011-01-19 21:32:01 +00007924 return ExprError();
7925 }
John McCall711c52b2011-01-05 12:14:39 +00007926
John McCallc6ac9c32011-02-04 18:33:18 +00007927 QualType functionType = getDerived().RebuildFunctionProtoType(
7928 blockScope->ReturnType,
7929 paramTypes.data(),
7930 paramTypes.size(),
7931 oldBlock->isVariadic(),
Douglas Gregorc938c162011-01-26 05:01:58 +00007932 0, RQ_None,
John McCallc6ac9c32011-02-04 18:33:18 +00007933 exprFunctionType->getExtInfo());
7934 blockScope->FunctionType = functionType;
John McCall711c52b2011-01-05 12:14:39 +00007935
7936 // Set the parameters on the block decl.
John McCallc6ac9c32011-02-04 18:33:18 +00007937 if (!params.empty())
7938 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregora779d9c2011-01-19 21:32:01 +00007939
7940 // If the return type wasn't explicitly set, it will have been marked as a
7941 // dependent type (DependentTy); clear out the return type setting so
7942 // we will deduce the return type when type-checking the block's body.
John McCallc6ac9c32011-02-04 18:33:18 +00007943 if (blockScope->ReturnType == getSema().Context.DependentTy)
7944 blockScope->ReturnType = QualType();
Douglas Gregora779d9c2011-01-19 21:32:01 +00007945
John McCall711c52b2011-01-05 12:14:39 +00007946 // Transform the body
John McCallc6ac9c32011-02-04 18:33:18 +00007947 StmtResult body = getDerived().TransformStmt(E->getBody());
7948 if (body.isInvalid())
John McCall711c52b2011-01-05 12:14:39 +00007949 return ExprError();
7950
John McCallc6ac9c32011-02-04 18:33:18 +00007951#ifndef NDEBUG
7952 // In builds with assertions, make sure that we captured everything we
7953 // captured before.
Douglas Gregorfc921372011-05-20 15:32:55 +00007954 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
7955 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7956 e = oldBlock->capture_end(); i != e; ++i) {
7957 VarDecl *oldCapture = i->getVariable();
John McCallc6ac9c32011-02-04 18:33:18 +00007958
Douglas Gregorfc921372011-05-20 15:32:55 +00007959 // Ignore parameter packs.
7960 if (isa<ParmVarDecl>(oldCapture) &&
7961 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7962 continue;
John McCallc6ac9c32011-02-04 18:33:18 +00007963
Douglas Gregorfc921372011-05-20 15:32:55 +00007964 VarDecl *newCapture =
7965 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7966 oldCapture));
7967 assert(blockScope->CaptureMap.count(newCapture));
7968 }
John McCallc6ac9c32011-02-04 18:33:18 +00007969 }
7970#endif
7971
7972 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7973 /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007974}
7975
Mike Stump1eb44332009-09-09 15:08:12 +00007976template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007977ExprResult
John McCall454feb92009-12-08 09:21:05 +00007978TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007979 ValueDecl *ND
7980 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7981 E->getDecl()));
7982 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00007983 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00007984
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007985 if (!getDerived().AlwaysRebuild() &&
7986 ND == E->getDecl()) {
7987 // Mark it referenced in the new context regardless.
7988 // FIXME: this is a bit instantiation-specific.
7989 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7990
John McCall3fa5cae2010-10-26 07:05:15 +00007991 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007992 }
7993
Abramo Bagnara25777432010-08-11 22:01:17 +00007994 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregor40d96a62011-02-28 21:54:11 +00007995 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnara25777432010-08-11 22:01:17 +00007996 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007997}
Mike Stump1eb44332009-09-09 15:08:12 +00007998
Tanya Lattner61eee0c2011-06-04 00:47:47 +00007999template<typename Derived>
8000ExprResult
8001TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
8002 assert(false && "Cannot transform asType expressions yet");
8003 return SemaRef.Owned(E);
8004}
8005
Douglas Gregorb98b1992009-08-11 05:31:07 +00008006//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00008007// Type reconstruction
8008//===----------------------------------------------------------------------===//
8009
Mike Stump1eb44332009-09-09 15:08:12 +00008010template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008011QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8012 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008013 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008014 getDerived().getBaseEntity());
8015}
8016
Mike Stump1eb44332009-09-09 15:08:12 +00008017template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00008018QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8019 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00008020 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008021 getDerived().getBaseEntity());
8022}
8023
Mike Stump1eb44332009-09-09 15:08:12 +00008024template<typename Derived>
8025QualType
John McCall85737a72009-10-30 00:06:24 +00008026TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8027 bool WrittenAsLValue,
8028 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008029 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00008030 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008031}
8032
8033template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008034QualType
John McCall85737a72009-10-30 00:06:24 +00008035TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8036 QualType ClassType,
8037 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00008038 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00008039 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008040}
8041
8042template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008043QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00008044TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8045 ArrayType::ArraySizeModifier SizeMod,
8046 const llvm::APInt *Size,
8047 Expr *SizeExpr,
8048 unsigned IndexTypeQuals,
8049 SourceRange BracketsRange) {
8050 if (SizeExpr || !Size)
8051 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8052 IndexTypeQuals, BracketsRange,
8053 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00008054
8055 QualType Types[] = {
8056 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8057 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8058 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00008059 };
8060 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8061 QualType SizeType;
8062 for (unsigned I = 0; I != NumTypes; ++I)
8063 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8064 SizeType = Types[I];
8065 break;
8066 }
Mike Stump1eb44332009-09-09 15:08:12 +00008067
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008068 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8069 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00008070 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008071 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00008072 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00008073}
Mike Stump1eb44332009-09-09 15:08:12 +00008074
Douglas Gregor577f75a2009-08-04 16:50:30 +00008075template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008076QualType
8077TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008078 ArrayType::ArraySizeModifier SizeMod,
8079 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00008080 unsigned IndexTypeQuals,
8081 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008082 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00008083 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008084}
8085
8086template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008087QualType
Mike Stump1eb44332009-09-09 15:08:12 +00008088TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008089 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00008090 unsigned IndexTypeQuals,
8091 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008092 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00008093 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008094}
Mike Stump1eb44332009-09-09 15:08:12 +00008095
Douglas Gregor577f75a2009-08-04 16:50:30 +00008096template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008097QualType
8098TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008099 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008100 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008101 unsigned IndexTypeQuals,
8102 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008103 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008104 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008105 IndexTypeQuals, BracketsRange);
8106}
8107
8108template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008109QualType
8110TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008111 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00008112 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008113 unsigned IndexTypeQuals,
8114 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00008115 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00008116 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008117 IndexTypeQuals, BracketsRange);
8118}
8119
8120template<typename Derived>
8121QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00008122 unsigned NumElements,
8123 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00008124 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00008125 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008126}
Mike Stump1eb44332009-09-09 15:08:12 +00008127
Douglas Gregor577f75a2009-08-04 16:50:30 +00008128template<typename Derived>
8129QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8130 unsigned NumElements,
8131 SourceLocation AttributeLoc) {
8132 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8133 NumElements, true);
8134 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00008135 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8136 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00008137 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008138}
Mike Stump1eb44332009-09-09 15:08:12 +00008139
Douglas Gregor577f75a2009-08-04 16:50:30 +00008140template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008141QualType
8142TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00008143 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008144 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00008145 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008146}
Mike Stump1eb44332009-09-09 15:08:12 +00008147
Douglas Gregor577f75a2009-08-04 16:50:30 +00008148template<typename Derived>
8149QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00008150 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008151 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00008152 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00008153 unsigned Quals,
Douglas Gregorc938c162011-01-26 05:01:58 +00008154 RefQualifierKind RefQualifier,
Eli Friedmanfa869542010-08-05 02:54:05 +00008155 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00008156 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregorc938c162011-01-26 05:01:58 +00008157 Quals, RefQualifier,
Douglas Gregor577f75a2009-08-04 16:50:30 +00008158 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00008159 getDerived().getBaseEntity(),
8160 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008161}
Mike Stump1eb44332009-09-09 15:08:12 +00008162
Douglas Gregor577f75a2009-08-04 16:50:30 +00008163template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00008164QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8165 return SemaRef.Context.getFunctionNoProtoType(T);
8166}
8167
8168template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00008169QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8170 assert(D && "no decl found");
8171 if (D->isInvalidDecl()) return QualType();
8172
Douglas Gregor92e986e2010-04-22 16:44:27 +00008173 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00008174 TypeDecl *Ty;
8175 if (isa<UsingDecl>(D)) {
8176 UsingDecl *Using = cast<UsingDecl>(D);
8177 assert(Using->isTypeName() &&
8178 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8179
8180 // A valid resolved using typename decl points to exactly one type decl.
8181 assert(++Using->shadow_begin() == Using->shadow_end());
8182 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00008183
John McCalled976492009-12-04 22:46:56 +00008184 } else {
8185 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8186 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8187 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8188 }
8189
8190 return SemaRef.Context.getTypeDeclType(Ty);
8191}
8192
8193template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008194QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8195 SourceLocation Loc) {
8196 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008197}
8198
8199template<typename Derived>
8200QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8201 return SemaRef.Context.getTypeOfType(Underlying);
8202}
8203
8204template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00008205QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8206 SourceLocation Loc) {
8207 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008208}
8209
8210template<typename Derived>
Sean Huntca63c202011-05-24 22:41:36 +00008211QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8212 UnaryTransformType::UTTKind UKind,
8213 SourceLocation Loc) {
8214 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8215}
8216
8217template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00008218QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00008219 TemplateName Template,
8220 SourceLocation TemplateNameLoc,
Douglas Gregor67714232011-03-03 02:41:12 +00008221 TemplateArgumentListInfo &TemplateArgs) {
John McCalld5532b62009-11-23 01:53:49 +00008222 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00008223}
Mike Stump1eb44332009-09-09 15:08:12 +00008224
Douglas Gregordcee1a12009-08-06 05:28:30 +00008225template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008226TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008227TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregord1067e52009-08-06 06:41:21 +00008228 bool TemplateKW,
8229 TemplateDecl *Template) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008230 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00008231 Template);
8232}
8233
8234template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00008235TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008236TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8237 const IdentifierInfo &Name,
8238 SourceLocation NameLoc,
John McCall43fed0d2010-11-12 08:19:04 +00008239 QualType ObjectType,
8240 NamedDecl *FirstQualifierInScope) {
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008241 UnqualifiedId TemplateName;
8242 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008243 Sema::TemplateTy Template;
8244 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008245 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008246 SS,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008247 TemplateName,
John McCallb3d87482010-08-24 05:47:05 +00008248 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008249 /*EnteringContext=*/false,
8250 Template);
John McCall43fed0d2010-11-12 08:19:04 +00008251 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00008252}
Mike Stump1eb44332009-09-09 15:08:12 +00008253
Douglas Gregorb98b1992009-08-11 05:31:07 +00008254template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008255TemplateName
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008256TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008257 OverloadedOperatorKind Operator,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008258 SourceLocation NameLoc,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008259 QualType ObjectType) {
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008260 UnqualifiedId Name;
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008261 // FIXME: Bogus location information.
8262 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8263 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00008264 Sema::TemplateTy Template;
8265 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorfd4ffeb2011-03-02 18:07:45 +00008266 /*FIXME:*/SourceLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008267 SS,
8268 Name,
John McCallb3d87482010-08-24 05:47:05 +00008269 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00008270 /*EnteringContext=*/false,
8271 Template);
8272 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008273}
Sean Huntc3021132010-05-05 15:23:54 +00008274
Douglas Gregorca1bdd72009-11-04 00:56:37 +00008275template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008276ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00008277TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8278 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008279 Expr *OrigCallee,
8280 Expr *First,
8281 Expr *Second) {
8282 Expr *Callee = OrigCallee->IgnoreParenCasts();
8283 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00008284
Douglas Gregorb98b1992009-08-11 05:31:07 +00008285 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00008286 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00008287 if (!First->getType()->isOverloadableType() &&
8288 !Second->getType()->isOverloadableType())
8289 return getSema().CreateBuiltinArraySubscriptExpr(First,
8290 Callee->getLocStart(),
8291 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00008292 } else if (Op == OO_Arrow) {
8293 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00008294 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8295 } else if (Second == 0 || isPostIncDec) {
8296 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008297 // The argument is not of overloadable type, so try to create a
8298 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00008299 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008300 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00008301
John McCall9ae2f072010-08-23 23:25:46 +00008302 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008303 }
8304 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008305 if (!First->getType()->isOverloadableType() &&
8306 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00008307 // Neither of the arguments is an overloadable type, so try to
8308 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00008309 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008310 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00008311 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008312 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008313 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008314
Douglas Gregorb98b1992009-08-11 05:31:07 +00008315 return move(Result);
8316 }
8317 }
Mike Stump1eb44332009-09-09 15:08:12 +00008318
8319 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00008320 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00008321 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00008322
John McCall9ae2f072010-08-23 23:25:46 +00008323 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00008324 assert(ULE->requiresADL());
8325
8326 // FIXME: Do we have to check
8327 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00008328 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00008329 } else {
John McCall9ae2f072010-08-23 23:25:46 +00008330 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00008331 }
Mike Stump1eb44332009-09-09 15:08:12 +00008332
Douglas Gregorb98b1992009-08-11 05:31:07 +00008333 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00008334 Expr *Args[2] = { First, Second };
8335 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00008336
Douglas Gregorb98b1992009-08-11 05:31:07 +00008337 // Create the overloaded operator invocation for unary operators.
8338 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00008339 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00008340 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00008341 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008342 }
Mike Stump1eb44332009-09-09 15:08:12 +00008343
Sebastian Redlf322ed62009-10-29 20:17:01 +00008344 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00008345 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00008346 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00008347 First,
8348 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00008349
Douglas Gregorb98b1992009-08-11 05:31:07 +00008350 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00008351 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00008352 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00008353 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8354 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00008355 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00008356
Mike Stump1eb44332009-09-09 15:08:12 +00008357 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00008358}
Mike Stump1eb44332009-09-09 15:08:12 +00008359
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008360template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00008361ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00008362TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008363 SourceLocation OperatorLoc,
8364 bool isArrow,
Douglas Gregorf3db29f2011-02-25 18:19:59 +00008365 CXXScopeSpec &SS,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008366 TypeSourceInfo *ScopeType,
8367 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008368 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008369 PseudoDestructorTypeStorage Destroyed) {
John McCall9ae2f072010-08-23 23:25:46 +00008370 QualType BaseType = Base->getType();
8371 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008372 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00008373 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00008374 !BaseType->getAs<PointerType>()->getPointeeType()
8375 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008376 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00008377 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008378 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00008379 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008380 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008381 /*FIXME?*/true);
8382 }
Abramo Bagnara25777432010-08-11 22:01:17 +00008383
Douglas Gregora2e7dd22010-02-25 01:56:36 +00008384 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00008385 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8386 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8387 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8388 NameInfo.setNamedTypeInfo(DestroyedType);
8389
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008390 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00008391
John McCall9ae2f072010-08-23 23:25:46 +00008392 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008393 OperatorLoc, isArrow,
8394 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00008395 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00008396 /*TemplateArgs*/ 0);
8397}
8398
Douglas Gregor577f75a2009-08-04 16:50:30 +00008399} // end namespace clang
8400
8401#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H