blob: e63cc7da7c75c8a67b2e120f30beb6c0e6c958f4 [file] [log] [blame]
John McCalla2becad2009-10-21 00:40:46 +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.
7//===----------------------------------------------------------------------===/
8//
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//
12//===----------------------------------------------------------------------===/
13#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
14#define LLVM_CLANG_SEMA_TREETRANSFORM_H
15
John McCall2d887082010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregore737f502010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregor8491ffe2010-12-20 22:05:00 +000018#include "clang/Sema/ParsedTemplate.h"
Douglas Gregordcee1a12009-08-06 05:28:30 +000019#include "clang/Sema/SemaDiagnostic.h"
John McCall781472f2010-08-25 08:40:02 +000020#include "clang/Sema/ScopeInfo.h"
Douglas Gregorc68afe22009-09-03 21:38:09 +000021#include "clang/AST/Decl.h"
John McCall7cd088e2010-08-24 07:21:54 +000022#include "clang/AST/DeclObjC.h"
Douglas Gregor657c1ac2009-08-06 22:17:10 +000023#include "clang/AST/Expr.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000024#include "clang/AST/ExprCXX.h"
25#include "clang/AST/ExprObjC.h"
Douglas Gregor43959a92009-08-20 07:17:43 +000026#include "clang/AST/Stmt.h"
27#include "clang/AST/StmtCXX.h"
28#include "clang/AST/StmtObjC.h"
John McCall19510852010-08-20 18:27:03 +000029#include "clang/Sema/Ownership.h"
30#include "clang/Sema/Designator.h"
Douglas Gregorb98b1992009-08-11 05:31:07 +000031#include "clang/Lex/Preprocessor.h"
John McCalla2becad2009-10-21 00:40:46 +000032#include "llvm/Support/ErrorHandling.h"
Douglas Gregor7e44e3f2010-12-02 00:05:49 +000033#include "TypeLocBuilder.h"
Douglas Gregor577f75a2009-08-04 16:50:30 +000034#include <algorithm>
35
36namespace clang {
John McCall781472f2010-08-25 08:40:02 +000037using namespace sema;
Mike Stump1eb44332009-09-09 15:08:12 +000038
Douglas Gregor577f75a2009-08-04 16:50:30 +000039/// \brief A semantic tree transformation that allows one to transform one
40/// abstract syntax tree into another.
41///
Mike Stump1eb44332009-09-09 15:08:12 +000042/// A new tree transformation is defined by creating a new subclass \c X of
43/// \c TreeTransform<X> and then overriding certain operations to provide
44/// behavior specific to that transformation. For example, template
Douglas Gregor577f75a2009-08-04 16:50:30 +000045/// instantiation is implemented as a tree transformation where the
46/// transformation of TemplateTypeParmType nodes involves substituting the
47/// template arguments for their corresponding template parameters; a similar
48/// transformation is performed for non-type template parameters and
49/// template template parameters.
50///
51/// This tree-transformation template uses static polymorphism to allow
Mike Stump1eb44332009-09-09 15:08:12 +000052/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregor577f75a2009-08-04 16:50:30 +000053/// override any of the transformation or rebuild operators by providing an
54/// operation with the same signature as the default implementation. The
55/// overridding function should not be virtual.
56///
57/// Semantic tree transformations are split into two stages, either of which
58/// can be replaced by a subclass. The "transform" step transforms an AST node
59/// or the parts of an AST node using the various transformation functions,
60/// then passes the pieces on to the "rebuild" step, which constructs a new AST
61/// node of the appropriate kind from the pieces. The default transformation
62/// routines recursively transform the operands to composite AST nodes (e.g.,
63/// the pointee type of a PointerType node) and, if any of those operand nodes
64/// were changed by the transformation, invokes the rebuild operation to create
65/// a new AST node.
66///
Mike Stump1eb44332009-09-09 15:08:12 +000067/// Subclasses can customize the transformation at various levels. The
Douglas Gregor670444e2009-08-04 22:27:00 +000068/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregor577f75a2009-08-04 16:50:30 +000069/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
70/// TransformTemplateName(), or TransformTemplateArgument() with entirely
71/// new implementations.
72///
73/// For more fine-grained transformations, subclasses can replace any of the
74/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregor43959a92009-08-20 07:17:43 +000075/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregor577f75a2009-08-04 16:50:30 +000076/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump1eb44332009-09-09 15:08:12 +000077/// to substitute template arguments for their corresponding template
Douglas Gregor577f75a2009-08-04 16:50:30 +000078/// parameters. Additionally, subclasses can override the \c RebuildXXX
79/// functions to control how AST nodes are rebuilt when their operands change.
80/// By default, \c TreeTransform will invoke semantic analysis to rebuild
81/// AST nodes. However, certain other tree transformations (e.g, cloning) may
82/// be able to use more efficient rebuild steps.
83///
84/// There are a handful of other functions that can be overridden, allowing one
Mike Stump1eb44332009-09-09 15:08:12 +000085/// to avoid traversing nodes that don't need any transformation
Douglas Gregor577f75a2009-08-04 16:50:30 +000086/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
87/// operands have not changed (\c AlwaysRebuild()), and customize the
88/// default locations and entity names used for type-checking
89/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregor577f75a2009-08-04 16:50:30 +000090template<typename Derived>
91class TreeTransform {
Douglas Gregord3731192011-01-10 07:32:04 +000092 /// \brief Private RAII object that helps us forget and then re-remember
93 /// the template argument corresponding to a partially-substituted parameter
94 /// pack.
95 class ForgetPartiallySubstitutedPackRAII {
96 Derived &Self;
97 TemplateArgument Old;
98
99 public:
100 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
101 Old = Self.ForgetPartiallySubstitutedPack();
102 }
103
104 ~ForgetPartiallySubstitutedPackRAII() {
105 Self.RememberPartiallySubstitutedPack(Old);
106 }
107 };
108
Douglas Gregor577f75a2009-08-04 16:50:30 +0000109protected:
110 Sema &SemaRef;
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000111
Mike Stump1eb44332009-09-09 15:08:12 +0000112public:
Douglas Gregor577f75a2009-08-04 16:50:30 +0000113 /// \brief Initializes a new tree transformer.
Douglas Gregorb99268b2010-12-21 00:52:54 +0000114 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000115
Douglas Gregor577f75a2009-08-04 16:50:30 +0000116 /// \brief Retrieves a reference to the derived class.
117 Derived &getDerived() { return static_cast<Derived&>(*this); }
118
119 /// \brief Retrieves a reference to the derived class.
Mike Stump1eb44332009-09-09 15:08:12 +0000120 const Derived &getDerived() const {
121 return static_cast<const Derived&>(*this);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000122 }
123
John McCall60d7b3a2010-08-24 06:29:42 +0000124 static inline ExprResult Owned(Expr *E) { return E; }
125 static inline StmtResult Owned(Stmt *S) { return S; }
John McCall9ae2f072010-08-23 23:25:46 +0000126
Douglas Gregor577f75a2009-08-04 16:50:30 +0000127 /// \brief Retrieves a reference to the semantic analysis object used for
128 /// this tree transform.
129 Sema &getSema() const { return SemaRef; }
Mike Stump1eb44332009-09-09 15:08:12 +0000130
Douglas Gregor577f75a2009-08-04 16:50:30 +0000131 /// \brief Whether the transformation should always rebuild AST nodes, even
132 /// if none of the children have changed.
133 ///
134 /// Subclasses may override this function to specify when the transformation
135 /// should rebuild all AST nodes.
136 bool AlwaysRebuild() { return false; }
Mike Stump1eb44332009-09-09 15:08:12 +0000137
Douglas Gregor577f75a2009-08-04 16:50:30 +0000138 /// \brief Returns the location of the entity being transformed, if that
139 /// information was not available elsewhere in the AST.
140 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000141 /// By default, returns no source-location information. Subclasses can
Douglas Gregor577f75a2009-08-04 16:50:30 +0000142 /// provide an alternative implementation that provides better location
143 /// information.
144 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump1eb44332009-09-09 15:08:12 +0000145
Douglas Gregor577f75a2009-08-04 16:50:30 +0000146 /// \brief Returns the name of the entity being transformed, if that
147 /// information was not available elsewhere in the AST.
148 ///
149 /// By default, returns an empty name. Subclasses can provide an alternative
150 /// implementation with a more precise name.
151 DeclarationName getBaseEntity() { return DeclarationName(); }
152
Douglas Gregorb98b1992009-08-11 05:31:07 +0000153 /// \brief Sets the "base" location and entity when that
154 /// information is known based on another transformation.
155 ///
156 /// By default, the source location and entity are ignored. Subclasses can
157 /// override this function to provide a customized implementation.
158 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump1eb44332009-09-09 15:08:12 +0000159
Douglas Gregorb98b1992009-08-11 05:31:07 +0000160 /// \brief RAII object that temporarily sets the base location and entity
161 /// used for reporting diagnostics in types.
162 class TemporaryBase {
163 TreeTransform &Self;
164 SourceLocation OldLocation;
165 DeclarationName OldEntity;
Mike Stump1eb44332009-09-09 15:08:12 +0000166
Douglas Gregorb98b1992009-08-11 05:31:07 +0000167 public:
168 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump1eb44332009-09-09 15:08:12 +0000169 DeclarationName Entity) : Self(Self) {
Douglas Gregorb98b1992009-08-11 05:31:07 +0000170 OldLocation = Self.getDerived().getBaseLocation();
171 OldEntity = Self.getDerived().getBaseEntity();
172 Self.getDerived().setBase(Location, Entity);
173 }
Mike Stump1eb44332009-09-09 15:08:12 +0000174
Douglas Gregorb98b1992009-08-11 05:31:07 +0000175 ~TemporaryBase() {
176 Self.getDerived().setBase(OldLocation, OldEntity);
177 }
178 };
Mike Stump1eb44332009-09-09 15:08:12 +0000179
180 /// \brief Determine whether the given type \p T has already been
Douglas Gregor577f75a2009-08-04 16:50:30 +0000181 /// transformed.
182 ///
183 /// Subclasses can provide an alternative implementation of this routine
Mike Stump1eb44332009-09-09 15:08:12 +0000184 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregor577f75a2009-08-04 16:50:30 +0000185 /// not change. For example, template instantiation need not traverse
186 /// non-dependent types.
187 bool AlreadyTransformed(QualType T) {
188 return T.isNull();
189 }
190
Douglas Gregor6eef5192009-12-14 19:27:10 +0000191 /// \brief Determine whether the given call argument should be dropped, e.g.,
192 /// because it is a default argument.
193 ///
194 /// Subclasses can provide an alternative implementation of this routine to
195 /// determine which kinds of call arguments get dropped. By default,
196 /// CXXDefaultArgument nodes are dropped (prior to transformation).
197 bool DropCallArgument(Expr *E) {
198 return E->isDefaultArgument();
199 }
Sean Huntc3021132010-05-05 15:23:54 +0000200
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000201 /// \brief Determine whether we should expand a pack expansion with the
202 /// given set of parameter packs into separate arguments by repeatedly
203 /// transforming the pattern.
204 ///
Douglas Gregorb99268b2010-12-21 00:52:54 +0000205 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000206 /// Subclasses can override this routine to provide different behavior.
207 ///
208 /// \param EllipsisLoc The location of the ellipsis that identifies the
209 /// pack expansion.
210 ///
211 /// \param PatternRange The source range that covers the entire pattern of
212 /// the pack expansion.
213 ///
214 /// \param Unexpanded The set of unexpanded parameter packs within the
215 /// pattern.
216 ///
217 /// \param NumUnexpanded The number of unexpanded parameter packs in
218 /// \p Unexpanded.
219 ///
220 /// \param ShouldExpand Will be set to \c true if the transformer should
221 /// expand the corresponding pack expansions into separate arguments. When
222 /// set, \c NumExpansions must also be set.
223 ///
Douglas Gregord3731192011-01-10 07:32:04 +0000224 /// \param RetainExpansion Whether the caller should add an unexpanded
225 /// pack expansion after all of the expanded arguments. This is used
226 /// when extending explicitly-specified template argument packs per
227 /// C++0x [temp.arg.explicit]p9.
228 ///
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000229 /// \param NumExpansions The number of separate arguments that will be in
230 /// the expanded form of the corresponding pack expansion. Must be set when
231 /// \c ShouldExpand is \c true.
232 ///
233 /// \returns true if an error occurred (e.g., because the parameter packs
234 /// are to be instantiated with arguments of different lengths), false
235 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
236 /// must be set.
237 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
238 SourceRange PatternRange,
239 const UnexpandedParameterPack *Unexpanded,
240 unsigned NumUnexpanded,
241 bool &ShouldExpand,
Douglas Gregord3731192011-01-10 07:32:04 +0000242 bool &RetainExpansion,
Douglas Gregor8491ffe2010-12-20 22:05:00 +0000243 unsigned &NumExpansions) {
244 ShouldExpand = false;
245 return false;
246 }
247
Douglas Gregord3731192011-01-10 07:32:04 +0000248 /// \brief "Forget" about the partially-substituted pack template argument,
249 /// when performing an instantiation that must preserve the parameter pack
250 /// use.
251 ///
252 /// This routine is meant to be overridden by the template instantiator.
253 TemplateArgument ForgetPartiallySubstitutedPack() {
254 return TemplateArgument();
255 }
256
257 /// \brief "Remember" the partially-substituted pack template argument
258 /// after performing an instantiation that must preserve the parameter pack
259 /// use.
260 ///
261 /// This routine is meant to be overridden by the template instantiator.
262 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
263
Douglas Gregor12c9c002011-01-07 16:43:16 +0000264 /// \brief Note to the derived class when a function parameter pack is
265 /// being expanded.
266 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
267
Douglas Gregor577f75a2009-08-04 16:50:30 +0000268 /// \brief Transforms the given type into another type.
269 ///
John McCalla2becad2009-10-21 00:40:46 +0000270 /// By default, this routine transforms a type by creating a
John McCalla93c9342009-12-07 02:54:59 +0000271 /// TypeSourceInfo for it and delegating to the appropriate
John McCalla2becad2009-10-21 00:40:46 +0000272 /// function. This is expensive, but we don't mind, because
273 /// this method is deprecated anyway; all users should be
John McCalla93c9342009-12-07 02:54:59 +0000274 /// switched to storing TypeSourceInfos.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000275 ///
276 /// \returns the transformed type.
John McCall43fed0d2010-11-12 08:19:04 +0000277 QualType TransformType(QualType T);
Mike Stump1eb44332009-09-09 15:08:12 +0000278
John McCalla2becad2009-10-21 00:40:46 +0000279 /// \brief Transforms the given type-with-location into a new
280 /// type-with-location.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000281 ///
John McCalla2becad2009-10-21 00:40:46 +0000282 /// By default, this routine transforms a type by delegating to the
283 /// appropriate TransformXXXType to build a new type. Subclasses
284 /// may override this function (to take over all type
285 /// transformations) or some set of the TransformXXXType functions
286 /// to alter the transformation.
John McCall43fed0d2010-11-12 08:19:04 +0000287 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCalla2becad2009-10-21 00:40:46 +0000288
289 /// \brief Transform the given type-with-location into a new
290 /// type, collecting location information in the given builder
291 /// as necessary.
292 ///
John McCall43fed0d2010-11-12 08:19:04 +0000293 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump1eb44332009-09-09 15:08:12 +0000294
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000295 /// \brief Transform the given statement.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000296 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000297 /// By default, this routine transforms a statement by delegating to the
Douglas Gregor43959a92009-08-20 07:17:43 +0000298 /// appropriate TransformXXXStmt function to transform a specific kind of
299 /// statement or the TransformExpr() function to transform an expression.
300 /// Subclasses may override this function to transform statements using some
301 /// other mechanism.
302 ///
303 /// \returns the transformed statement.
John McCall60d7b3a2010-08-24 06:29:42 +0000304 StmtResult TransformStmt(Stmt *S);
Mike Stump1eb44332009-09-09 15:08:12 +0000305
Douglas Gregor657c1ac2009-08-06 22:17:10 +0000306 /// \brief Transform the given expression.
307 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +0000308 /// By default, this routine transforms an expression by delegating to the
309 /// appropriate TransformXXXExpr function to build a new expression.
310 /// Subclasses may override this function to transform expressions using some
311 /// other mechanism.
312 ///
313 /// \returns the transformed expression.
John McCall60d7b3a2010-08-24 06:29:42 +0000314 ExprResult TransformExpr(Expr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000315
Douglas Gregoraa165f82011-01-03 19:04:46 +0000316 /// \brief Transform the given list of expressions.
317 ///
318 /// This routine transforms a list of expressions by invoking
319 /// \c TransformExpr() for each subexpression. However, it also provides
320 /// support for variadic templates by expanding any pack expansions (if the
321 /// derived class permits such expansion) along the way. When pack expansions
322 /// are present, the number of outputs may not equal the number of inputs.
323 ///
324 /// \param Inputs The set of expressions to be transformed.
325 ///
326 /// \param NumInputs The number of expressions in \c Inputs.
327 ///
328 /// \param IsCall If \c true, then this transform is being performed on
329 /// function-call arguments, and any arguments that should be dropped, will
330 /// be.
331 ///
332 /// \param Outputs The transformed input expressions will be added to this
333 /// vector.
334 ///
335 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
336 /// due to transformation.
337 ///
338 /// \returns true if an error occurred, false otherwise.
339 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
340 llvm::SmallVectorImpl<Expr *> &Outputs,
341 bool *ArgChanged = 0);
342
Douglas Gregor577f75a2009-08-04 16:50:30 +0000343 /// \brief Transform the given declaration, which is referenced from a type
344 /// or expression.
345 ///
Douglas Gregordcee1a12009-08-06 05:28:30 +0000346 /// By default, acts as the identity function on declarations. Subclasses
347 /// may override this function to provide alternate behavior.
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000348 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregor43959a92009-08-20 07:17:43 +0000349
350 /// \brief Transform the definition of the given declaration.
351 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000352 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregor43959a92009-08-20 07:17:43 +0000353 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000354 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
355 return getDerived().TransformDecl(Loc, D);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +0000356 }
Mike Stump1eb44332009-09-09 15:08:12 +0000357
Douglas Gregor6cd21982009-10-20 05:58:46 +0000358 /// \brief Transform the given declaration, which was the first part of a
359 /// nested-name-specifier in a member access expression.
360 ///
Sean Huntc3021132010-05-05 15:23:54 +0000361 /// This specific declaration transformation only applies to the first
Douglas Gregor6cd21982009-10-20 05:58:46 +0000362 /// identifier in a nested-name-specifier of a member access expression, e.g.,
363 /// the \c T in \c x->T::member
364 ///
365 /// By default, invokes TransformDecl() to transform the declaration.
366 /// Subclasses may override this function to provide alternate behavior.
Sean Huntc3021132010-05-05 15:23:54 +0000367 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
368 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregor6cd21982009-10-20 05:58:46 +0000369 }
Sean Huntc3021132010-05-05 15:23:54 +0000370
Douglas Gregor577f75a2009-08-04 16:50:30 +0000371 /// \brief Transform the given nested-name-specifier.
372 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000373 /// By default, transforms all of the types and declarations within the
Douglas Gregordcee1a12009-08-06 05:28:30 +0000374 /// nested-name-specifier. Subclasses may override this function to provide
375 /// alternate behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000376 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +0000377 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000378 QualType ObjectType = QualType(),
379 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000380
Douglas Gregor81499bb2009-09-03 22:13:48 +0000381 /// \brief Transform the given declaration name.
382 ///
383 /// By default, transforms the types of conversion function, constructor,
384 /// and destructor names and then (if needed) rebuilds the declaration name.
385 /// Identifiers and selectors are returned unmodified. Sublcasses may
386 /// override this function to provide alternate behavior.
Abramo Bagnara25777432010-08-11 22:01:17 +0000387 DeclarationNameInfo
John McCall43fed0d2010-11-12 08:19:04 +0000388 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump1eb44332009-09-09 15:08:12 +0000389
Douglas Gregor577f75a2009-08-04 16:50:30 +0000390 /// \brief Transform the given template name.
Mike Stump1eb44332009-09-09 15:08:12 +0000391 ///
Douglas Gregord1067e52009-08-06 06:41:21 +0000392 /// By default, transforms the template name by transforming the declarations
Mike Stump1eb44332009-09-09 15:08:12 +0000393 /// and nested-name-specifiers that occur within the template name.
Douglas Gregord1067e52009-08-06 06:41:21 +0000394 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000395 TemplateName TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +0000396 QualType ObjectType = QualType(),
397 NamedDecl *FirstQualifierInScope = 0);
Mike Stump1eb44332009-09-09 15:08:12 +0000398
Douglas Gregor577f75a2009-08-04 16:50:30 +0000399 /// \brief Transform the given template argument.
400 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000401 /// By default, this operation transforms the type, expression, or
402 /// declaration stored within the template argument and constructs a
Douglas Gregor670444e2009-08-04 22:27:00 +0000403 /// new template argument from the transformed result. Subclasses may
404 /// override this function to provide alternate behavior.
John McCall833ca992009-10-29 08:12:44 +0000405 ///
406 /// Returns true if there was an error.
407 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
408 TemplateArgumentLoc &Output);
409
Douglas Gregorfcc12532010-12-20 17:31:10 +0000410 /// \brief Transform the given set of template arguments.
411 ///
412 /// By default, this operation transforms all of the template arguments
413 /// in the input set using \c TransformTemplateArgument(), and appends
414 /// the transformed arguments to the output list.
415 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000416 /// Note that this overload of \c TransformTemplateArguments() is merely
417 /// a convenience function. Subclasses that wish to override this behavior
418 /// should override the iterator-based member template version.
419 ///
Douglas Gregorfcc12532010-12-20 17:31:10 +0000420 /// \param Inputs The set of template arguments to be transformed.
421 ///
422 /// \param NumInputs The number of template arguments in \p Inputs.
423 ///
424 /// \param Outputs The set of transformed template arguments output by this
425 /// routine.
426 ///
427 /// Returns true if an error occurred.
428 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
429 unsigned NumInputs,
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000430 TemplateArgumentListInfo &Outputs) {
431 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
432 }
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000433
434 /// \brief Transform the given set of template arguments.
435 ///
436 /// By default, this operation transforms all of the template arguments
437 /// in the input set using \c TransformTemplateArgument(), and appends
438 /// the transformed arguments to the output list.
439 ///
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000440 /// \param First An iterator to the first template argument.
441 ///
442 /// \param Last An iterator one step past the last template argument.
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000443 ///
444 /// \param Outputs The set of transformed template arguments output by this
445 /// routine.
446 ///
447 /// Returns true if an error occurred.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +0000448 template<typename InputIterator>
449 bool TransformTemplateArguments(InputIterator First,
450 InputIterator Last,
451 TemplateArgumentListInfo &Outputs);
Douglas Gregor7f61f2f2010-12-20 17:42:22 +0000452
John McCall833ca992009-10-29 08:12:44 +0000453 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
454 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
455 TemplateArgumentLoc &ArgLoc);
456
John McCalla93c9342009-12-07 02:54:59 +0000457 /// \brief Fakes up a TypeSourceInfo for a type.
458 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
459 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall833ca992009-10-29 08:12:44 +0000460 getDerived().getBaseLocation());
461 }
Mike Stump1eb44332009-09-09 15:08:12 +0000462
John McCalla2becad2009-10-21 00:40:46 +0000463#define ABSTRACT_TYPELOC(CLASS, PARENT)
464#define TYPELOC(CLASS, PARENT) \
John McCall43fed0d2010-11-12 08:19:04 +0000465 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCalla2becad2009-10-21 00:40:46 +0000466#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +0000467
John McCall43fed0d2010-11-12 08:19:04 +0000468 QualType
469 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
470 TemplateSpecializationTypeLoc TL,
471 TemplateName Template);
472
473 QualType
474 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
475 DependentTemplateSpecializationTypeLoc TL,
476 NestedNameSpecifier *Prefix);
477
John McCall21ef0fa2010-03-11 09:03:00 +0000478 /// \brief Transforms the parameters of a function type into the
479 /// given vectors.
480 ///
481 /// The result vectors should be kept in sync; null entries in the
482 /// variables vector are acceptable.
483 ///
484 /// Return true on error.
Douglas Gregora009b592011-01-07 00:20:55 +0000485 bool TransformFunctionTypeParams(SourceLocation Loc,
486 ParmVarDecl **Params, unsigned NumParams,
487 const QualType *ParamTypes,
John McCall21ef0fa2010-03-11 09:03:00 +0000488 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregora009b592011-01-07 00:20:55 +0000489 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall21ef0fa2010-03-11 09:03:00 +0000490
491 /// \brief Transforms a single function-type parameter. Return null
492 /// on error.
493 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm);
494
John McCall43fed0d2010-11-12 08:19:04 +0000495 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall833ca992009-10-29 08:12:44 +0000496
John McCall60d7b3a2010-08-24 06:29:42 +0000497 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
498 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump1eb44332009-09-09 15:08:12 +0000499
Douglas Gregor43959a92009-08-20 07:17:43 +0000500#define STMT(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000501 StmtResult Transform##Node(Node *S);
Douglas Gregorb98b1992009-08-11 05:31:07 +0000502#define EXPR(Node, Parent) \
John McCall60d7b3a2010-08-24 06:29:42 +0000503 ExprResult Transform##Node(Node *E);
Sean Hunt7381d5c2010-05-18 06:22:21 +0000504#define ABSTRACT_STMT(Stmt)
Sean Hunt4bfe1962010-05-05 15:24:00 +0000505#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +0000506
Douglas Gregor577f75a2009-08-04 16:50:30 +0000507 /// \brief Build a new pointer type given its pointee type.
508 ///
509 /// By default, performs semantic analysis when building the pointer type.
510 /// Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000511 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000512
513 /// \brief Build a new block pointer type given its pointee type.
514 ///
Mike Stump1eb44332009-09-09 15:08:12 +0000515 /// By default, performs semantic analysis when building the block pointer
Douglas Gregor577f75a2009-08-04 16:50:30 +0000516 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000517 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000518
John McCall85737a72009-10-30 00:06:24 +0000519 /// \brief Build a new reference type given the type it references.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000520 ///
John McCall85737a72009-10-30 00:06:24 +0000521 /// By default, performs semantic analysis when building the
522 /// reference type. Subclasses may override this routine to provide
523 /// different behavior.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000524 ///
John McCall85737a72009-10-30 00:06:24 +0000525 /// \param LValue whether the type was written with an lvalue sigil
526 /// or an rvalue sigil.
527 QualType RebuildReferenceType(QualType ReferentType,
528 bool LValue,
529 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000530
Douglas Gregor577f75a2009-08-04 16:50:30 +0000531 /// \brief Build a new member pointer type given the pointee type and the
532 /// class type it refers into.
533 ///
534 /// By default, performs semantic analysis when building the member pointer
535 /// type. Subclasses may override this routine to provide different behavior.
John McCall85737a72009-10-30 00:06:24 +0000536 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
537 SourceLocation Sigil);
Mike Stump1eb44332009-09-09 15:08:12 +0000538
Douglas Gregor577f75a2009-08-04 16:50:30 +0000539 /// \brief Build a new array type given the element type, size
540 /// modifier, size of the array (if known), size expression, and index type
541 /// qualifiers.
542 ///
543 /// By default, performs semantic analysis when building the array type.
544 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000545 /// Also by default, all of the other Rebuild*Array
Douglas Gregor577f75a2009-08-04 16:50:30 +0000546 QualType RebuildArrayType(QualType ElementType,
547 ArrayType::ArraySizeModifier SizeMod,
548 const llvm::APInt *Size,
549 Expr *SizeExpr,
550 unsigned IndexTypeQuals,
551 SourceRange BracketsRange);
Mike Stump1eb44332009-09-09 15:08:12 +0000552
Douglas Gregor577f75a2009-08-04 16:50:30 +0000553 /// \brief Build a new constant array type given the element type, size
554 /// modifier, (known) size of the array, and index type qualifiers.
555 ///
556 /// By default, performs semantic analysis when building the array type.
557 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000558 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000559 ArrayType::ArraySizeModifier SizeMod,
560 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +0000561 unsigned IndexTypeQuals,
562 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000563
Douglas Gregor577f75a2009-08-04 16:50:30 +0000564 /// \brief Build a new incomplete array type given the element type, size
565 /// modifier, and index type qualifiers.
566 ///
567 /// By default, performs semantic analysis when building the array type.
568 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000569 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000570 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +0000571 unsigned IndexTypeQuals,
572 SourceRange BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000573
Mike Stump1eb44332009-09-09 15:08:12 +0000574 /// \brief Build a new variable-length array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000575 /// size modifier, size expression, and index type qualifiers.
576 ///
577 /// By default, performs semantic analysis when building the array type.
578 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000579 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000580 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000581 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000582 unsigned IndexTypeQuals,
583 SourceRange BracketsRange);
584
Mike Stump1eb44332009-09-09 15:08:12 +0000585 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000586 /// size modifier, size expression, and index type qualifiers.
587 ///
588 /// By default, performs semantic analysis when building the array type.
589 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000590 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000591 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +0000592 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000593 unsigned IndexTypeQuals,
594 SourceRange BracketsRange);
595
596 /// \brief Build a new vector type given the element type and
597 /// number of elements.
598 ///
599 /// By default, performs semantic analysis when building the vector type.
600 /// Subclasses may override this routine to provide different behavior.
John Thompson82287d12010-02-05 00:12:22 +0000601 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsone86d78c2010-11-10 21:56:12 +0000602 VectorType::VectorKind VecKind);
Mike Stump1eb44332009-09-09 15:08:12 +0000603
Douglas Gregor577f75a2009-08-04 16:50:30 +0000604 /// \brief Build a new extended vector type given the element type and
605 /// number of elements.
606 ///
607 /// By default, performs semantic analysis when building the vector type.
608 /// Subclasses may override this routine to provide different behavior.
609 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
610 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000611
612 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregor577f75a2009-08-04 16:50:30 +0000613 /// given the element type and number of elements.
614 ///
615 /// By default, performs semantic analysis when building the vector type.
616 /// Subclasses may override this routine to provide different behavior.
Mike Stump1eb44332009-09-09 15:08:12 +0000617 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +0000618 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000619 SourceLocation AttributeLoc);
Mike Stump1eb44332009-09-09 15:08:12 +0000620
Douglas Gregor577f75a2009-08-04 16:50:30 +0000621 /// \brief Build a new function type.
622 ///
623 /// By default, performs semantic analysis when building the function type.
624 /// Subclasses may override this routine to provide different behavior.
625 QualType RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +0000626 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +0000627 unsigned NumParamTypes,
Eli Friedmanfa869542010-08-05 02:54:05 +0000628 bool Variadic, unsigned Quals,
629 const FunctionType::ExtInfo &Info);
Mike Stump1eb44332009-09-09 15:08:12 +0000630
John McCalla2becad2009-10-21 00:40:46 +0000631 /// \brief Build a new unprototyped function type.
632 QualType RebuildFunctionNoProtoType(QualType ResultType);
633
John McCalled976492009-12-04 22:46:56 +0000634 /// \brief Rebuild an unresolved typename type, given the decl that
635 /// the UnresolvedUsingTypenameDecl was transformed to.
636 QualType RebuildUnresolvedUsingType(Decl *D);
637
Douglas Gregor577f75a2009-08-04 16:50:30 +0000638 /// \brief Build a new typedef type.
639 QualType RebuildTypedefType(TypedefDecl *Typedef) {
640 return SemaRef.Context.getTypeDeclType(Typedef);
641 }
642
643 /// \brief Build a new class/struct/union type.
644 QualType RebuildRecordType(RecordDecl *Record) {
645 return SemaRef.Context.getTypeDeclType(Record);
646 }
647
648 /// \brief Build a new Enum type.
649 QualType RebuildEnumType(EnumDecl *Enum) {
650 return SemaRef.Context.getTypeDeclType(Enum);
651 }
John McCall7da24312009-09-05 00:15:47 +0000652
Mike Stump1eb44332009-09-09 15:08:12 +0000653 /// \brief Build a new typeof(expr) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000654 ///
655 /// By default, performs semantic analysis when building the typeof type.
656 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000657 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +0000658
Mike Stump1eb44332009-09-09 15:08:12 +0000659 /// \brief Build a new typeof(type) type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000660 ///
661 /// By default, builds a new TypeOfType with the given underlying type.
662 QualType RebuildTypeOfType(QualType Underlying);
663
Mike Stump1eb44332009-09-09 15:08:12 +0000664 /// \brief Build a new C++0x decltype type.
Douglas Gregor577f75a2009-08-04 16:50:30 +0000665 ///
666 /// By default, performs semantic analysis when building the decltype type.
667 /// Subclasses may override this routine to provide different behavior.
John McCall2a984ca2010-10-12 00:20:44 +0000668 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump1eb44332009-09-09 15:08:12 +0000669
Douglas Gregor577f75a2009-08-04 16:50:30 +0000670 /// \brief Build a new template specialization type.
671 ///
672 /// By default, performs semantic analysis when building the template
673 /// specialization type. Subclasses may override this routine to provide
674 /// different behavior.
675 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall833ca992009-10-29 08:12:44 +0000676 SourceLocation TemplateLoc,
John McCalld5532b62009-11-23 01:53:49 +0000677 const TemplateArgumentListInfo &Args);
Mike Stump1eb44332009-09-09 15:08:12 +0000678
Abramo Bagnara075f8f12010-12-10 16:29:40 +0000679 /// \brief Build a new parenthesized type.
680 ///
681 /// By default, builds a new ParenType type from the inner type.
682 /// Subclasses may override this routine to provide different behavior.
683 QualType RebuildParenType(QualType InnerType) {
684 return SemaRef.Context.getParenType(InnerType);
685 }
686
Douglas Gregor577f75a2009-08-04 16:50:30 +0000687 /// \brief Build a new qualified name type.
688 ///
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000689 /// By default, builds a new ElaboratedType type from the keyword,
690 /// the nested-name-specifier and the named type.
691 /// Subclasses may override this routine to provide different behavior.
John McCall21e413f2010-11-04 19:04:38 +0000692 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
693 ElaboratedTypeKeyword Keyword,
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000694 NestedNameSpecifier *NNS, QualType Named) {
695 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump1eb44332009-09-09 15:08:12 +0000696 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000697
698 /// \brief Build a new typename type that refers to a template-id.
699 ///
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000700 /// By default, builds a new DependentNameType type from the
701 /// nested-name-specifier and the given type. Subclasses may override
702 /// this routine to provide different behavior.
John McCall33500952010-06-11 00:33:02 +0000703 QualType RebuildDependentTemplateSpecializationType(
704 ElaboratedTypeKeyword Keyword,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000705 NestedNameSpecifier *Qualifier,
706 SourceRange QualifierRange,
John McCall33500952010-06-11 00:33:02 +0000707 const IdentifierInfo *Name,
708 SourceLocation NameLoc,
709 const TemplateArgumentListInfo &Args) {
710 // Rebuild the template name.
711 // TODO: avoid TemplateName abstraction
712 TemplateName InstName =
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000713 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall43fed0d2010-11-12 08:19:04 +0000714 QualType(), 0);
John McCall33500952010-06-11 00:33:02 +0000715
Douglas Gregor96fb42e2010-06-18 22:12:56 +0000716 if (InstName.isNull())
717 return QualType();
718
John McCall33500952010-06-11 00:33:02 +0000719 // If it's still dependent, make a dependent specialization.
720 if (InstName.getAsDependentTemplateName())
721 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000722 Keyword, Qualifier, Name, Args);
John McCall33500952010-06-11 00:33:02 +0000723
724 // Otherwise, make an elaborated type wrapping a non-dependent
725 // specialization.
726 QualType T =
727 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
728 if (T.isNull()) return QualType();
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000729
Abramo Bagnara22f638a2010-08-10 13:46:45 +0000730 // NOTE: NNS is already recorded in template specialization type T.
731 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump1eb44332009-09-09 15:08:12 +0000732 }
Douglas Gregor577f75a2009-08-04 16:50:30 +0000733
734 /// \brief Build a new typename type that refers to an identifier.
735 ///
736 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000737 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregor577f75a2009-08-04 16:50:30 +0000738 /// different behavior.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000739 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor4a2023f2010-03-31 20:19:30 +0000740 NestedNameSpecifier *NNS,
741 const IdentifierInfo *Id,
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000742 SourceLocation KeywordLoc,
743 SourceRange NNSRange,
744 SourceLocation IdLoc) {
Douglas Gregor40336422010-03-31 22:19:08 +0000745 CXXScopeSpec SS;
746 SS.setScopeRep(NNS);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000747 SS.setRange(NNSRange);
748
Douglas Gregor40336422010-03-31 22:19:08 +0000749 if (NNS->isDependent()) {
750 // If the name is still dependent, just build a new dependent name type.
751 if (!SemaRef.computeDeclContext(SS))
752 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
753 }
754
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000755 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000756 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
757 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000758
759 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
760
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000761 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregor40336422010-03-31 22:19:08 +0000762 // into a non-dependent elaborated-type-specifier. Find the tag we're
763 // referring to.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000764 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregor40336422010-03-31 22:19:08 +0000765 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
766 if (!DC)
767 return QualType();
768
John McCall56138762010-05-27 06:40:31 +0000769 if (SemaRef.RequireCompleteDeclContext(SS, DC))
770 return QualType();
771
Douglas Gregor40336422010-03-31 22:19:08 +0000772 TagDecl *Tag = 0;
773 SemaRef.LookupQualifiedName(Result, DC);
774 switch (Result.getResultKind()) {
775 case LookupResult::NotFound:
776 case LookupResult::NotFoundInCurrentInstantiation:
777 break;
Sean Huntc3021132010-05-05 15:23:54 +0000778
Douglas Gregor40336422010-03-31 22:19:08 +0000779 case LookupResult::Found:
780 Tag = Result.getAsSingle<TagDecl>();
781 break;
Sean Huntc3021132010-05-05 15:23:54 +0000782
Douglas Gregor40336422010-03-31 22:19:08 +0000783 case LookupResult::FoundOverloaded:
784 case LookupResult::FoundUnresolvedValue:
785 llvm_unreachable("Tag lookup cannot find non-tags");
786 return QualType();
Sean Huntc3021132010-05-05 15:23:54 +0000787
Douglas Gregor40336422010-03-31 22:19:08 +0000788 case LookupResult::Ambiguous:
789 // Let the LookupResult structure handle ambiguities.
790 return QualType();
791 }
792
793 if (!Tag) {
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000794 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000795 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregor1eabb7d2010-03-31 23:17:41 +0000796 << Kind << Id << DC;
Douglas Gregor40336422010-03-31 22:19:08 +0000797 return QualType();
798 }
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000799
Abramo Bagnarae4da7a02010-05-19 21:37:53 +0000800 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
801 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregor40336422010-03-31 22:19:08 +0000802 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
803 return QualType();
804 }
805
806 // Build the elaborated-type-specifier type.
807 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara465d41b2010-05-11 21:36:43 +0000808 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000809 }
Mike Stump1eb44332009-09-09 15:08:12 +0000810
Douglas Gregordcee1a12009-08-06 05:28:30 +0000811 /// \brief Build a new nested-name-specifier given the prefix and an
812 /// identifier that names the next step in the nested-name-specifier.
813 ///
814 /// By default, performs semantic analysis when building the new
815 /// nested-name-specifier. Subclasses may override this routine to provide
816 /// different behavior.
817 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
818 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +0000819 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +0000820 QualType ObjectType,
821 NamedDecl *FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +0000822
823 /// \brief Build a new nested-name-specifier given the prefix and the
824 /// namespace named in the next step in the nested-name-specifier.
825 ///
826 /// By default, performs semantic analysis when building the new
827 /// nested-name-specifier. Subclasses may override this routine to provide
828 /// different behavior.
829 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
830 SourceRange Range,
831 NamespaceDecl *NS);
832
833 /// \brief Build a new nested-name-specifier given the prefix and the
834 /// type named in the next step in the nested-name-specifier.
835 ///
836 /// By default, performs semantic analysis when building the new
837 /// nested-name-specifier. Subclasses may override this routine to provide
838 /// different behavior.
839 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
840 SourceRange Range,
841 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +0000842 QualType T);
Douglas Gregord1067e52009-08-06 06:41:21 +0000843
844 /// \brief Build a new template name given a nested name specifier, a flag
845 /// indicating whether the "template" keyword was provided, and the template
846 /// that the template name refers to.
847 ///
848 /// By default, builds the new template name directly. Subclasses may override
849 /// this routine to provide different behavior.
850 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
851 bool TemplateKW,
852 TemplateDecl *Template);
853
Douglas Gregord1067e52009-08-06 06:41:21 +0000854 /// \brief Build a new template name given a nested name specifier and the
855 /// name that is referred to as a template.
856 ///
857 /// By default, performs semantic analysis to determine whether the name can
858 /// be resolved to a specific template, then builds the appropriate kind of
859 /// template name. Subclasses may override this routine to provide different
860 /// behavior.
861 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +0000862 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +0000863 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +0000864 QualType ObjectType,
865 NamedDecl *FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +0000866
Douglas Gregorca1bdd72009-11-04 00:56:37 +0000867 /// \brief Build a new template name given a nested name specifier and the
868 /// overloaded operator name that is referred to as a template.
869 ///
870 /// By default, performs semantic analysis to determine whether the name can
871 /// be resolved to a specific template, then builds the appropriate kind of
872 /// template name. Subclasses may override this routine to provide different
873 /// behavior.
874 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
875 OverloadedOperatorKind Operator,
876 QualType ObjectType);
Sean Huntc3021132010-05-05 15:23:54 +0000877
Douglas Gregor43959a92009-08-20 07:17:43 +0000878 /// \brief Build a new compound statement.
879 ///
880 /// By default, performs semantic analysis to build the new statement.
881 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000882 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000883 MultiStmtArg Statements,
884 SourceLocation RBraceLoc,
885 bool IsStmtExpr) {
John McCall9ae2f072010-08-23 23:25:46 +0000886 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregor43959a92009-08-20 07:17:43 +0000887 IsStmtExpr);
888 }
889
890 /// \brief Build a new case statement.
891 ///
892 /// By default, performs semantic analysis to build the new statement.
893 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000894 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000895 Expr *LHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000896 SourceLocation EllipsisLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000897 Expr *RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000898 SourceLocation ColonLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000899 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregor43959a92009-08-20 07:17:43 +0000900 ColonLoc);
901 }
Mike Stump1eb44332009-09-09 15:08:12 +0000902
Douglas Gregor43959a92009-08-20 07:17:43 +0000903 /// \brief Attach the body to a new case statement.
904 ///
905 /// By default, performs semantic analysis to build the new statement.
906 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000907 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCall9ae2f072010-08-23 23:25:46 +0000908 getSema().ActOnCaseStmtBody(S, Body);
909 return S;
Douglas Gregor43959a92009-08-20 07:17:43 +0000910 }
Mike Stump1eb44332009-09-09 15:08:12 +0000911
Douglas Gregor43959a92009-08-20 07:17:43 +0000912 /// \brief Build a new default statement.
913 ///
914 /// By default, performs semantic analysis to build the new statement.
915 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000916 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000917 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000918 Stmt *SubStmt) {
919 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregor43959a92009-08-20 07:17:43 +0000920 /*CurScope=*/0);
921 }
Mike Stump1eb44332009-09-09 15:08:12 +0000922
Douglas Gregor43959a92009-08-20 07:17:43 +0000923 /// \brief Build a new label statement.
924 ///
925 /// By default, performs semantic analysis to build the new statement.
926 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000927 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000928 IdentifierInfo *Id,
929 SourceLocation ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +0000930 Stmt *SubStmt, bool HasUnusedAttr) {
931 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
932 HasUnusedAttr);
Douglas Gregor43959a92009-08-20 07:17:43 +0000933 }
Mike Stump1eb44332009-09-09 15:08:12 +0000934
Douglas Gregor43959a92009-08-20 07:17:43 +0000935 /// \brief Build a new "if" statement.
936 ///
937 /// By default, performs semantic analysis to build the new statement.
938 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000939 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000940 VarDecl *CondVar, Stmt *Then,
John McCall9ae2f072010-08-23 23:25:46 +0000941 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +0000942 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregor43959a92009-08-20 07:17:43 +0000943 }
Mike Stump1eb44332009-09-09 15:08:12 +0000944
Douglas Gregor43959a92009-08-20 07:17:43 +0000945 /// \brief Start building a new switch statement.
946 ///
947 /// By default, performs semantic analysis to build the new statement.
948 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000949 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000950 Expr *Cond, VarDecl *CondVar) {
951 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCalld226f652010-08-21 09:40:31 +0000952 CondVar);
Douglas Gregor43959a92009-08-20 07:17:43 +0000953 }
Mike Stump1eb44332009-09-09 15:08:12 +0000954
Douglas Gregor43959a92009-08-20 07:17:43 +0000955 /// \brief Attach the body to the switch 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 RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000960 Stmt *Switch, Stmt *Body) {
961 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000962 }
963
964 /// \brief Build a new while statement.
965 ///
966 /// By default, performs semantic analysis to build the new statement.
967 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000968 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregoreaa18e42010-05-08 22:20:28 +0000969 Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000970 VarDecl *CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000971 Stmt *Body) {
972 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +0000973 }
Mike Stump1eb44332009-09-09 15:08:12 +0000974
Douglas Gregor43959a92009-08-20 07:17:43 +0000975 /// \brief Build a new do-while statement.
976 ///
977 /// By default, performs semantic analysis to build the new statement.
978 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000979 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregor43959a92009-08-20 07:17:43 +0000980 SourceLocation WhileLoc,
981 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000982 Expr *Cond,
Douglas Gregor43959a92009-08-20 07:17:43 +0000983 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +0000984 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
985 Cond, RParenLoc);
Douglas Gregor43959a92009-08-20 07:17:43 +0000986 }
987
988 /// \brief Build a new for statement.
989 ///
990 /// By default, performs semantic analysis to build the new statement.
991 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +0000992 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +0000993 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +0000994 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor99e9b4d2009-11-25 00:27:52 +0000995 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCall9ae2f072010-08-23 23:25:46 +0000996 SourceLocation RParenLoc, Stmt *Body) {
997 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCalld226f652010-08-21 09:40:31 +0000998 CondVar,
John McCall9ae2f072010-08-23 23:25:46 +0000999 Inc, RParenLoc, Body);
Douglas Gregor43959a92009-08-20 07:17:43 +00001000 }
Mike Stump1eb44332009-09-09 15:08:12 +00001001
Douglas Gregor43959a92009-08-20 07:17:43 +00001002 /// \brief Build a new goto statement.
1003 ///
1004 /// By default, performs semantic analysis to build the new statement.
1005 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001006 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001007 SourceLocation LabelLoc,
1008 LabelStmt *Label) {
1009 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
1010 }
1011
1012 /// \brief Build a new indirect goto statement.
1013 ///
1014 /// By default, performs semantic analysis to build the new statement.
1015 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001016 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001017 SourceLocation StarLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001018 Expr *Target) {
1019 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregor43959a92009-08-20 07:17:43 +00001020 }
Mike Stump1eb44332009-09-09 15:08:12 +00001021
Douglas Gregor43959a92009-08-20 07:17:43 +00001022 /// \brief Build a new return statement.
1023 ///
1024 /// By default, performs semantic analysis to build the new statement.
1025 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001026 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001027 Expr *Result) {
Mike Stump1eb44332009-09-09 15:08:12 +00001028
John McCall9ae2f072010-08-23 23:25:46 +00001029 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregor43959a92009-08-20 07:17:43 +00001030 }
Mike Stump1eb44332009-09-09 15:08:12 +00001031
Douglas Gregor43959a92009-08-20 07:17:43 +00001032 /// \brief Build a new declaration statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001036 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump1eb44332009-09-09 15:08:12 +00001037 SourceLocation StartLoc,
Douglas Gregor43959a92009-08-20 07:17:43 +00001038 SourceLocation EndLoc) {
1039 return getSema().Owned(
1040 new (getSema().Context) DeclStmt(
1041 DeclGroupRef::Create(getSema().Context,
1042 Decls, NumDecls),
1043 StartLoc, EndLoc));
1044 }
Mike Stump1eb44332009-09-09 15:08:12 +00001045
Anders Carlsson703e3942010-01-24 05:50:09 +00001046 /// \brief Build a new inline asm statement.
1047 ///
1048 /// By default, performs semantic analysis to build the new statement.
1049 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001050 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlsson703e3942010-01-24 05:50:09 +00001051 bool IsSimple,
1052 bool IsVolatile,
1053 unsigned NumOutputs,
1054 unsigned NumInputs,
Anders Carlssonff93dbd2010-01-30 22:25:16 +00001055 IdentifierInfo **Names,
Anders Carlsson703e3942010-01-24 05:50:09 +00001056 MultiExprArg Constraints,
1057 MultiExprArg Exprs,
John McCall9ae2f072010-08-23 23:25:46 +00001058 Expr *AsmString,
Anders Carlsson703e3942010-01-24 05:50:09 +00001059 MultiExprArg Clobbers,
1060 SourceLocation RParenLoc,
1061 bool MSAsm) {
Sean Huntc3021132010-05-05 15:23:54 +00001062 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlsson703e3942010-01-24 05:50:09 +00001063 NumInputs, Names, move(Constraints),
John McCall9ae2f072010-08-23 23:25:46 +00001064 Exprs, AsmString, Clobbers,
Anders Carlsson703e3942010-01-24 05:50:09 +00001065 RParenLoc, MSAsm);
1066 }
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001067
1068 /// \brief Build a new Objective-C @try statement.
1069 ///
1070 /// By default, performs semantic analysis to build the new statement.
1071 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001072 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001073 Stmt *TryBody,
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00001074 MultiStmtArg CatchStmts,
John McCall9ae2f072010-08-23 23:25:46 +00001075 Stmt *Finally) {
1076 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1077 Finally);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001078 }
1079
Douglas Gregorbe270a02010-04-26 17:57:08 +00001080 /// \brief Rebuild an Objective-C exception declaration.
1081 ///
1082 /// By default, performs semantic analysis to build the new declaration.
1083 /// Subclasses may override this routine to provide different behavior.
1084 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1085 TypeSourceInfo *TInfo, QualType T) {
Sean Huntc3021132010-05-05 15:23:54 +00001086 return getSema().BuildObjCExceptionDecl(TInfo, T,
1087 ExceptionDecl->getIdentifier(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00001088 ExceptionDecl->getLocation());
1089 }
Sean Huntc3021132010-05-05 15:23:54 +00001090
Douglas Gregorbe270a02010-04-26 17:57:08 +00001091 /// \brief Build a new Objective-C @catch statement.
1092 ///
1093 /// By default, performs semantic analysis to build the new statement.
1094 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001095 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorbe270a02010-04-26 17:57:08 +00001096 SourceLocation RParenLoc,
1097 VarDecl *Var,
John McCall9ae2f072010-08-23 23:25:46 +00001098 Stmt *Body) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00001099 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001100 Var, Body);
Douglas Gregorbe270a02010-04-26 17:57:08 +00001101 }
Sean Huntc3021132010-05-05 15:23:54 +00001102
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001103 /// \brief Build a new Objective-C @finally statement.
1104 ///
1105 /// By default, performs semantic analysis to build the new statement.
1106 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001107 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001108 Stmt *Body) {
1109 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00001110 }
Sean Huntc3021132010-05-05 15:23:54 +00001111
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001112 /// \brief Build a new Objective-C @throw statement.
Douglas Gregord1377b22010-04-22 21:44:01 +00001113 ///
1114 /// By default, performs semantic analysis to build the new statement.
1115 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001116 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001117 Expr *Operand) {
1118 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregord1377b22010-04-22 21:44:01 +00001119 }
Sean Huntc3021132010-05-05 15:23:54 +00001120
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001121 /// \brief Build a new Objective-C @synchronized statement.
1122 ///
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001125 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001126 Expr *Object,
1127 Stmt *Body) {
1128 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1129 Body);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00001130 }
Douglas Gregorc3203e72010-04-22 23:10:45 +00001131
1132 /// \brief Build a new Objective-C fast enumeration statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001136 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001137 SourceLocation LParenLoc,
1138 Stmt *Element,
1139 Expr *Collection,
1140 SourceLocation RParenLoc,
1141 Stmt *Body) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00001142 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001143 Element,
1144 Collection,
Douglas Gregorc3203e72010-04-22 23:10:45 +00001145 RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001146 Body);
Douglas Gregorc3203e72010-04-22 23:10:45 +00001147 }
Sean Huntc3021132010-05-05 15:23:54 +00001148
Douglas Gregor43959a92009-08-20 07:17:43 +00001149 /// \brief Build a new C++ exception declaration.
1150 ///
1151 /// By default, performs semantic analysis to build the new decaration.
1152 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor83cb9422010-09-09 17:09:21 +00001153 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCalla93c9342009-12-07 02:54:59 +00001154 TypeSourceInfo *Declarator,
Douglas Gregor43959a92009-08-20 07:17:43 +00001155 IdentifierInfo *Name,
Douglas Gregor83cb9422010-09-09 17:09:21 +00001156 SourceLocation Loc) {
1157 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregor43959a92009-08-20 07:17:43 +00001158 }
1159
1160 /// \brief Build a new C++ catch statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001164 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001165 VarDecl *ExceptionDecl,
1166 Stmt *Handler) {
John McCall9ae2f072010-08-23 23:25:46 +00001167 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1168 Handler));
Douglas Gregor43959a92009-08-20 07:17:43 +00001169 }
Mike Stump1eb44332009-09-09 15:08:12 +00001170
Douglas Gregor43959a92009-08-20 07:17:43 +00001171 /// \brief Build a new C++ try statement.
1172 ///
1173 /// By default, performs semantic analysis to build the new statement.
1174 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001175 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001176 Stmt *TryBlock,
1177 MultiStmtArg Handlers) {
John McCall9ae2f072010-08-23 23:25:46 +00001178 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00001179 }
Mike Stump1eb44332009-09-09 15:08:12 +00001180
Douglas Gregorb98b1992009-08-11 05:31:07 +00001181 /// \brief Build a new expression that references a declaration.
1182 ///
1183 /// By default, performs semantic analysis to build the new expression.
1184 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001185 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallf312b1e2010-08-26 23:41:50 +00001186 LookupResult &R,
1187 bool RequiresADL) {
John McCallf7a1a742009-11-24 19:00:30 +00001188 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1189 }
1190
1191
1192 /// \brief Build a new expression that references a declaration.
1193 ///
1194 /// By default, performs semantic analysis to build the new expression.
1195 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001196 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallf312b1e2010-08-26 23:41:50 +00001197 SourceRange QualifierRange,
1198 ValueDecl *VD,
1199 const DeclarationNameInfo &NameInfo,
1200 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00001201 CXXScopeSpec SS;
1202 SS.setScopeRep(Qualifier);
1203 SS.setRange(QualifierRange);
John McCalldbd872f2009-12-08 09:08:17 +00001204
1205 // FIXME: loses template args.
Abramo Bagnara25777432010-08-11 22:01:17 +00001206
1207 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001208 }
Mike Stump1eb44332009-09-09 15:08:12 +00001209
Douglas Gregorb98b1992009-08-11 05:31:07 +00001210 /// \brief Build a new expression in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001211 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001212 /// By default, performs semantic analysis to build the new expression.
1213 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001214 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001215 SourceLocation RParen) {
John McCall9ae2f072010-08-23 23:25:46 +00001216 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001217 }
1218
Douglas Gregora71d8192009-09-04 17:36:40 +00001219 /// \brief Build a new pseudo-destructor expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001220 ///
Douglas Gregora71d8192009-09-04 17:36:40 +00001221 /// By default, performs semantic analysis to build the new expression.
1222 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001223 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora71d8192009-09-04 17:36:40 +00001224 SourceLocation OperatorLoc,
1225 bool isArrow,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001226 NestedNameSpecifier *Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00001227 SourceRange QualifierRange,
1228 TypeSourceInfo *ScopeType,
1229 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00001230 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00001231 PseudoDestructorTypeStorage Destroyed);
Mike Stump1eb44332009-09-09 15:08:12 +00001232
Douglas Gregorb98b1992009-08-11 05:31:07 +00001233 /// \brief Build a new unary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001234 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001235 /// By default, performs semantic analysis to build the new expression.
1236 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001237 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001238 UnaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001239 Expr *SubExpr) {
1240 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001241 }
Mike Stump1eb44332009-09-09 15:08:12 +00001242
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001243 /// \brief Build a new builtin offsetof expression.
1244 ///
1245 /// By default, performs semantic analysis to build the new expression.
1246 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001247 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001248 TypeSourceInfo *Type,
John McCallf312b1e2010-08-26 23:41:50 +00001249 Sema::OffsetOfComponent *Components,
Douglas Gregor8ecdb652010-04-28 22:16:22 +00001250 unsigned NumComponents,
1251 SourceLocation RParenLoc) {
1252 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1253 NumComponents, RParenLoc);
1254 }
Sean Huntc3021132010-05-05 15:23:54 +00001255
Douglas Gregorb98b1992009-08-11 05:31:07 +00001256 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001257 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001258 /// By default, performs semantic analysis to build the new expression.
1259 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001260 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall5ab75172009-11-04 07:28:41 +00001261 SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001262 bool isSizeOf, SourceRange R) {
John McCalla93c9342009-12-07 02:54:59 +00001263 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001264 }
1265
Mike Stump1eb44332009-09-09 15:08:12 +00001266 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregorb98b1992009-08-11 05:31:07 +00001267 /// argument.
Mike Stump1eb44332009-09-09 15:08:12 +00001268 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001269 /// By default, performs semantic analysis to build the new expression.
1270 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001271 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001272 bool isSizeOf, SourceRange R) {
John McCall60d7b3a2010-08-24 06:29:42 +00001273 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00001274 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001275 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001276 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001277
Douglas Gregorb98b1992009-08-11 05:31:07 +00001278 return move(Result);
1279 }
Mike Stump1eb44332009-09-09 15:08:12 +00001280
Douglas Gregorb98b1992009-08-11 05:31:07 +00001281 /// \brief Build a new array subscript expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001282 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001283 /// By default, performs semantic analysis to build the new expression.
1284 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001285 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001286 SourceLocation LBracketLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001287 Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001288 SourceLocation RBracketLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001289 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1290 LBracketLoc, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001291 RBracketLoc);
1292 }
1293
1294 /// \brief Build a new call expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001295 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001296 /// By default, performs semantic analysis to build the new expression.
1297 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001298 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001299 MultiExprArg Args,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001300 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001301 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregora1a04782010-09-09 16:33:13 +00001302 move(Args), RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001303 }
1304
1305 /// \brief Build a new member access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001306 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001307 /// By default, performs semantic analysis to build the new expression.
1308 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001309 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCallf89e55a2010-11-18 06:31:45 +00001310 bool isArrow,
1311 NestedNameSpecifier *Qualifier,
1312 SourceRange QualifierRange,
1313 const DeclarationNameInfo &MemberNameInfo,
1314 ValueDecl *Member,
1315 NamedDecl *FoundDecl,
John McCalld5532b62009-11-23 01:53:49 +00001316 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCallf89e55a2010-11-18 06:31:45 +00001317 NamedDecl *FirstQualifierInScope) {
Anders Carlssond8b285f2009-09-01 04:26:58 +00001318 if (!Member->getDeclName()) {
John McCallf89e55a2010-11-18 06:31:45 +00001319 // We have a reference to an unnamed field. This is always the
1320 // base of an anonymous struct/union member access, i.e. the
1321 // field is always of record type.
Anders Carlssond8b285f2009-09-01 04:26:58 +00001322 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCallf89e55a2010-11-18 06:31:45 +00001323 assert(Member->getType()->isRecordType() &&
1324 "unnamed member not of record type?");
Mike Stump1eb44332009-09-09 15:08:12 +00001325
John McCall9ae2f072010-08-23 23:25:46 +00001326 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall6bb80172010-03-30 21:47:33 +00001327 FoundDecl, Member))
John McCallf312b1e2010-08-26 23:41:50 +00001328 return ExprError();
Douglas Gregor8aa5f402009-12-24 20:23:34 +00001329
John McCallf89e55a2010-11-18 06:31:45 +00001330 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump1eb44332009-09-09 15:08:12 +00001331 MemberExpr *ME =
John McCall9ae2f072010-08-23 23:25:46 +00001332 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnara25777432010-08-11 22:01:17 +00001333 Member, MemberNameInfo,
John McCallf89e55a2010-11-18 06:31:45 +00001334 cast<FieldDecl>(Member)->getType(),
1335 VK, OK_Ordinary);
Anders Carlssond8b285f2009-09-01 04:26:58 +00001336 return getSema().Owned(ME);
1337 }
Mike Stump1eb44332009-09-09 15:08:12 +00001338
Douglas Gregor83f6faf2009-08-31 23:41:50 +00001339 CXXScopeSpec SS;
1340 if (Qualifier) {
1341 SS.setRange(QualifierRange);
1342 SS.setScopeRep(Qualifier);
1343 }
1344
John McCall9ae2f072010-08-23 23:25:46 +00001345 getSema().DefaultFunctionArrayConversion(Base);
1346 QualType BaseType = Base->getType();
John McCallaa81e162009-12-01 22:10:20 +00001347
John McCall6bb80172010-03-30 21:47:33 +00001348 // FIXME: this involves duplicating earlier analysis in a lot of
1349 // cases; we should avoid this when possible.
Abramo Bagnara25777432010-08-11 22:01:17 +00001350 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall6bb80172010-03-30 21:47:33 +00001351 R.addDecl(FoundDecl);
John McCallc2233c52010-01-15 08:34:02 +00001352 R.resolveKind();
1353
John McCall9ae2f072010-08-23 23:25:46 +00001354 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall129e2df2009-11-30 22:42:35 +00001355 SS, FirstQualifierInScope,
John McCallc2233c52010-01-15 08:34:02 +00001356 R, ExplicitTemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001357 }
Mike Stump1eb44332009-09-09 15:08:12 +00001358
Douglas Gregorb98b1992009-08-11 05:31:07 +00001359 /// \brief Build a new binary operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001360 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001361 /// By default, performs semantic analysis to build the new expression.
1362 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001363 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCall2de56d12010-08-25 11:45:40 +00001364 BinaryOperatorKind Opc,
John McCall9ae2f072010-08-23 23:25:46 +00001365 Expr *LHS, Expr *RHS) {
1366 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001367 }
1368
1369 /// \brief Build a new conditional operator expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001370 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001371 /// By default, performs semantic analysis to build the new expression.
1372 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001373 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001374 SourceLocation QuestionLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001375 Expr *LHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001376 SourceLocation ColonLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001377 Expr *RHS) {
1378 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1379 LHS, RHS);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001380 }
1381
Douglas Gregorb98b1992009-08-11 05:31:07 +00001382 /// \brief Build a new C-style cast expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001383 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001384 /// By default, performs semantic analysis to build the new expression.
1385 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001386 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall9d125032010-01-15 18:39:57 +00001387 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001388 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001389 Expr *SubExpr) {
John McCallb042fdf2010-01-15 18:56:44 +00001390 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001391 SubExpr);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001392 }
Mike Stump1eb44332009-09-09 15:08:12 +00001393
Douglas Gregorb98b1992009-08-11 05:31:07 +00001394 /// \brief Build a new compound literal expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001395 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001396 /// By default, performs semantic analysis to build the new expression.
1397 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001398 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCall42f56b52010-01-18 19:35:47 +00001399 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001400 SourceLocation RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001401 Expr *Init) {
John McCall42f56b52010-01-18 19:35:47 +00001402 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001403 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001404 }
Mike Stump1eb44332009-09-09 15:08:12 +00001405
Douglas Gregorb98b1992009-08-11 05:31:07 +00001406 /// \brief Build a new extended vector element access expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001407 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001408 /// By default, performs semantic analysis to build the new expression.
1409 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001410 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001411 SourceLocation OpLoc,
1412 SourceLocation AccessorLoc,
1413 IdentifierInfo &Accessor) {
John McCallaa81e162009-12-01 22:10:20 +00001414
John McCall129e2df2009-11-30 22:42:35 +00001415 CXXScopeSpec SS;
Abramo Bagnara25777432010-08-11 22:01:17 +00001416 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCall9ae2f072010-08-23 23:25:46 +00001417 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall129e2df2009-11-30 22:42:35 +00001418 OpLoc, /*IsArrow*/ false,
1419 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00001420 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001421 /* TemplateArgs */ 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001422 }
Mike Stump1eb44332009-09-09 15:08:12 +00001423
Douglas Gregorb98b1992009-08-11 05:31:07 +00001424 /// \brief Build a new initializer list 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 RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001429 MultiExprArg Inits,
Douglas Gregore48319a2009-11-09 17:16:50 +00001430 SourceLocation RBraceLoc,
1431 QualType ResultTy) {
John McCall60d7b3a2010-08-24 06:29:42 +00001432 ExprResult Result
Douglas Gregore48319a2009-11-09 17:16:50 +00001433 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1434 if (Result.isInvalid() || ResultTy->isDependentType())
1435 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00001436
Douglas Gregore48319a2009-11-09 17:16:50 +00001437 // Patch in the result type we were given, which may have been computed
1438 // when the initial InitListExpr was built.
1439 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1440 ILE->setType(ResultTy);
1441 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001442 }
Mike Stump1eb44332009-09-09 15:08:12 +00001443
Douglas Gregorb98b1992009-08-11 05:31:07 +00001444 /// \brief Build a new designated initializer expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001445 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001446 /// By default, performs semantic analysis to build the new expression.
1447 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001448 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001449 MultiExprArg ArrayExprs,
1450 SourceLocation EqualOrColonLoc,
1451 bool GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001452 Expr *Init) {
John McCall60d7b3a2010-08-24 06:29:42 +00001453 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00001454 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCall9ae2f072010-08-23 23:25:46 +00001455 Init);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001456 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00001457 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00001458
Douglas Gregorb98b1992009-08-11 05:31:07 +00001459 ArrayExprs.release();
1460 return move(Result);
1461 }
Mike Stump1eb44332009-09-09 15:08:12 +00001462
Douglas Gregorb98b1992009-08-11 05:31:07 +00001463 /// \brief Build a new value-initialized expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001464 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001465 /// By default, builds the implicit value initialization without performing
1466 /// any semantic analysis. Subclasses may override this routine to provide
1467 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001468 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001469 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1470 }
Mike Stump1eb44332009-09-09 15:08:12 +00001471
Douglas Gregorb98b1992009-08-11 05:31:07 +00001472 /// \brief Build a new \c va_arg expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001473 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001474 /// By default, performs semantic analysis to build the new expression.
1475 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001476 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001477 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001478 SourceLocation RParenLoc) {
1479 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001480 SubExpr, TInfo,
Abramo Bagnara2cad9002010-08-10 10:06:15 +00001481 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001482 }
1483
1484 /// \brief Build a new expression list in parentheses.
Mike Stump1eb44332009-09-09 15:08:12 +00001485 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001486 /// By default, performs semantic analysis to build the new expression.
1487 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001488 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001489 MultiExprArg SubExprs,
1490 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001491 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanianf88f7ab2009-11-25 01:26:41 +00001492 move(SubExprs));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001493 }
Mike Stump1eb44332009-09-09 15:08:12 +00001494
Douglas Gregorb98b1992009-08-11 05:31:07 +00001495 /// \brief Build a new address-of-label expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001496 ///
1497 /// By default, performs semantic analysis, using the name of the label
Douglas Gregorb98b1992009-08-11 05:31:07 +00001498 /// rather than attempting to map the label statement itself.
1499 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001500 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001501 SourceLocation LabelLoc,
1502 LabelStmt *Label) {
1503 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1504 }
Mike Stump1eb44332009-09-09 15:08:12 +00001505
Douglas Gregorb98b1992009-08-11 05:31:07 +00001506 /// \brief Build a new GNU statement expression.
Mike Stump1eb44332009-09-09 15:08:12 +00001507 ///
Douglas Gregorb98b1992009-08-11 05:31:07 +00001508 /// By default, performs semantic analysis to build the new expression.
1509 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001510 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001511 Stmt *SubStmt,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001512 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001513 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001514 }
Mike Stump1eb44332009-09-09 15:08:12 +00001515
Douglas Gregorb98b1992009-08-11 05:31:07 +00001516 /// \brief Build a new __builtin_choose_expr expression.
1517 ///
1518 /// By default, performs semantic analysis to build the new expression.
1519 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001520 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001521 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001522 SourceLocation RParenLoc) {
1523 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001524 Cond, LHS, RHS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001525 RParenLoc);
1526 }
Mike Stump1eb44332009-09-09 15:08:12 +00001527
Douglas Gregorb98b1992009-08-11 05:31:07 +00001528 /// \brief Build a new overloaded operator call expression.
1529 ///
1530 /// By default, performs semantic analysis to build the new expression.
1531 /// The semantic analysis provides the behavior of template instantiation,
1532 /// copying with transformations that turn what looks like an overloaded
Mike Stump1eb44332009-09-09 15:08:12 +00001533 /// operator call into a use of a builtin operator, performing
Douglas Gregorb98b1992009-08-11 05:31:07 +00001534 /// argument-dependent lookup, etc. Subclasses may override this routine to
1535 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001536 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001537 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001538 Expr *Callee,
1539 Expr *First,
1540 Expr *Second);
Mike Stump1eb44332009-09-09 15:08:12 +00001541
1542 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregorb98b1992009-08-11 05:31:07 +00001543 /// reinterpret_cast.
1544 ///
1545 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump1eb44332009-09-09 15:08:12 +00001546 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregorb98b1992009-08-11 05:31:07 +00001547 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001548 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001549 Stmt::StmtClass Class,
1550 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001551 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001552 SourceLocation RAngleLoc,
1553 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001554 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001555 SourceLocation RParenLoc) {
1556 switch (Class) {
1557 case Stmt::CXXStaticCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001558 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001559 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001560 SubExpr, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001561
1562 case Stmt::CXXDynamicCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001563 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001564 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001565 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001566
Douglas Gregorb98b1992009-08-11 05:31:07 +00001567 case Stmt::CXXReinterpretCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001568 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001569 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001570 SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001571 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001572
Douglas Gregorb98b1992009-08-11 05:31:07 +00001573 case Stmt::CXXConstCastExprClass:
John McCall9d125032010-01-15 18:39:57 +00001574 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump1eb44332009-09-09 15:08:12 +00001575 RAngleLoc, LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001576 SubExpr, RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001577
Douglas Gregorb98b1992009-08-11 05:31:07 +00001578 default:
1579 assert(false && "Invalid C++ named cast");
1580 break;
1581 }
Mike Stump1eb44332009-09-09 15:08:12 +00001582
John McCallf312b1e2010-08-26 23:41:50 +00001583 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00001584 }
Mike Stump1eb44332009-09-09 15:08:12 +00001585
Douglas Gregorb98b1992009-08-11 05:31:07 +00001586 /// \brief Build a new C++ static_cast expression.
1587 ///
1588 /// By default, performs semantic analysis to build the new expression.
1589 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001590 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001591 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001592 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001593 SourceLocation RAngleLoc,
1594 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001595 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001596 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001597 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001598 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001599 SourceRange(LAngleLoc, RAngleLoc),
1600 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001601 }
1602
1603 /// \brief Build a new C++ dynamic_cast expression.
1604 ///
1605 /// By default, performs semantic analysis to build the new expression.
1606 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001607 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001608 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001609 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001610 SourceLocation RAngleLoc,
1611 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001612 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001613 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001614 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001615 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001616 SourceRange(LAngleLoc, RAngleLoc),
1617 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001618 }
1619
1620 /// \brief Build a new C++ reinterpret_cast expression.
1621 ///
1622 /// By default, performs semantic analysis to build the new expression.
1623 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001624 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001625 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001626 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001627 SourceLocation RAngleLoc,
1628 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001629 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001630 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001631 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001632 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001633 SourceRange(LAngleLoc, RAngleLoc),
1634 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001635 }
1636
1637 /// \brief Build a new C++ const_cast expression.
1638 ///
1639 /// By default, performs semantic analysis to build the new expression.
1640 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001641 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001642 SourceLocation LAngleLoc,
John McCall9d125032010-01-15 18:39:57 +00001643 TypeSourceInfo *TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001644 SourceLocation RAngleLoc,
1645 SourceLocation LParenLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001646 Expr *SubExpr,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001647 SourceLocation RParenLoc) {
John McCallc89724c2010-01-15 19:13:16 +00001648 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCall9ae2f072010-08-23 23:25:46 +00001649 TInfo, SubExpr,
John McCallc89724c2010-01-15 19:13:16 +00001650 SourceRange(LAngleLoc, RAngleLoc),
1651 SourceRange(LParenLoc, RParenLoc));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001652 }
Mike Stump1eb44332009-09-09 15:08:12 +00001653
Douglas Gregorb98b1992009-08-11 05:31:07 +00001654 /// \brief Build a new C++ functional-style cast expression.
1655 ///
1656 /// By default, performs semantic analysis to build the new expression.
1657 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001658 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1659 SourceLocation LParenLoc,
1660 Expr *Sub,
1661 SourceLocation RParenLoc) {
1662 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallf312b1e2010-08-26 23:41:50 +00001663 MultiExprArg(&Sub, 1),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001664 RParenLoc);
1665 }
Mike Stump1eb44332009-09-09 15:08:12 +00001666
Douglas Gregorb98b1992009-08-11 05:31:07 +00001667 /// \brief Build a new C++ typeid(type) expression.
1668 ///
1669 /// By default, performs semantic analysis to build the new expression.
1670 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001671 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001672 SourceLocation TypeidLoc,
1673 TypeSourceInfo *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001674 SourceLocation RParenLoc) {
Sean Huntc3021132010-05-05 15:23:54 +00001675 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001676 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001677 }
Mike Stump1eb44332009-09-09 15:08:12 +00001678
Francois Pichet01b7c302010-09-08 12:20:18 +00001679
Douglas Gregorb98b1992009-08-11 05:31:07 +00001680 /// \brief Build a new C++ typeid(expr) expression.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001684 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001685 SourceLocation TypeidLoc,
John McCall9ae2f072010-08-23 23:25:46 +00001686 Expr *Operand,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001687 SourceLocation RParenLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00001688 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00001689 RParenLoc);
Mike Stump1eb44332009-09-09 15:08:12 +00001690 }
1691
Francois Pichet01b7c302010-09-08 12:20:18 +00001692 /// \brief Build a new C++ __uuidof(type) expression.
1693 ///
1694 /// By default, performs semantic analysis to build the new expression.
1695 /// Subclasses may override this routine to provide different behavior.
1696 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1697 SourceLocation TypeidLoc,
1698 TypeSourceInfo *Operand,
1699 SourceLocation RParenLoc) {
1700 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1701 RParenLoc);
1702 }
1703
1704 /// \brief Build a new C++ __uuidof(expr) expression.
1705 ///
1706 /// By default, performs semantic analysis to build the new expression.
1707 /// Subclasses may override this routine to provide different behavior.
1708 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1709 SourceLocation TypeidLoc,
1710 Expr *Operand,
1711 SourceLocation RParenLoc) {
1712 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1713 RParenLoc);
1714 }
1715
Douglas Gregorb98b1992009-08-11 05:31:07 +00001716 /// \brief Build a new C++ "this" expression.
1717 ///
1718 /// By default, builds a new "this" expression without performing any
Mike Stump1eb44332009-09-09 15:08:12 +00001719 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregorb98b1992009-08-11 05:31:07 +00001720 /// different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001721 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00001722 QualType ThisType,
1723 bool isImplicit) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001724 return getSema().Owned(
Douglas Gregor828a1972010-01-07 23:12:05 +00001725 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1726 isImplicit));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001727 }
1728
1729 /// \brief Build a new C++ throw expression.
1730 ///
1731 /// By default, performs semantic analysis to build the new expression.
1732 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001733 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCall9ae2f072010-08-23 23:25:46 +00001734 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001735 }
1736
1737 /// \brief Build a new C++ default-argument expression.
1738 ///
1739 /// By default, builds a new default-argument expression, which does not
1740 /// require any semantic analysis. Subclasses may override this routine to
1741 /// provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001742 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor036aed12009-12-23 23:03:06 +00001743 ParmVarDecl *Param) {
1744 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1745 Param));
Douglas Gregorb98b1992009-08-11 05:31:07 +00001746 }
1747
1748 /// \brief Build a new C++ zero-initialization expression.
1749 ///
1750 /// By default, performs semantic analysis to build the new expression.
1751 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001752 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1753 SourceLocation LParenLoc,
1754 SourceLocation RParenLoc) {
1755 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump1eb44332009-09-09 15:08:12 +00001756 MultiExprArg(getSema(), 0, 0),
Douglas Gregorab6677e2010-09-08 00:15:04 +00001757 RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001758 }
Mike Stump1eb44332009-09-09 15:08:12 +00001759
Douglas Gregorb98b1992009-08-11 05:31:07 +00001760 /// \brief Build a new C++ "new" expression.
1761 ///
1762 /// By default, performs semantic analysis to build the new expression.
1763 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001764 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001765 bool UseGlobal,
1766 SourceLocation PlacementLParen,
1767 MultiExprArg PlacementArgs,
1768 SourceLocation PlacementRParen,
1769 SourceRange TypeIdParens,
1770 QualType AllocatedType,
1771 TypeSourceInfo *AllocatedTypeInfo,
1772 Expr *ArraySize,
1773 SourceLocation ConstructorLParen,
1774 MultiExprArg ConstructorArgs,
1775 SourceLocation ConstructorRParen) {
Mike Stump1eb44332009-09-09 15:08:12 +00001776 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001777 PlacementLParen,
1778 move(PlacementArgs),
1779 PlacementRParen,
Douglas Gregor4bd40312010-07-13 15:54:32 +00001780 TypeIdParens,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00001781 AllocatedType,
1782 AllocatedTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00001783 ArraySize,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001784 ConstructorLParen,
1785 move(ConstructorArgs),
1786 ConstructorRParen);
1787 }
Mike Stump1eb44332009-09-09 15:08:12 +00001788
Douglas Gregorb98b1992009-08-11 05:31:07 +00001789 /// \brief Build a new C++ "delete" expression.
1790 ///
1791 /// By default, performs semantic analysis to build the new expression.
1792 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001793 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001794 bool IsGlobalDelete,
1795 bool IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001796 Expr *Operand) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001797 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCall9ae2f072010-08-23 23:25:46 +00001798 Operand);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001799 }
Mike Stump1eb44332009-09-09 15:08:12 +00001800
Douglas Gregorb98b1992009-08-11 05:31:07 +00001801 /// \brief Build a new unary type trait expression.
1802 ///
1803 /// By default, performs semantic analysis to build the new expression.
1804 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001805 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00001806 SourceLocation StartLoc,
1807 TypeSourceInfo *T,
1808 SourceLocation RParenLoc) {
1809 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001810 }
1811
Francois Pichet6ad6f282010-12-07 00:08:36 +00001812 /// \brief Build a new binary type trait expression.
1813 ///
1814 /// By default, performs semantic analysis to build the new expression.
1815 /// Subclasses may override this routine to provide different behavior.
1816 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1817 SourceLocation StartLoc,
1818 TypeSourceInfo *LhsT,
1819 TypeSourceInfo *RhsT,
1820 SourceLocation RParenLoc) {
1821 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1822 }
1823
Mike Stump1eb44332009-09-09 15:08:12 +00001824 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregorb98b1992009-08-11 05:31:07 +00001825 /// expression.
1826 ///
1827 /// By default, performs semantic analysis to build the new expression.
1828 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001829 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001830 SourceRange QualifierRange,
Abramo Bagnara25777432010-08-11 22:01:17 +00001831 const DeclarationNameInfo &NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001832 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001833 CXXScopeSpec SS;
1834 SS.setRange(QualifierRange);
1835 SS.setScopeRep(NNS);
John McCallf7a1a742009-11-24 19:00:30 +00001836
1837 if (TemplateArgs)
Abramo Bagnara25777432010-08-11 22:01:17 +00001838 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00001839 *TemplateArgs);
1840
Abramo Bagnara25777432010-08-11 22:01:17 +00001841 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001842 }
1843
1844 /// \brief Build a new template-id expression.
1845 ///
1846 /// By default, performs semantic analysis to build the new expression.
1847 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001848 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCallf7a1a742009-11-24 19:00:30 +00001849 LookupResult &R,
1850 bool RequiresADL,
John McCalld5532b62009-11-23 01:53:49 +00001851 const TemplateArgumentListInfo &TemplateArgs) {
John McCallf7a1a742009-11-24 19:00:30 +00001852 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001853 }
1854
1855 /// \brief Build a new object-construction expression.
1856 ///
1857 /// By default, performs semantic analysis to build the new expression.
1858 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001859 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001860 SourceLocation Loc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001861 CXXConstructorDecl *Constructor,
1862 bool IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001863 MultiExprArg Args,
1864 bool RequiresZeroInit,
Chandler Carruth428edaf2010-10-25 08:47:36 +00001865 CXXConstructExpr::ConstructionKind ConstructKind,
1866 SourceRange ParenRange) {
John McCallca0408f2010-08-23 06:44:23 +00001867 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Sean Huntc3021132010-05-05 15:23:54 +00001868 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001869 ConvertedArgs))
John McCallf312b1e2010-08-26 23:41:50 +00001870 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00001871
Douglas Gregor4411d2e2009-12-14 16:27:04 +00001872 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregor8c3e5542010-08-22 17:20:18 +00001873 move_arg(ConvertedArgs),
Chandler Carruth428edaf2010-10-25 08:47:36 +00001874 RequiresZeroInit, ConstructKind,
1875 ParenRange);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001876 }
1877
1878 /// \brief Build a new object-construction expression.
1879 ///
1880 /// By default, performs semantic analysis to build the new expression.
1881 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001882 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1883 SourceLocation LParenLoc,
1884 MultiExprArg Args,
1885 SourceLocation RParenLoc) {
1886 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001887 LParenLoc,
1888 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001889 RParenLoc);
1890 }
1891
1892 /// \brief Build a new object-construction expression.
1893 ///
1894 /// By default, performs semantic analysis to build the new expression.
1895 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorab6677e2010-09-08 00:15:04 +00001896 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1897 SourceLocation LParenLoc,
1898 MultiExprArg Args,
1899 SourceLocation RParenLoc) {
1900 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001901 LParenLoc,
1902 move(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00001903 RParenLoc);
1904 }
Mike Stump1eb44332009-09-09 15:08:12 +00001905
Douglas Gregorb98b1992009-08-11 05:31:07 +00001906 /// \brief Build a new member reference expression.
1907 ///
1908 /// By default, performs semantic analysis to build the new expression.
1909 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001910 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001911 QualType BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001912 bool IsArrow,
1913 SourceLocation OperatorLoc,
Douglas Gregora38c6872009-09-03 16:14:30 +00001914 NestedNameSpecifier *Qualifier,
1915 SourceRange QualifierRange,
John McCall129e2df2009-11-30 22:42:35 +00001916 NamedDecl *FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001917 const DeclarationNameInfo &MemberNameInfo,
John McCall129e2df2009-11-30 22:42:35 +00001918 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00001919 CXXScopeSpec SS;
Douglas Gregora38c6872009-09-03 16:14:30 +00001920 SS.setRange(QualifierRange);
1921 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001922
John McCall9ae2f072010-08-23 23:25:46 +00001923 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001924 OperatorLoc, IsArrow,
John McCall129e2df2009-11-30 22:42:35 +00001925 SS, FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00001926 MemberNameInfo,
1927 TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00001928 }
1929
John McCall129e2df2009-11-30 22:42:35 +00001930 /// \brief Build a new member reference expression.
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001931 ///
1932 /// By default, performs semantic analysis to build the new expression.
1933 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001934 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCallaa81e162009-12-01 22:10:20 +00001935 QualType BaseType,
John McCall129e2df2009-11-30 22:42:35 +00001936 SourceLocation OperatorLoc,
1937 bool IsArrow,
1938 NestedNameSpecifier *Qualifier,
1939 SourceRange QualifierRange,
John McCallc2233c52010-01-15 08:34:02 +00001940 NamedDecl *FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00001941 LookupResult &R,
1942 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001943 CXXScopeSpec SS;
1944 SS.setRange(QualifierRange);
1945 SS.setScopeRep(Qualifier);
Mike Stump1eb44332009-09-09 15:08:12 +00001946
John McCall9ae2f072010-08-23 23:25:46 +00001947 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCallaa81e162009-12-01 22:10:20 +00001948 OperatorLoc, IsArrow,
John McCallc2233c52010-01-15 08:34:02 +00001949 SS, FirstQualifierInScope,
1950 R, TemplateArgs);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00001951 }
Mike Stump1eb44332009-09-09 15:08:12 +00001952
Sebastian Redl2e156222010-09-10 20:55:43 +00001953 /// \brief Build a new noexcept expression.
1954 ///
1955 /// By default, performs semantic analysis to build the new expression.
1956 /// Subclasses may override this routine to provide different behavior.
1957 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1958 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1959 }
1960
Douglas Gregoree8aff02011-01-04 17:33:58 +00001961 /// \brief Build a new expression to compute the length of a parameter pack.
1962 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
1963 SourceLocation PackLoc,
1964 SourceLocation RParenLoc,
1965 unsigned Length) {
1966 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
1967 OperatorLoc, Pack, PackLoc,
1968 RParenLoc, Length);
1969 }
1970
Douglas Gregorb98b1992009-08-11 05:31:07 +00001971 /// \brief Build a new Objective-C @encode expression.
1972 ///
1973 /// By default, performs semantic analysis to build the new expression.
1974 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00001975 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregor81d34662010-04-20 15:39:42 +00001976 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001977 SourceLocation RParenLoc) {
Douglas Gregor81d34662010-04-20 15:39:42 +00001978 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00001979 RParenLoc));
Mike Stump1eb44332009-09-09 15:08:12 +00001980 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00001981
Douglas Gregor92e986e2010-04-22 16:44:27 +00001982 /// \brief Build a new Objective-C class message.
John McCall60d7b3a2010-08-24 06:29:42 +00001983 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001984 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001985 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001986 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00001987 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001988 MultiExprArg Args,
1989 SourceLocation RBracLoc) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00001990 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
1991 ReceiverTypeInfo->getType(),
1992 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00001993 Sel, Method, LBracLoc, SelectorLoc,
1994 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00001995 }
1996
1997 /// \brief Build a new Objective-C instance message.
John McCall60d7b3a2010-08-24 06:29:42 +00001998 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregor92e986e2010-04-22 16:44:27 +00001999 Selector Sel,
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002000 SourceLocation SelectorLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002001 ObjCMethodDecl *Method,
Sean Huntc3021132010-05-05 15:23:54 +00002002 SourceLocation LBracLoc,
Douglas Gregor92e986e2010-04-22 16:44:27 +00002003 MultiExprArg Args,
2004 SourceLocation RBracLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00002005 return SemaRef.BuildInstanceMessage(Receiver,
2006 Receiver->getType(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00002007 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00002008 Sel, Method, LBracLoc, SelectorLoc,
2009 RBracLoc, move(Args));
Douglas Gregor92e986e2010-04-22 16:44:27 +00002010 }
2011
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002012 /// \brief Build a new Objective-C ivar reference expression.
2013 ///
2014 /// By default, performs semantic analysis to build the new expression.
2015 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002016 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002017 SourceLocation IvarLoc,
2018 bool IsArrow, bool IsFreeIvar) {
2019 // FIXME: We lose track of the IsFreeIvar bit.
2020 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002021 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002022 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2023 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002024 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002025 /*FIME:*/IvarLoc,
John McCalld226f652010-08-21 09:40:31 +00002026 SS, 0,
John McCallad00b772010-06-16 08:42:20 +00002027 false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002028 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002029 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002030
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002031 if (Result.get())
2032 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002033
John McCall9ae2f072010-08-23 23:25:46 +00002034 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002035 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002036 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002037 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002038 /*TemplateArgs=*/0);
2039 }
Douglas Gregore3303542010-04-26 20:47:02 +00002040
2041 /// \brief Build a new Objective-C property reference expression.
2042 ///
2043 /// By default, performs semantic analysis to build the new expression.
2044 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002045 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregore3303542010-04-26 20:47:02 +00002046 ObjCPropertyDecl *Property,
2047 SourceLocation PropertyLoc) {
2048 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002049 Expr *Base = BaseArg;
Douglas Gregore3303542010-04-26 20:47:02 +00002050 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2051 Sema::LookupMemberName);
2052 bool IsArrow = false;
John McCall60d7b3a2010-08-24 06:29:42 +00002053 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregore3303542010-04-26 20:47:02 +00002054 /*FIME:*/PropertyLoc,
John McCalld226f652010-08-21 09:40:31 +00002055 SS, 0, false);
Douglas Gregore3303542010-04-26 20:47:02 +00002056 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002057 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002058
Douglas Gregore3303542010-04-26 20:47:02 +00002059 if (Result.get())
2060 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002061
John McCall9ae2f072010-08-23 23:25:46 +00002062 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002063 /*FIXME:*/PropertyLoc, IsArrow,
2064 SS,
Douglas Gregore3303542010-04-26 20:47:02 +00002065 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002066 R,
Douglas Gregore3303542010-04-26 20:47:02 +00002067 /*TemplateArgs=*/0);
2068 }
Sean Huntc3021132010-05-05 15:23:54 +00002069
John McCall12f78a62010-12-02 01:19:52 +00002070 /// \brief Build a new Objective-C property reference expression.
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002071 ///
2072 /// By default, performs semantic analysis to build the new expression.
John McCall12f78a62010-12-02 01:19:52 +00002073 /// Subclasses may override this routine to provide different behavior.
2074 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2075 ObjCMethodDecl *Getter,
2076 ObjCMethodDecl *Setter,
2077 SourceLocation PropertyLoc) {
2078 // Since these expressions can only be value-dependent, we do not
2079 // need to perform semantic analysis again.
2080 return Owned(
2081 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2082 VK_LValue, OK_ObjCProperty,
2083 PropertyLoc, Base));
Douglas Gregor9cbfdd22010-04-26 21:04:54 +00002084 }
2085
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002086 /// \brief Build a new Objective-C "isa" expression.
2087 ///
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 RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002091 bool IsArrow) {
2092 CXXScopeSpec SS;
John McCall9ae2f072010-08-23 23:25:46 +00002093 Expr *Base = BaseArg;
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002094 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2095 Sema::LookupMemberName);
John McCall60d7b3a2010-08-24 06:29:42 +00002096 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002097 /*FIME:*/IsaLoc,
John McCalld226f652010-08-21 09:40:31 +00002098 SS, 0, false);
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002099 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002100 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00002101
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002102 if (Result.get())
2103 return move(Result);
Sean Huntc3021132010-05-05 15:23:54 +00002104
John McCall9ae2f072010-08-23 23:25:46 +00002105 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Sean Huntc3021132010-05-05 15:23:54 +00002106 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002107 /*FirstQualifierInScope=*/0,
Sean Huntc3021132010-05-05 15:23:54 +00002108 R,
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00002109 /*TemplateArgs=*/0);
2110 }
Sean Huntc3021132010-05-05 15:23:54 +00002111
Douglas Gregorb98b1992009-08-11 05:31:07 +00002112 /// \brief Build a new shuffle vector expression.
2113 ///
2114 /// By default, performs semantic analysis to build the new expression.
2115 /// Subclasses may override this routine to provide different behavior.
John McCall60d7b3a2010-08-24 06:29:42 +00002116 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCallf89e55a2010-11-18 06:31:45 +00002117 MultiExprArg SubExprs,
2118 SourceLocation RParenLoc) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002119 // Find the declaration for __builtin_shufflevector
Mike Stump1eb44332009-09-09 15:08:12 +00002120 const IdentifierInfo &Name
Douglas Gregorb98b1992009-08-11 05:31:07 +00002121 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2122 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2123 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2124 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump1eb44332009-09-09 15:08:12 +00002125
Douglas Gregorb98b1992009-08-11 05:31:07 +00002126 // Build a reference to the __builtin_shufflevector builtin
2127 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump1eb44332009-09-09 15:08:12 +00002128 Expr *Callee
Douglas Gregorb98b1992009-08-11 05:31:07 +00002129 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCallf89e55a2010-11-18 06:31:45 +00002130 VK_LValue, BuiltinLoc);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002131 SemaRef.UsualUnaryConversions(Callee);
Mike Stump1eb44332009-09-09 15:08:12 +00002132
2133 // Build the CallExpr
Douglas Gregorb98b1992009-08-11 05:31:07 +00002134 unsigned NumSubExprs = SubExprs.size();
2135 Expr **Subs = (Expr **)SubExprs.release();
2136 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2137 Subs, NumSubExprs,
Douglas Gregor5291c3c2010-07-13 08:18:22 +00002138 Builtin->getCallResultType(),
John McCallf89e55a2010-11-18 06:31:45 +00002139 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregorb98b1992009-08-11 05:31:07 +00002140 RParenLoc);
John McCall60d7b3a2010-08-24 06:29:42 +00002141 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump1eb44332009-09-09 15:08:12 +00002142
Douglas Gregorb98b1992009-08-11 05:31:07 +00002143 // Type-check the __builtin_shufflevector expression.
John McCall60d7b3a2010-08-24 06:29:42 +00002144 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002145 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002146 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00002147
Douglas Gregorb98b1992009-08-11 05:31:07 +00002148 OwnedCall.release();
Mike Stump1eb44332009-09-09 15:08:12 +00002149 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00002150 }
John McCall43fed0d2010-11-12 08:19:04 +00002151
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002152 /// \brief Build a new template argument pack expansion.
2153 ///
2154 /// By default, performs semantic analysis to build a new pack expansion
2155 /// for a template argument. Subclasses may override this routine to provide
2156 /// different behavior.
2157 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2158 SourceLocation EllipsisLoc) {
2159 switch (Pattern.getArgument().getKind()) {
Douglas Gregor7a21fd42011-01-03 21:37:45 +00002160 case TemplateArgument::Expression: {
2161 ExprResult Result
2162 = getSema().ActOnPackExpansion(Pattern.getSourceExpression(),
2163 EllipsisLoc);
2164 if (Result.isInvalid())
2165 return TemplateArgumentLoc();
2166
2167 return TemplateArgumentLoc(Result.get(), Result.get());
2168 }
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002169
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002170 case TemplateArgument::Template:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002171 return TemplateArgumentLoc(TemplateArgument(
2172 Pattern.getArgument().getAsTemplate(),
2173 true),
2174 Pattern.getTemplateQualifierRange(),
2175 Pattern.getTemplateNameLoc(),
2176 EllipsisLoc);
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002177
2178 case TemplateArgument::Null:
2179 case TemplateArgument::Integral:
2180 case TemplateArgument::Declaration:
2181 case TemplateArgument::Pack:
Douglas Gregora7fc9012011-01-05 18:58:31 +00002182 case TemplateArgument::TemplateExpansion:
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002183 llvm_unreachable("Pack expansion pattern has no parameter packs");
2184
2185 case TemplateArgument::Type:
2186 if (TypeSourceInfo *Expansion
2187 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2188 EllipsisLoc))
2189 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2190 Expansion);
2191 break;
2192 }
2193
2194 return TemplateArgumentLoc();
2195 }
2196
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002197 /// \brief Build a new expression pack expansion.
2198 ///
2199 /// By default, performs semantic analysis to build a new pack expansion
2200 /// for an expression. Subclasses may override this routine to provide
2201 /// different behavior.
2202 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc) {
2203 return getSema().ActOnPackExpansion(Pattern, EllipsisLoc);
2204 }
2205
John McCall43fed0d2010-11-12 08:19:04 +00002206private:
2207 QualType TransformTypeInObjectScope(QualType T,
2208 QualType ObjectType,
2209 NamedDecl *FirstQualifierInScope,
2210 NestedNameSpecifier *Prefix);
2211
2212 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2213 QualType ObjectType,
2214 NamedDecl *FirstQualifierInScope,
2215 NestedNameSpecifier *Prefix);
Douglas Gregor577f75a2009-08-04 16:50:30 +00002216};
Douglas Gregorb98b1992009-08-11 05:31:07 +00002217
Douglas Gregor43959a92009-08-20 07:17:43 +00002218template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002219StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00002220 if (!S)
2221 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00002222
Douglas Gregor43959a92009-08-20 07:17:43 +00002223 switch (S->getStmtClass()) {
2224 case Stmt::NoStmtClass: break;
Mike Stump1eb44332009-09-09 15:08:12 +00002225
Douglas Gregor43959a92009-08-20 07:17:43 +00002226 // Transform individual statement nodes
2227#define STMT(Node, Parent) \
2228 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2229#define EXPR(Node, Parent)
Sean Hunt4bfe1962010-05-05 15:24:00 +00002230#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002231
Douglas Gregor43959a92009-08-20 07:17:43 +00002232 // Transform expressions by calling TransformExpr.
2233#define STMT(Node, Parent)
Sean Hunt7381d5c2010-05-18 06:22:21 +00002234#define ABSTRACT_STMT(Stmt)
Douglas Gregor43959a92009-08-20 07:17:43 +00002235#define EXPR(Node, Parent) case Stmt::Node##Class:
Sean Hunt4bfe1962010-05-05 15:24:00 +00002236#include "clang/AST/StmtNodes.inc"
Douglas Gregor43959a92009-08-20 07:17:43 +00002237 {
John McCall60d7b3a2010-08-24 06:29:42 +00002238 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregor43959a92009-08-20 07:17:43 +00002239 if (E.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00002240 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00002241
John McCall9ae2f072010-08-23 23:25:46 +00002242 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregor43959a92009-08-20 07:17:43 +00002243 }
Mike Stump1eb44332009-09-09 15:08:12 +00002244 }
2245
John McCall3fa5cae2010-10-26 07:05:15 +00002246 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00002247}
Mike Stump1eb44332009-09-09 15:08:12 +00002248
2249
Douglas Gregor670444e2009-08-04 22:27:00 +00002250template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00002251ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00002252 if (!E)
2253 return SemaRef.Owned(E);
2254
2255 switch (E->getStmtClass()) {
2256 case Stmt::NoStmtClass: break;
2257#define STMT(Node, Parent) case Stmt::Node##Class: break;
Sean Hunt7381d5c2010-05-18 06:22:21 +00002258#define ABSTRACT_STMT(Stmt)
Douglas Gregorb98b1992009-08-11 05:31:07 +00002259#define EXPR(Node, Parent) \
John McCall454feb92009-12-08 09:21:05 +00002260 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Sean Hunt4bfe1962010-05-05 15:24:00 +00002261#include "clang/AST/StmtNodes.inc"
Mike Stump1eb44332009-09-09 15:08:12 +00002262 }
2263
John McCall3fa5cae2010-10-26 07:05:15 +00002264 return SemaRef.Owned(E);
Douglas Gregor657c1ac2009-08-06 22:17:10 +00002265}
2266
2267template<typename Derived>
Douglas Gregoraa165f82011-01-03 19:04:46 +00002268bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2269 unsigned NumInputs,
2270 bool IsCall,
2271 llvm::SmallVectorImpl<Expr *> &Outputs,
2272 bool *ArgChanged) {
2273 for (unsigned I = 0; I != NumInputs; ++I) {
2274 // If requested, drop call arguments that need to be dropped.
2275 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2276 if (ArgChanged)
2277 *ArgChanged = true;
2278
2279 break;
2280 }
2281
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002282 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2283 Expr *Pattern = Expansion->getPattern();
2284
2285 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2286 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2287 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2288
2289 // Determine whether the set of unexpanded parameter packs can and should
2290 // be expanded.
2291 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002292 bool RetainExpansion = false;
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002293 unsigned NumExpansions = 0;
2294 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2295 Pattern->getSourceRange(),
2296 Unexpanded.data(),
2297 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002298 Expand, RetainExpansion,
2299 NumExpansions))
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002300 return true;
2301
2302 if (!Expand) {
2303 // The transform has determined that we should perform a simple
2304 // transformation on the pack expansion, producing another pack
2305 // expansion.
2306 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2307 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2308 if (OutPattern.isInvalid())
2309 return true;
2310
2311 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
2312 Expansion->getEllipsisLoc());
2313 if (Out.isInvalid())
2314 return true;
2315
2316 if (ArgChanged)
2317 *ArgChanged = true;
2318 Outputs.push_back(Out.get());
2319 continue;
2320 }
2321
2322 // The transform has determined that we should perform an elementwise
2323 // expansion of the pattern. Do so.
2324 for (unsigned I = 0; I != NumExpansions; ++I) {
2325 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2326 ExprResult Out = getDerived().TransformExpr(Pattern);
2327 if (Out.isInvalid())
2328 return true;
2329
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002330 if (Out.get()->containsUnexpandedParameterPack()) {
2331 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc());
2332 if (Out.isInvalid())
2333 return true;
2334 }
2335
Douglas Gregordcaa1ca2011-01-03 19:31:53 +00002336 if (ArgChanged)
2337 *ArgChanged = true;
2338 Outputs.push_back(Out.get());
2339 }
2340
2341 continue;
2342 }
2343
Douglas Gregoraa165f82011-01-03 19:04:46 +00002344 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2345 if (Result.isInvalid())
2346 return true;
2347
2348 if (Result.get() != Inputs[I] && ArgChanged)
2349 *ArgChanged = true;
2350
2351 Outputs.push_back(Result.get());
2352 }
2353
2354 return false;
2355}
2356
2357template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002358NestedNameSpecifier *
2359TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002360 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002361 QualType ObjectType,
2362 NamedDecl *FirstQualifierInScope) {
John McCall43fed0d2010-11-12 08:19:04 +00002363 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump1eb44332009-09-09 15:08:12 +00002364
Douglas Gregor43959a92009-08-20 07:17:43 +00002365 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002366 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002367 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002368 ObjectType,
2369 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002370 if (!Prefix)
2371 return 0;
2372 }
Mike Stump1eb44332009-09-09 15:08:12 +00002373
Douglas Gregordcee1a12009-08-06 05:28:30 +00002374 switch (NNS->getKind()) {
2375 case NestedNameSpecifier::Identifier:
John McCall43fed0d2010-11-12 08:19:04 +00002376 if (Prefix) {
2377 // The object type and qualifier-in-scope really apply to the
2378 // leftmost entity.
2379 ObjectType = QualType();
2380 FirstQualifierInScope = 0;
2381 }
2382
Mike Stump1eb44332009-09-09 15:08:12 +00002383 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002384 "Identifier nested-name-specifier with no prefix or object type");
2385 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2386 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002387 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002388
2389 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002390 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002391 ObjectType,
2392 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002393
Douglas Gregordcee1a12009-08-06 05:28:30 +00002394 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002395 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002396 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002397 getDerived().TransformDecl(Range.getBegin(),
2398 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002399 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002400 Prefix == NNS->getPrefix() &&
2401 NS == NNS->getAsNamespace())
2402 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002403
Douglas Gregordcee1a12009-08-06 05:28:30 +00002404 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2405 }
Mike Stump1eb44332009-09-09 15:08:12 +00002406
Douglas Gregordcee1a12009-08-06 05:28:30 +00002407 case NestedNameSpecifier::Global:
2408 // There is no meaningful transformation that one could perform on the
2409 // global scope.
2410 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002411
Douglas Gregordcee1a12009-08-06 05:28:30 +00002412 case NestedNameSpecifier::TypeSpecWithTemplate:
2413 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002414 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall43fed0d2010-11-12 08:19:04 +00002415 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2416 ObjectType,
2417 FirstQualifierInScope,
2418 Prefix);
Douglas Gregord1067e52009-08-06 06:41:21 +00002419 if (T.isNull())
2420 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002421
Douglas Gregordcee1a12009-08-06 05:28:30 +00002422 if (!getDerived().AlwaysRebuild() &&
2423 Prefix == NNS->getPrefix() &&
2424 T == QualType(NNS->getAsType(), 0))
2425 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002426
2427 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2428 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002429 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002430 }
2431 }
Mike Stump1eb44332009-09-09 15:08:12 +00002432
Douglas Gregordcee1a12009-08-06 05:28:30 +00002433 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002434 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002435}
2436
2437template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002438DeclarationNameInfo
2439TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002440::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002441 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002442 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002443 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002444
2445 switch (Name.getNameKind()) {
2446 case DeclarationName::Identifier:
2447 case DeclarationName::ObjCZeroArgSelector:
2448 case DeclarationName::ObjCOneArgSelector:
2449 case DeclarationName::ObjCMultiArgSelector:
2450 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002451 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002452 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002453 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002454
Douglas Gregor81499bb2009-09-03 22:13:48 +00002455 case DeclarationName::CXXConstructorName:
2456 case DeclarationName::CXXDestructorName:
2457 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002458 TypeSourceInfo *NewTInfo;
2459 CanQualType NewCanTy;
2460 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002461 NewTInfo = getDerived().TransformType(OldTInfo);
2462 if (!NewTInfo)
2463 return DeclarationNameInfo();
2464 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002465 }
2466 else {
2467 NewTInfo = 0;
2468 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002469 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002470 if (NewT.isNull())
2471 return DeclarationNameInfo();
2472 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2473 }
Mike Stump1eb44332009-09-09 15:08:12 +00002474
Abramo Bagnara25777432010-08-11 22:01:17 +00002475 DeclarationName NewName
2476 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2477 NewCanTy);
2478 DeclarationNameInfo NewNameInfo(NameInfo);
2479 NewNameInfo.setName(NewName);
2480 NewNameInfo.setNamedTypeInfo(NewTInfo);
2481 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002482 }
Mike Stump1eb44332009-09-09 15:08:12 +00002483 }
2484
Abramo Bagnara25777432010-08-11 22:01:17 +00002485 assert(0 && "Unknown name kind.");
2486 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002487}
2488
2489template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002490TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002491TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +00002492 QualType ObjectType,
2493 NamedDecl *FirstQualifierInScope) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002494 SourceLocation Loc = getDerived().getBaseLocation();
2495
Douglas Gregord1067e52009-08-06 06:41:21 +00002496 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002497 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002498 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002499 /*FIXME*/ SourceRange(Loc),
2500 ObjectType,
2501 FirstQualifierInScope);
Douglas Gregord1067e52009-08-06 06:41:21 +00002502 if (!NNS)
2503 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002504
Douglas Gregord1067e52009-08-06 06:41:21 +00002505 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002506 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002507 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002508 if (!TransTemplate)
2509 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002510
Douglas Gregord1067e52009-08-06 06:41:21 +00002511 if (!getDerived().AlwaysRebuild() &&
2512 NNS == QTN->getQualifier() &&
2513 TransTemplate == Template)
2514 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002515
Douglas Gregord1067e52009-08-06 06:41:21 +00002516 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2517 TransTemplate);
2518 }
Mike Stump1eb44332009-09-09 15:08:12 +00002519
John McCallf7a1a742009-11-24 19:00:30 +00002520 // These should be getting filtered out before they make it into the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002521 llvm_unreachable("overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002522 }
Mike Stump1eb44332009-09-09 15:08:12 +00002523
Douglas Gregord1067e52009-08-06 06:41:21 +00002524 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall43fed0d2010-11-12 08:19:04 +00002525 NestedNameSpecifier *NNS = DTN->getQualifier();
2526 if (NNS) {
2527 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2528 /*FIXME:*/SourceRange(Loc),
2529 ObjectType,
2530 FirstQualifierInScope);
2531 if (!NNS) return TemplateName();
2532
2533 // These apply to the scope specifier, not the template.
2534 ObjectType = QualType();
2535 FirstQualifierInScope = 0;
2536 }
Mike Stump1eb44332009-09-09 15:08:12 +00002537
Douglas Gregord1067e52009-08-06 06:41:21 +00002538 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002539 NNS == DTN->getQualifier() &&
2540 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002541 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002542
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002543 if (DTN->isIdentifier()) {
2544 // FIXME: Bad range
2545 SourceRange QualifierRange(getDerived().getBaseLocation());
2546 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2547 *DTN->getIdentifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002548 ObjectType,
2549 FirstQualifierInScope);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002550 }
Sean Huntc3021132010-05-05 15:23:54 +00002551
2552 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002553 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002554 }
Mike Stump1eb44332009-09-09 15:08:12 +00002555
Douglas Gregord1067e52009-08-06 06:41:21 +00002556 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002557 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002558 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002559 if (!TransTemplate)
2560 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002561
Douglas Gregord1067e52009-08-06 06:41:21 +00002562 if (!getDerived().AlwaysRebuild() &&
2563 TransTemplate == Template)
2564 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002565
Douglas Gregord1067e52009-08-06 06:41:21 +00002566 return TemplateName(TransTemplate);
2567 }
Mike Stump1eb44332009-09-09 15:08:12 +00002568
John McCallf7a1a742009-11-24 19:00:30 +00002569 // These should be getting filtered out before they reach the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002570 llvm_unreachable("overloaded function decl survived to here");
John McCallf7a1a742009-11-24 19:00:30 +00002571 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002572}
2573
2574template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002575void TreeTransform<Derived>::InventTemplateArgumentLoc(
2576 const TemplateArgument &Arg,
2577 TemplateArgumentLoc &Output) {
2578 SourceLocation Loc = getDerived().getBaseLocation();
2579 switch (Arg.getKind()) {
2580 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002581 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002582 break;
2583
2584 case TemplateArgument::Type:
2585 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002586 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002587
John McCall833ca992009-10-29 08:12:44 +00002588 break;
2589
Douglas Gregor788cd062009-11-11 01:00:40 +00002590 case TemplateArgument::Template:
2591 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2592 break;
Douglas Gregora7fc9012011-01-05 18:58:31 +00002593
2594 case TemplateArgument::TemplateExpansion:
2595 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2596 break;
2597
John McCall833ca992009-10-29 08:12:44 +00002598 case TemplateArgument::Expression:
2599 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2600 break;
2601
2602 case TemplateArgument::Declaration:
2603 case TemplateArgument::Integral:
2604 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002605 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002606 break;
2607 }
2608}
2609
2610template<typename Derived>
2611bool TreeTransform<Derived>::TransformTemplateArgument(
2612 const TemplateArgumentLoc &Input,
2613 TemplateArgumentLoc &Output) {
2614 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002615 switch (Arg.getKind()) {
2616 case TemplateArgument::Null:
2617 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002618 Output = Input;
2619 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002620
Douglas Gregor670444e2009-08-04 22:27:00 +00002621 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002622 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002623 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002624 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002625
2626 DI = getDerived().TransformType(DI);
2627 if (!DI) return true;
2628
2629 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2630 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002631 }
Mike Stump1eb44332009-09-09 15:08:12 +00002632
Douglas Gregor670444e2009-08-04 22:27:00 +00002633 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002634 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002635 DeclarationName Name;
2636 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2637 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002638 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002639 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002640 if (!D) return true;
2641
John McCall828bff22009-10-29 18:45:58 +00002642 Expr *SourceExpr = Input.getSourceDeclExpression();
2643 if (SourceExpr) {
2644 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002645 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002646 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002647 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002648 }
2649
2650 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002651 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002652 }
Mike Stump1eb44332009-09-09 15:08:12 +00002653
Douglas Gregor788cd062009-11-11 01:00:40 +00002654 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002655 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002656 TemplateName Template
2657 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2658 if (Template.isNull())
2659 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002660
Douglas Gregor788cd062009-11-11 01:00:40 +00002661 Output = TemplateArgumentLoc(TemplateArgument(Template),
2662 Input.getTemplateQualifierRange(),
2663 Input.getTemplateNameLoc());
2664 return false;
2665 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002666
2667 case TemplateArgument::TemplateExpansion:
2668 llvm_unreachable("Caller should expand pack expansions");
2669
Douglas Gregor670444e2009-08-04 22:27:00 +00002670 case TemplateArgument::Expression: {
2671 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002672 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002673 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002674
John McCall833ca992009-10-29 08:12:44 +00002675 Expr *InputExpr = Input.getSourceExpression();
2676 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2677
John McCall60d7b3a2010-08-24 06:29:42 +00002678 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002679 = getDerived().TransformExpr(InputExpr);
2680 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002681 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002682 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002683 }
Mike Stump1eb44332009-09-09 15:08:12 +00002684
Douglas Gregor670444e2009-08-04 22:27:00 +00002685 case TemplateArgument::Pack: {
2686 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2687 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002688 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002689 AEnd = Arg.pack_end();
2690 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002691
John McCall833ca992009-10-29 08:12:44 +00002692 // FIXME: preserve source information here when we start
2693 // caring about parameter packs.
2694
John McCall828bff22009-10-29 18:45:58 +00002695 TemplateArgumentLoc InputArg;
2696 TemplateArgumentLoc OutputArg;
2697 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2698 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002699 return true;
2700
John McCall828bff22009-10-29 18:45:58 +00002701 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002702 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002703
2704 TemplateArgument *TransformedArgsPtr
2705 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2706 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2707 TransformedArgsPtr);
2708 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2709 TransformedArgs.size()),
2710 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002711 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002712 }
2713 }
Mike Stump1eb44332009-09-09 15:08:12 +00002714
Douglas Gregor670444e2009-08-04 22:27:00 +00002715 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002716 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002717}
2718
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002719/// \brief Iterator adaptor that invents template argument location information
2720/// for each of the template arguments in its underlying iterator.
2721template<typename Derived, typename InputIterator>
2722class TemplateArgumentLocInventIterator {
2723 TreeTransform<Derived> &Self;
2724 InputIterator Iter;
2725
2726public:
2727 typedef TemplateArgumentLoc value_type;
2728 typedef TemplateArgumentLoc reference;
2729 typedef typename std::iterator_traits<InputIterator>::difference_type
2730 difference_type;
2731 typedef std::input_iterator_tag iterator_category;
2732
2733 class pointer {
2734 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002735
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002736 public:
2737 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2738
2739 const TemplateArgumentLoc *operator->() const { return &Arg; }
2740 };
2741
2742 TemplateArgumentLocInventIterator() { }
2743
2744 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2745 InputIterator Iter)
2746 : Self(Self), Iter(Iter) { }
2747
2748 TemplateArgumentLocInventIterator &operator++() {
2749 ++Iter;
2750 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002751 }
2752
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002753 TemplateArgumentLocInventIterator operator++(int) {
2754 TemplateArgumentLocInventIterator Old(*this);
2755 ++(*this);
2756 return Old;
2757 }
2758
2759 reference operator*() const {
2760 TemplateArgumentLoc Result;
2761 Self.InventTemplateArgumentLoc(*Iter, Result);
2762 return Result;
2763 }
2764
2765 pointer operator->() const { return pointer(**this); }
2766
2767 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2768 const TemplateArgumentLocInventIterator &Y) {
2769 return X.Iter == Y.Iter;
2770 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002771
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002772 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2773 const TemplateArgumentLocInventIterator &Y) {
2774 return X.Iter != Y.Iter;
2775 }
2776};
2777
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002778template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002779template<typename InputIterator>
2780bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2781 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002782 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002783 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002784 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002785 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002786
2787 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2788 // Unpack argument packs, which we translate them into separate
2789 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002790 // FIXME: We could do much better if we could guarantee that the
2791 // TemplateArgumentLocInfo for the pack expansion would be usable for
2792 // all of the template arguments in the argument pack.
2793 typedef TemplateArgumentLocInventIterator<Derived,
2794 TemplateArgument::pack_iterator>
2795 PackLocIterator;
2796 if (TransformTemplateArguments(PackLocIterator(*this,
2797 In.getArgument().pack_begin()),
2798 PackLocIterator(*this,
2799 In.getArgument().pack_end()),
2800 Outputs))
2801 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002802
2803 continue;
2804 }
2805
2806 if (In.getArgument().isPackExpansion()) {
2807 // We have a pack expansion, for which we will be substituting into
2808 // the pattern.
2809 SourceLocation Ellipsis;
2810 TemplateArgumentLoc Pattern
2811 = In.getPackExpansionPattern(Ellipsis, getSema().Context);
2812
2813 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2814 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2815 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2816
2817 // Determine whether the set of unexpanded parameter packs can and should
2818 // be expanded.
2819 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002820 bool RetainExpansion = false;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002821 unsigned NumExpansions = 0;
2822 if (getDerived().TryExpandParameterPacks(Ellipsis,
2823 Pattern.getSourceRange(),
2824 Unexpanded.data(),
2825 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002826 Expand,
2827 RetainExpansion,
2828 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002829 return true;
2830
2831 if (!Expand) {
2832 // The transform has determined that we should perform a simple
2833 // transformation on the pack expansion, producing another pack
2834 // expansion.
2835 TemplateArgumentLoc OutPattern;
2836 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2837 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2838 return true;
2839
2840 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis);
2841 if (Out.getArgument().isNull())
2842 return true;
2843
2844 Outputs.addArgument(Out);
2845 continue;
2846 }
2847
2848 // The transform has determined that we should perform an elementwise
2849 // expansion of the pattern. Do so.
2850 for (unsigned I = 0; I != NumExpansions; ++I) {
2851 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2852
2853 if (getDerived().TransformTemplateArgument(Pattern, Out))
2854 return true;
2855
Douglas Gregor77d6bb92011-01-11 22:21:24 +00002856 if (Out.getArgument().containsUnexpandedParameterPack()) {
2857 Out = getDerived().RebuildPackExpansion(Out, Ellipsis);
2858 if (Out.getArgument().isNull())
2859 return true;
2860 }
2861
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002862 Outputs.addArgument(Out);
2863 }
2864
Douglas Gregor3cae5c92011-01-10 20:53:55 +00002865 // If we're supposed to retain a pack expansion, do so by temporarily
2866 // forgetting the partially-substituted parameter pack.
2867 if (RetainExpansion) {
2868 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2869
2870 if (getDerived().TransformTemplateArgument(Pattern, Out))
2871 return true;
2872
2873 Out = getDerived().RebuildPackExpansion(Out, Ellipsis);
2874 if (Out.getArgument().isNull())
2875 return true;
2876
2877 Outputs.addArgument(Out);
2878 }
Douglas Gregord3731192011-01-10 07:32:04 +00002879
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002880 continue;
2881 }
2882
2883 // The simple case:
2884 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002885 return true;
2886
2887 Outputs.addArgument(Out);
2888 }
2889
2890 return false;
2891
2892}
2893
Douglas Gregor577f75a2009-08-04 16:50:30 +00002894//===----------------------------------------------------------------------===//
2895// Type transformation
2896//===----------------------------------------------------------------------===//
2897
2898template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002899QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002900 if (getDerived().AlreadyTransformed(T))
2901 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002902
John McCalla2becad2009-10-21 00:40:46 +00002903 // Temporary workaround. All of these transformations should
2904 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002905 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002906 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002907
John McCall43fed0d2010-11-12 08:19:04 +00002908 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002909
John McCalla2becad2009-10-21 00:40:46 +00002910 if (!NewDI)
2911 return QualType();
2912
2913 return NewDI->getType();
2914}
2915
2916template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002917TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002918 if (getDerived().AlreadyTransformed(DI->getType()))
2919 return DI;
2920
2921 TypeLocBuilder TLB;
2922
2923 TypeLoc TL = DI->getTypeLoc();
2924 TLB.reserve(TL.getFullDataSize());
2925
John McCall43fed0d2010-11-12 08:19:04 +00002926 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00002927 if (Result.isNull())
2928 return 0;
2929
John McCalla93c9342009-12-07 02:54:59 +00002930 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002931}
2932
2933template<typename Derived>
2934QualType
John McCall43fed0d2010-11-12 08:19:04 +00002935TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00002936 switch (T.getTypeLocClass()) {
2937#define ABSTRACT_TYPELOC(CLASS, PARENT)
2938#define TYPELOC(CLASS, PARENT) \
2939 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00002940 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00002941#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002942 }
Mike Stump1eb44332009-09-09 15:08:12 +00002943
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002944 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002945 return QualType();
2946}
2947
2948/// FIXME: By default, this routine adds type qualifiers only to types
2949/// that can have qualifiers, and silently suppresses those qualifiers
2950/// that are not permitted (e.g., qualifiers on reference or function
2951/// types). This is the right thing for template instantiation, but
2952/// probably not for other clients.
2953template<typename Derived>
2954QualType
2955TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002956 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002957 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002958
John McCall43fed0d2010-11-12 08:19:04 +00002959 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00002960 if (Result.isNull())
2961 return QualType();
2962
2963 // Silently suppress qualifiers if the result type can't be qualified.
2964 // FIXME: this is the right thing for template instantiation, but
2965 // probably not for other clients.
2966 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002967 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002968
John McCall28654742010-06-05 06:41:15 +00002969 if (!Quals.empty()) {
2970 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2971 TLB.push<QualifiedTypeLoc>(Result);
2972 // No location information to preserve.
2973 }
John McCalla2becad2009-10-21 00:40:46 +00002974
2975 return Result;
2976}
2977
John McCall43fed0d2010-11-12 08:19:04 +00002978/// \brief Transforms a type that was written in a scope specifier,
2979/// given an object type, the results of unqualified lookup, and
2980/// an already-instantiated prefix.
2981///
2982/// The object type is provided iff the scope specifier qualifies the
2983/// member of a dependent member-access expression. The prefix is
2984/// provided iff the the scope specifier in which this appears has a
2985/// prefix.
2986///
2987/// This is private to TreeTransform.
2988template<typename Derived>
2989QualType
2990TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2991 QualType ObjectType,
2992 NamedDecl *UnqualLookup,
2993 NestedNameSpecifier *Prefix) {
2994 if (getDerived().AlreadyTransformed(T))
2995 return T;
2996
2997 TypeSourceInfo *TSI =
2998 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2999
3000 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3001 UnqualLookup, Prefix);
3002 if (!TSI) return QualType();
3003 return TSI->getType();
3004}
3005
3006template<typename Derived>
3007TypeSourceInfo *
3008TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3009 QualType ObjectType,
3010 NamedDecl *UnqualLookup,
3011 NestedNameSpecifier *Prefix) {
3012 // TODO: in some cases, we might be some verification to do here.
3013 if (ObjectType.isNull())
3014 return getDerived().TransformType(TSI);
3015
3016 QualType T = TSI->getType();
3017 if (getDerived().AlreadyTransformed(T))
3018 return TSI;
3019
3020 TypeLocBuilder TLB;
3021 QualType Result;
3022
3023 if (isa<TemplateSpecializationType>(T)) {
3024 TemplateSpecializationTypeLoc TL
3025 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3026
3027 TemplateName Template =
3028 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3029 ObjectType, UnqualLookup);
3030 if (Template.isNull()) return 0;
3031
3032 Result = getDerived()
3033 .TransformTemplateSpecializationType(TLB, TL, Template);
3034 } else if (isa<DependentTemplateSpecializationType>(T)) {
3035 DependentTemplateSpecializationTypeLoc TL
3036 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3037
3038 Result = getDerived()
3039 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3040 } else {
3041 // Nothing special needs to be done for these.
3042 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3043 }
3044
3045 if (Result.isNull()) return 0;
3046 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3047}
3048
John McCalla2becad2009-10-21 00:40:46 +00003049template <class TyLoc> static inline
3050QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3051 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3052 NewT.setNameLoc(T.getNameLoc());
3053 return T.getType();
3054}
3055
John McCalla2becad2009-10-21 00:40:46 +00003056template<typename Derived>
3057QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003058 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003059 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3060 NewT.setBuiltinLoc(T.getBuiltinLoc());
3061 if (T.needsExtraLocalData())
3062 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3063 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003064}
Mike Stump1eb44332009-09-09 15:08:12 +00003065
Douglas Gregor577f75a2009-08-04 16:50:30 +00003066template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003067QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003068 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003069 // FIXME: recurse?
3070 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003071}
Mike Stump1eb44332009-09-09 15:08:12 +00003072
Douglas Gregor577f75a2009-08-04 16:50:30 +00003073template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003074QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003075 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003076 QualType PointeeType
3077 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003078 if (PointeeType.isNull())
3079 return QualType();
3080
3081 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003082 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003083 // A dependent pointer type 'T *' has is being transformed such
3084 // that an Objective-C class type is being replaced for 'T'. The
3085 // resulting pointer type is an ObjCObjectPointerType, not a
3086 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003087 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003088
John McCallc12c5bb2010-05-15 11:32:37 +00003089 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3090 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003091 return Result;
3092 }
John McCall43fed0d2010-11-12 08:19:04 +00003093
Douglas Gregor92e986e2010-04-22 16:44:27 +00003094 if (getDerived().AlwaysRebuild() ||
3095 PointeeType != TL.getPointeeLoc().getType()) {
3096 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3097 if (Result.isNull())
3098 return QualType();
3099 }
Sean Huntc3021132010-05-05 15:23:54 +00003100
Douglas Gregor92e986e2010-04-22 16:44:27 +00003101 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3102 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003103 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003104}
Mike Stump1eb44332009-09-09 15:08:12 +00003105
3106template<typename Derived>
3107QualType
John McCalla2becad2009-10-21 00:40:46 +00003108TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003109 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003110 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003111 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3112 if (PointeeType.isNull())
3113 return QualType();
3114
3115 QualType Result = TL.getType();
3116 if (getDerived().AlwaysRebuild() ||
3117 PointeeType != TL.getPointeeLoc().getType()) {
3118 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003119 TL.getSigilLoc());
3120 if (Result.isNull())
3121 return QualType();
3122 }
3123
Douglas Gregor39968ad2010-04-22 16:50:51 +00003124 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003125 NewT.setSigilLoc(TL.getSigilLoc());
3126 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003127}
3128
John McCall85737a72009-10-30 00:06:24 +00003129/// Transforms a reference type. Note that somewhat paradoxically we
3130/// don't care whether the type itself is an l-value type or an r-value
3131/// type; we only care if the type was *written* as an l-value type
3132/// or an r-value type.
3133template<typename Derived>
3134QualType
3135TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003136 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003137 const ReferenceType *T = TL.getTypePtr();
3138
3139 // Note that this works with the pointee-as-written.
3140 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3141 if (PointeeType.isNull())
3142 return QualType();
3143
3144 QualType Result = TL.getType();
3145 if (getDerived().AlwaysRebuild() ||
3146 PointeeType != T->getPointeeTypeAsWritten()) {
3147 Result = getDerived().RebuildReferenceType(PointeeType,
3148 T->isSpelledAsLValue(),
3149 TL.getSigilLoc());
3150 if (Result.isNull())
3151 return QualType();
3152 }
3153
3154 // r-value references can be rebuilt as l-value references.
3155 ReferenceTypeLoc NewTL;
3156 if (isa<LValueReferenceType>(Result))
3157 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3158 else
3159 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3160 NewTL.setSigilLoc(TL.getSigilLoc());
3161
3162 return Result;
3163}
3164
Mike Stump1eb44332009-09-09 15:08:12 +00003165template<typename Derived>
3166QualType
John McCalla2becad2009-10-21 00:40:46 +00003167TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003168 LValueReferenceTypeLoc TL) {
3169 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003170}
3171
Mike Stump1eb44332009-09-09 15:08:12 +00003172template<typename Derived>
3173QualType
John McCalla2becad2009-10-21 00:40:46 +00003174TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003175 RValueReferenceTypeLoc TL) {
3176 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003177}
Mike Stump1eb44332009-09-09 15:08:12 +00003178
Douglas Gregor577f75a2009-08-04 16:50:30 +00003179template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003180QualType
John McCalla2becad2009-10-21 00:40:46 +00003181TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003182 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003183 MemberPointerType *T = TL.getTypePtr();
3184
3185 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003186 if (PointeeType.isNull())
3187 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003188
John McCalla2becad2009-10-21 00:40:46 +00003189 // TODO: preserve source information for this.
3190 QualType ClassType
3191 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003192 if (ClassType.isNull())
3193 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003194
John McCalla2becad2009-10-21 00:40:46 +00003195 QualType Result = TL.getType();
3196 if (getDerived().AlwaysRebuild() ||
3197 PointeeType != T->getPointeeType() ||
3198 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00003199 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3200 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003201 if (Result.isNull())
3202 return QualType();
3203 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003204
John McCalla2becad2009-10-21 00:40:46 +00003205 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3206 NewTL.setSigilLoc(TL.getSigilLoc());
3207
3208 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003209}
3210
Mike Stump1eb44332009-09-09 15:08:12 +00003211template<typename Derived>
3212QualType
John McCalla2becad2009-10-21 00:40:46 +00003213TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003214 ConstantArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003215 ConstantArrayType *T = TL.getTypePtr();
3216 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003217 if (ElementType.isNull())
3218 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003219
John McCalla2becad2009-10-21 00:40:46 +00003220 QualType Result = TL.getType();
3221 if (getDerived().AlwaysRebuild() ||
3222 ElementType != T->getElementType()) {
3223 Result = getDerived().RebuildConstantArrayType(ElementType,
3224 T->getSizeModifier(),
3225 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003226 T->getIndexTypeCVRQualifiers(),
3227 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003228 if (Result.isNull())
3229 return QualType();
3230 }
Sean Huntc3021132010-05-05 15:23:54 +00003231
John McCalla2becad2009-10-21 00:40:46 +00003232 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3233 NewTL.setLBracketLoc(TL.getLBracketLoc());
3234 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003235
John McCalla2becad2009-10-21 00:40:46 +00003236 Expr *Size = TL.getSizeExpr();
3237 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003238 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003239 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3240 }
3241 NewTL.setSizeExpr(Size);
3242
3243 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003244}
Mike Stump1eb44332009-09-09 15:08:12 +00003245
Douglas Gregor577f75a2009-08-04 16:50:30 +00003246template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003247QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003248 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003249 IncompleteArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003250 IncompleteArrayType *T = TL.getTypePtr();
3251 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003252 if (ElementType.isNull())
3253 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003254
John McCalla2becad2009-10-21 00:40:46 +00003255 QualType Result = TL.getType();
3256 if (getDerived().AlwaysRebuild() ||
3257 ElementType != T->getElementType()) {
3258 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003259 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003260 T->getIndexTypeCVRQualifiers(),
3261 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003262 if (Result.isNull())
3263 return QualType();
3264 }
Sean Huntc3021132010-05-05 15:23:54 +00003265
John McCalla2becad2009-10-21 00:40:46 +00003266 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3267 NewTL.setLBracketLoc(TL.getLBracketLoc());
3268 NewTL.setRBracketLoc(TL.getRBracketLoc());
3269 NewTL.setSizeExpr(0);
3270
3271 return Result;
3272}
3273
3274template<typename Derived>
3275QualType
3276TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003277 VariableArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003278 VariableArrayType *T = TL.getTypePtr();
3279 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3280 if (ElementType.isNull())
3281 return QualType();
3282
3283 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003284 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003285
John McCall60d7b3a2010-08-24 06:29:42 +00003286 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003287 = getDerived().TransformExpr(T->getSizeExpr());
3288 if (SizeResult.isInvalid())
3289 return QualType();
3290
John McCall9ae2f072010-08-23 23:25:46 +00003291 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003292
3293 QualType Result = TL.getType();
3294 if (getDerived().AlwaysRebuild() ||
3295 ElementType != T->getElementType() ||
3296 Size != T->getSizeExpr()) {
3297 Result = getDerived().RebuildVariableArrayType(ElementType,
3298 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003299 Size,
John McCalla2becad2009-10-21 00:40:46 +00003300 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003301 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003302 if (Result.isNull())
3303 return QualType();
3304 }
Sean Huntc3021132010-05-05 15:23:54 +00003305
John McCalla2becad2009-10-21 00:40:46 +00003306 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3307 NewTL.setLBracketLoc(TL.getLBracketLoc());
3308 NewTL.setRBracketLoc(TL.getRBracketLoc());
3309 NewTL.setSizeExpr(Size);
3310
3311 return Result;
3312}
3313
3314template<typename Derived>
3315QualType
3316TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003317 DependentSizedArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003318 DependentSizedArrayType *T = TL.getTypePtr();
3319 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3320 if (ElementType.isNull())
3321 return QualType();
3322
3323 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003324 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003325
John McCall60d7b3a2010-08-24 06:29:42 +00003326 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003327 = getDerived().TransformExpr(T->getSizeExpr());
3328 if (SizeResult.isInvalid())
3329 return QualType();
3330
3331 Expr *Size = static_cast<Expr*>(SizeResult.get());
3332
3333 QualType Result = TL.getType();
3334 if (getDerived().AlwaysRebuild() ||
3335 ElementType != T->getElementType() ||
3336 Size != T->getSizeExpr()) {
3337 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3338 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003339 Size,
John McCalla2becad2009-10-21 00:40:46 +00003340 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003341 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003342 if (Result.isNull())
3343 return QualType();
3344 }
3345 else SizeResult.take();
3346
3347 // We might have any sort of array type now, but fortunately they
3348 // all have the same location layout.
3349 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3350 NewTL.setLBracketLoc(TL.getLBracketLoc());
3351 NewTL.setRBracketLoc(TL.getRBracketLoc());
3352 NewTL.setSizeExpr(Size);
3353
3354 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003355}
Mike Stump1eb44332009-09-09 15:08:12 +00003356
3357template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003358QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003359 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003360 DependentSizedExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003361 DependentSizedExtVectorType *T = TL.getTypePtr();
3362
3363 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003364 QualType ElementType = getDerived().TransformType(T->getElementType());
3365 if (ElementType.isNull())
3366 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003367
Douglas Gregor670444e2009-08-04 22:27:00 +00003368 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003369 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003370
John McCall60d7b3a2010-08-24 06:29:42 +00003371 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003372 if (Size.isInvalid())
3373 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003374
John McCalla2becad2009-10-21 00:40:46 +00003375 QualType Result = TL.getType();
3376 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003377 ElementType != T->getElementType() ||
3378 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003379 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003380 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003381 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003382 if (Result.isNull())
3383 return QualType();
3384 }
John McCalla2becad2009-10-21 00:40:46 +00003385
3386 // Result might be dependent or not.
3387 if (isa<DependentSizedExtVectorType>(Result)) {
3388 DependentSizedExtVectorTypeLoc NewTL
3389 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3390 NewTL.setNameLoc(TL.getNameLoc());
3391 } else {
3392 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3393 NewTL.setNameLoc(TL.getNameLoc());
3394 }
3395
3396 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003397}
Mike Stump1eb44332009-09-09 15:08:12 +00003398
3399template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003400QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003401 VectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003402 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003403 QualType ElementType = getDerived().TransformType(T->getElementType());
3404 if (ElementType.isNull())
3405 return QualType();
3406
John McCalla2becad2009-10-21 00:40:46 +00003407 QualType Result = TL.getType();
3408 if (getDerived().AlwaysRebuild() ||
3409 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003410 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003411 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003412 if (Result.isNull())
3413 return QualType();
3414 }
Sean Huntc3021132010-05-05 15:23:54 +00003415
John McCalla2becad2009-10-21 00:40:46 +00003416 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3417 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003418
John McCalla2becad2009-10-21 00:40:46 +00003419 return Result;
3420}
3421
3422template<typename Derived>
3423QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003424 ExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003425 VectorType *T = TL.getTypePtr();
3426 QualType ElementType = getDerived().TransformType(T->getElementType());
3427 if (ElementType.isNull())
3428 return QualType();
3429
3430 QualType Result = TL.getType();
3431 if (getDerived().AlwaysRebuild() ||
3432 ElementType != T->getElementType()) {
3433 Result = getDerived().RebuildExtVectorType(ElementType,
3434 T->getNumElements(),
3435 /*FIXME*/ SourceLocation());
3436 if (Result.isNull())
3437 return QualType();
3438 }
Sean Huntc3021132010-05-05 15:23:54 +00003439
John McCalla2becad2009-10-21 00:40:46 +00003440 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3441 NewTL.setNameLoc(TL.getNameLoc());
3442
3443 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003444}
Mike Stump1eb44332009-09-09 15:08:12 +00003445
3446template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003447ParmVarDecl *
3448TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
3449 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
3450 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
3451 if (!NewDI)
3452 return 0;
3453
3454 if (NewDI == OldDI)
3455 return OldParm;
3456 else
3457 return ParmVarDecl::Create(SemaRef.Context,
3458 OldParm->getDeclContext(),
3459 OldParm->getLocation(),
3460 OldParm->getIdentifier(),
3461 NewDI->getType(),
3462 NewDI,
3463 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00003464 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00003465 /* DefArg */ NULL);
3466}
3467
3468template<typename Derived>
3469bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003470 TransformFunctionTypeParams(SourceLocation Loc,
3471 ParmVarDecl **Params, unsigned NumParams,
3472 const QualType *ParamTypes,
3473 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3474 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3475 for (unsigned i = 0; i != NumParams; ++i) {
3476 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003477 if (OldParm->isParameterPack()) {
3478 // We have a function parameter pack that may need to be expanded.
3479 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003480
Douglas Gregor603cfb42011-01-05 23:12:31 +00003481 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003482 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3483 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3484 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3485 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003486
3487 // Determine whether we should expand the parameter packs.
3488 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003489 bool RetainExpansion = false;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003490 unsigned NumExpansions = 0;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003491 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3492 Pattern.getSourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003493 Unexpanded.data(),
3494 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003495 ShouldExpand,
3496 RetainExpansion,
3497 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003498 return true;
3499 }
3500
3501 if (ShouldExpand) {
3502 // Expand the function parameter pack into multiple, separate
3503 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003504 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003505 for (unsigned I = 0; I != NumExpansions; ++I) {
3506 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3507 ParmVarDecl *NewParm
3508 = getDerived().TransformFunctionTypeParam(OldParm);
3509 if (!NewParm)
3510 return true;
3511
Douglas Gregora009b592011-01-07 00:20:55 +00003512 OutParamTypes.push_back(NewParm->getType());
3513 if (PVars)
3514 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003515 }
Douglas Gregord3731192011-01-10 07:32:04 +00003516
3517 // If we're supposed to retain a pack expansion, do so by temporarily
3518 // forgetting the partially-substituted parameter pack.
3519 if (RetainExpansion) {
3520 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3521 ParmVarDecl *NewParm
3522 = getDerived().TransformFunctionTypeParam(OldParm);
3523 if (!NewParm)
3524 return true;
3525
3526 OutParamTypes.push_back(NewParm->getType());
3527 if (PVars)
3528 PVars->push_back(NewParm);
3529 }
3530
Douglas Gregor603cfb42011-01-05 23:12:31 +00003531 // We're done with the pack expansion.
3532 continue;
3533 }
3534
3535 // We'll substitute the parameter now without expanding the pack
3536 // expansion.
3537 }
3538
3539 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3540 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
John McCall21ef0fa2010-03-11 09:03:00 +00003541 if (!NewParm)
3542 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003543
Douglas Gregora009b592011-01-07 00:20:55 +00003544 OutParamTypes.push_back(NewParm->getType());
3545 if (PVars)
3546 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003547 continue;
3548 }
John McCall21ef0fa2010-03-11 09:03:00 +00003549
3550 // Deal with the possibility that we don't have a parameter
3551 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003552 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003553 bool IsPackExpansion = false;
3554 if (const PackExpansionType *Expansion
3555 = dyn_cast<PackExpansionType>(OldType)) {
3556 // We have a function parameter pack that may need to be expanded.
3557 QualType Pattern = Expansion->getPattern();
3558 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3559 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3560
3561 // Determine whether we should expand the parameter packs.
3562 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003563 bool RetainExpansion = false;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003564 unsigned NumExpansions = 0;
Douglas Gregora009b592011-01-07 00:20:55 +00003565 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003566 Unexpanded.data(),
3567 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003568 ShouldExpand,
3569 RetainExpansion,
3570 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003571 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003572 }
3573
3574 if (ShouldExpand) {
3575 // Expand the function parameter pack into multiple, separate
3576 // parameters.
3577 for (unsigned I = 0; I != NumExpansions; ++I) {
3578 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3579 QualType NewType = getDerived().TransformType(Pattern);
3580 if (NewType.isNull())
3581 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003582
Douglas Gregora009b592011-01-07 00:20:55 +00003583 OutParamTypes.push_back(NewType);
3584 if (PVars)
3585 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003586 }
3587
3588 // We're done with the pack expansion.
3589 continue;
3590 }
3591
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003592 // If we're supposed to retain a pack expansion, do so by temporarily
3593 // forgetting the partially-substituted parameter pack.
3594 if (RetainExpansion) {
3595 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3596 QualType NewType = getDerived().TransformType(Pattern);
3597 if (NewType.isNull())
3598 return true;
3599
3600 OutParamTypes.push_back(NewType);
3601 if (PVars)
3602 PVars->push_back(0);
3603 }
Douglas Gregord3731192011-01-10 07:32:04 +00003604
Douglas Gregor603cfb42011-01-05 23:12:31 +00003605 // We'll substitute the parameter now without expanding the pack
3606 // expansion.
3607 OldType = Expansion->getPattern();
3608 IsPackExpansion = true;
3609 }
3610
3611 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3612 QualType NewType = getDerived().TransformType(OldType);
3613 if (NewType.isNull())
3614 return true;
3615
3616 if (IsPackExpansion)
3617 NewType = getSema().Context.getPackExpansionType(NewType);
3618
Douglas Gregora009b592011-01-07 00:20:55 +00003619 OutParamTypes.push_back(NewType);
3620 if (PVars)
3621 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00003622 }
3623
3624 return false;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003625 }
John McCall21ef0fa2010-03-11 09:03:00 +00003626
3627template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003628QualType
John McCalla2becad2009-10-21 00:40:46 +00003629TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003630 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003631 // Transform the parameters and return type.
3632 //
3633 // We instantiate in source order, with the return type first followed by
3634 // the parameters, because users tend to expect this (even if they shouldn't
3635 // rely on it!).
3636 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003637 // When the function has a trailing return type, we instantiate the
3638 // parameters before the return type, since the return type can then refer
3639 // to the parameters themselves (via decltype, sizeof, etc.).
3640 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003641 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003642 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor895162d2010-04-30 18:55:50 +00003643 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003644
Douglas Gregordab60ad2010-10-01 18:44:50 +00003645 QualType ResultType;
3646
3647 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00003648 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3649 TL.getParmArray(),
3650 TL.getNumArgs(),
3651 TL.getTypePtr()->arg_type_begin(),
3652 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003653 return QualType();
3654
3655 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3656 if (ResultType.isNull())
3657 return QualType();
3658 }
3659 else {
3660 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3661 if (ResultType.isNull())
3662 return QualType();
3663
Douglas Gregora009b592011-01-07 00:20:55 +00003664 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3665 TL.getParmArray(),
3666 TL.getNumArgs(),
3667 TL.getTypePtr()->arg_type_begin(),
3668 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003669 return QualType();
3670 }
3671
John McCalla2becad2009-10-21 00:40:46 +00003672 QualType Result = TL.getType();
3673 if (getDerived().AlwaysRebuild() ||
3674 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00003675 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00003676 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3677 Result = getDerived().RebuildFunctionProtoType(ResultType,
3678 ParamTypes.data(),
3679 ParamTypes.size(),
3680 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003681 T->getTypeQuals(),
3682 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00003683 if (Result.isNull())
3684 return QualType();
3685 }
Mike Stump1eb44332009-09-09 15:08:12 +00003686
John McCalla2becad2009-10-21 00:40:46 +00003687 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3688 NewTL.setLParenLoc(TL.getLParenLoc());
3689 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003690 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00003691 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3692 NewTL.setArg(i, ParamDecls[i]);
3693
3694 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003695}
Mike Stump1eb44332009-09-09 15:08:12 +00003696
Douglas Gregor577f75a2009-08-04 16:50:30 +00003697template<typename Derived>
3698QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00003699 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003700 FunctionNoProtoTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003701 FunctionNoProtoType *T = TL.getTypePtr();
3702 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3703 if (ResultType.isNull())
3704 return QualType();
3705
3706 QualType Result = TL.getType();
3707 if (getDerived().AlwaysRebuild() ||
3708 ResultType != T->getResultType())
3709 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3710
3711 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3712 NewTL.setLParenLoc(TL.getLParenLoc());
3713 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003714 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003715
3716 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003717}
Mike Stump1eb44332009-09-09 15:08:12 +00003718
John McCalled976492009-12-04 22:46:56 +00003719template<typename Derived> QualType
3720TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003721 UnresolvedUsingTypeLoc TL) {
John McCalled976492009-12-04 22:46:56 +00003722 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003723 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00003724 if (!D)
3725 return QualType();
3726
3727 QualType Result = TL.getType();
3728 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3729 Result = getDerived().RebuildUnresolvedUsingType(D);
3730 if (Result.isNull())
3731 return QualType();
3732 }
3733
3734 // We might get an arbitrary type spec type back. We should at
3735 // least always get a type spec type, though.
3736 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3737 NewTL.setNameLoc(TL.getNameLoc());
3738
3739 return Result;
3740}
3741
Douglas Gregor577f75a2009-08-04 16:50:30 +00003742template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003743QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003744 TypedefTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003745 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003746 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003747 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3748 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003749 if (!Typedef)
3750 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003751
John McCalla2becad2009-10-21 00:40:46 +00003752 QualType Result = TL.getType();
3753 if (getDerived().AlwaysRebuild() ||
3754 Typedef != T->getDecl()) {
3755 Result = getDerived().RebuildTypedefType(Typedef);
3756 if (Result.isNull())
3757 return QualType();
3758 }
Mike Stump1eb44332009-09-09 15:08:12 +00003759
John McCalla2becad2009-10-21 00:40:46 +00003760 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3761 NewTL.setNameLoc(TL.getNameLoc());
3762
3763 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003764}
Mike Stump1eb44332009-09-09 15:08:12 +00003765
Douglas Gregor577f75a2009-08-04 16:50:30 +00003766template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003767QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003768 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003769 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003770 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003771
John McCall60d7b3a2010-08-24 06:29:42 +00003772 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003773 if (E.isInvalid())
3774 return QualType();
3775
John McCalla2becad2009-10-21 00:40:46 +00003776 QualType Result = TL.getType();
3777 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003778 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003779 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00003780 if (Result.isNull())
3781 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003782 }
John McCalla2becad2009-10-21 00:40:46 +00003783 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003784
John McCalla2becad2009-10-21 00:40:46 +00003785 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003786 NewTL.setTypeofLoc(TL.getTypeofLoc());
3787 NewTL.setLParenLoc(TL.getLParenLoc());
3788 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003789
3790 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003791}
Mike Stump1eb44332009-09-09 15:08:12 +00003792
3793template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003794QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003795 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00003796 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3797 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3798 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003799 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003800
John McCalla2becad2009-10-21 00:40:46 +00003801 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003802 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3803 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003804 if (Result.isNull())
3805 return QualType();
3806 }
Mike Stump1eb44332009-09-09 15:08:12 +00003807
John McCalla2becad2009-10-21 00:40:46 +00003808 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003809 NewTL.setTypeofLoc(TL.getTypeofLoc());
3810 NewTL.setLParenLoc(TL.getLParenLoc());
3811 NewTL.setRParenLoc(TL.getRParenLoc());
3812 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003813
3814 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003815}
Mike Stump1eb44332009-09-09 15:08:12 +00003816
3817template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003818QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003819 DecltypeTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003820 DecltypeType *T = TL.getTypePtr();
3821
Douglas Gregor670444e2009-08-04 22:27:00 +00003822 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003823 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003824
John McCall60d7b3a2010-08-24 06:29:42 +00003825 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003826 if (E.isInvalid())
3827 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003828
John McCalla2becad2009-10-21 00:40:46 +00003829 QualType Result = TL.getType();
3830 if (getDerived().AlwaysRebuild() ||
3831 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003832 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003833 if (Result.isNull())
3834 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003835 }
John McCalla2becad2009-10-21 00:40:46 +00003836 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003837
John McCalla2becad2009-10-21 00:40:46 +00003838 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3839 NewTL.setNameLoc(TL.getNameLoc());
3840
3841 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003842}
3843
3844template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003845QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003846 RecordTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003847 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003848 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003849 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3850 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003851 if (!Record)
3852 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003853
John McCalla2becad2009-10-21 00:40:46 +00003854 QualType Result = TL.getType();
3855 if (getDerived().AlwaysRebuild() ||
3856 Record != T->getDecl()) {
3857 Result = getDerived().RebuildRecordType(Record);
3858 if (Result.isNull())
3859 return QualType();
3860 }
Mike Stump1eb44332009-09-09 15:08:12 +00003861
John McCalla2becad2009-10-21 00:40:46 +00003862 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3863 NewTL.setNameLoc(TL.getNameLoc());
3864
3865 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003866}
Mike Stump1eb44332009-09-09 15:08:12 +00003867
3868template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003869QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003870 EnumTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003871 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003872 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003873 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3874 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003875 if (!Enum)
3876 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003877
John McCalla2becad2009-10-21 00:40:46 +00003878 QualType Result = TL.getType();
3879 if (getDerived().AlwaysRebuild() ||
3880 Enum != T->getDecl()) {
3881 Result = getDerived().RebuildEnumType(Enum);
3882 if (Result.isNull())
3883 return QualType();
3884 }
Mike Stump1eb44332009-09-09 15:08:12 +00003885
John McCalla2becad2009-10-21 00:40:46 +00003886 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3887 NewTL.setNameLoc(TL.getNameLoc());
3888
3889 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003890}
John McCall7da24312009-09-05 00:15:47 +00003891
John McCall3cb0ebd2010-03-10 03:28:59 +00003892template<typename Derived>
3893QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3894 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003895 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00003896 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3897 TL.getTypePtr()->getDecl());
3898 if (!D) return QualType();
3899
3900 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3901 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3902 return T;
3903}
3904
Douglas Gregor577f75a2009-08-04 16:50:30 +00003905template<typename Derived>
3906QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003907 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003908 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003909 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003910}
3911
Mike Stump1eb44332009-09-09 15:08:12 +00003912template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003913QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003914 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003915 SubstTemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003916 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003917}
3918
3919template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003920QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003921 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003922 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00003923 const TemplateSpecializationType *T = TL.getTypePtr();
3924
Mike Stump1eb44332009-09-09 15:08:12 +00003925 TemplateName Template
John McCall43fed0d2010-11-12 08:19:04 +00003926 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003927 if (Template.isNull())
3928 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003929
John McCall43fed0d2010-11-12 08:19:04 +00003930 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3931}
3932
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003933namespace {
3934 /// \brief Simple iterator that traverses the template arguments in a
3935 /// container that provides a \c getArgLoc() member function.
3936 ///
3937 /// This iterator is intended to be used with the iterator form of
3938 /// \c TreeTransform<Derived>::TransformTemplateArguments().
3939 template<typename ArgLocContainer>
3940 class TemplateArgumentLocContainerIterator {
3941 ArgLocContainer *Container;
3942 unsigned Index;
3943
3944 public:
3945 typedef TemplateArgumentLoc value_type;
3946 typedef TemplateArgumentLoc reference;
3947 typedef int difference_type;
3948 typedef std::input_iterator_tag iterator_category;
3949
3950 class pointer {
3951 TemplateArgumentLoc Arg;
3952
3953 public:
3954 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3955
3956 const TemplateArgumentLoc *operator->() const {
3957 return &Arg;
3958 }
3959 };
3960
3961
3962 TemplateArgumentLocContainerIterator() {}
3963
3964 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
3965 unsigned Index)
3966 : Container(&Container), Index(Index) { }
3967
3968 TemplateArgumentLocContainerIterator &operator++() {
3969 ++Index;
3970 return *this;
3971 }
3972
3973 TemplateArgumentLocContainerIterator operator++(int) {
3974 TemplateArgumentLocContainerIterator Old(*this);
3975 ++(*this);
3976 return Old;
3977 }
3978
3979 TemplateArgumentLoc operator*() const {
3980 return Container->getArgLoc(Index);
3981 }
3982
3983 pointer operator->() const {
3984 return pointer(Container->getArgLoc(Index));
3985 }
3986
3987 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00003988 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003989 return X.Container == Y.Container && X.Index == Y.Index;
3990 }
3991
3992 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00003993 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003994 return !(X == Y);
3995 }
3996 };
3997}
3998
3999
John McCall43fed0d2010-11-12 08:19:04 +00004000template <typename Derived>
4001QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4002 TypeLocBuilder &TLB,
4003 TemplateSpecializationTypeLoc TL,
4004 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00004005 TemplateArgumentListInfo NewTemplateArgs;
4006 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4007 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004008 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4009 ArgIterator;
4010 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4011 ArgIterator(TL, TL.getNumArgs()),
4012 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004013 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004014
John McCall833ca992009-10-29 08:12:44 +00004015 // FIXME: maybe don't rebuild if all the template arguments are the same.
4016
4017 QualType Result =
4018 getDerived().RebuildTemplateSpecializationType(Template,
4019 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004020 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004021
4022 if (!Result.isNull()) {
4023 TemplateSpecializationTypeLoc NewTL
4024 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4025 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4026 NewTL.setLAngleLoc(TL.getLAngleLoc());
4027 NewTL.setRAngleLoc(TL.getRAngleLoc());
4028 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4029 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004030 }
Mike Stump1eb44332009-09-09 15:08:12 +00004031
John McCall833ca992009-10-29 08:12:44 +00004032 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004033}
Mike Stump1eb44332009-09-09 15:08:12 +00004034
4035template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004036QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004037TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004038 ElaboratedTypeLoc TL) {
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004039 ElaboratedType *T = TL.getTypePtr();
4040
4041 NestedNameSpecifier *NNS = 0;
4042 // NOTE: the qualifier in an ElaboratedType is optional.
4043 if (T->getQualifier() != 0) {
4044 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004045 TL.getQualifierRange());
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004046 if (!NNS)
4047 return QualType();
4048 }
Mike Stump1eb44332009-09-09 15:08:12 +00004049
John McCall43fed0d2010-11-12 08:19:04 +00004050 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4051 if (NamedT.isNull())
4052 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004053
John McCalla2becad2009-10-21 00:40:46 +00004054 QualType Result = TL.getType();
4055 if (getDerived().AlwaysRebuild() ||
4056 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004057 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004058 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4059 T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004060 if (Result.isNull())
4061 return QualType();
4062 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004063
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004064 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004065 NewTL.setKeywordLoc(TL.getKeywordLoc());
4066 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00004067
4068 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004069}
Mike Stump1eb44332009-09-09 15:08:12 +00004070
4071template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004072QualType TreeTransform<Derived>::TransformAttributedType(
4073 TypeLocBuilder &TLB,
4074 AttributedTypeLoc TL) {
4075 const AttributedType *oldType = TL.getTypePtr();
4076 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4077 if (modifiedType.isNull())
4078 return QualType();
4079
4080 QualType result = TL.getType();
4081
4082 // FIXME: dependent operand expressions?
4083 if (getDerived().AlwaysRebuild() ||
4084 modifiedType != oldType->getModifiedType()) {
4085 // TODO: this is really lame; we should really be rebuilding the
4086 // equivalent type from first principles.
4087 QualType equivalentType
4088 = getDerived().TransformType(oldType->getEquivalentType());
4089 if (equivalentType.isNull())
4090 return QualType();
4091 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4092 modifiedType,
4093 equivalentType);
4094 }
4095
4096 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4097 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4098 if (TL.hasAttrOperand())
4099 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4100 if (TL.hasAttrExprOperand())
4101 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4102 else if (TL.hasAttrEnumOperand())
4103 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4104
4105 return result;
4106}
4107
4108template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004109QualType
4110TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4111 ParenTypeLoc TL) {
4112 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4113 if (Inner.isNull())
4114 return QualType();
4115
4116 QualType Result = TL.getType();
4117 if (getDerived().AlwaysRebuild() ||
4118 Inner != TL.getInnerLoc().getType()) {
4119 Result = getDerived().RebuildParenType(Inner);
4120 if (Result.isNull())
4121 return QualType();
4122 }
4123
4124 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4125 NewTL.setLParenLoc(TL.getLParenLoc());
4126 NewTL.setRParenLoc(TL.getRParenLoc());
4127 return Result;
4128}
4129
4130template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004131QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004132 DependentNameTypeLoc TL) {
Douglas Gregor4714c122010-03-31 17:34:00 +00004133 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004134
Douglas Gregor577f75a2009-08-04 16:50:30 +00004135 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004136 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004137 TL.getQualifierRange());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004138 if (!NNS)
4139 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004140
John McCall33500952010-06-11 00:33:02 +00004141 QualType Result
4142 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4143 T->getIdentifier(),
4144 TL.getKeywordLoc(),
4145 TL.getQualifierRange(),
4146 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004147 if (Result.isNull())
4148 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004149
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004150 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4151 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004152 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4153
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004154 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4155 NewTL.setKeywordLoc(TL.getKeywordLoc());
4156 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00004157 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004158 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4159 NewTL.setKeywordLoc(TL.getKeywordLoc());
4160 NewTL.setQualifierRange(TL.getQualifierRange());
4161 NewTL.setNameLoc(TL.getNameLoc());
4162 }
John McCalla2becad2009-10-21 00:40:46 +00004163 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004164}
Mike Stump1eb44332009-09-09 15:08:12 +00004165
Douglas Gregor577f75a2009-08-04 16:50:30 +00004166template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004167QualType TreeTransform<Derived>::
4168 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004169 DependentTemplateSpecializationTypeLoc TL) {
John McCall33500952010-06-11 00:33:02 +00004170 DependentTemplateSpecializationType *T = TL.getTypePtr();
4171
4172 NestedNameSpecifier *NNS
4173 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004174 TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00004175 if (!NNS)
4176 return QualType();
4177
John McCall43fed0d2010-11-12 08:19:04 +00004178 return getDerived()
4179 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4180}
4181
4182template<typename Derived>
4183QualType TreeTransform<Derived>::
4184 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4185 DependentTemplateSpecializationTypeLoc TL,
4186 NestedNameSpecifier *NNS) {
4187 DependentTemplateSpecializationType *T = TL.getTypePtr();
4188
John McCall33500952010-06-11 00:33:02 +00004189 TemplateArgumentListInfo NewTemplateArgs;
4190 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4191 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004192
4193 typedef TemplateArgumentLocContainerIterator<
4194 DependentTemplateSpecializationTypeLoc> ArgIterator;
4195 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4196 ArgIterator(TL, TL.getNumArgs()),
4197 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004198 return QualType();
John McCall33500952010-06-11 00:33:02 +00004199
Douglas Gregor1efb6c72010-09-08 23:56:00 +00004200 QualType Result
4201 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4202 NNS,
4203 TL.getQualifierRange(),
4204 T->getIdentifier(),
4205 TL.getNameLoc(),
4206 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00004207 if (Result.isNull())
4208 return QualType();
4209
4210 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4211 QualType NamedT = ElabT->getNamedType();
4212
4213 // Copy information relevant to the template specialization.
4214 TemplateSpecializationTypeLoc NamedTL
4215 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4216 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4217 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4218 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4219 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4220
4221 // Copy information relevant to the elaborated type.
4222 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4223 NewTL.setKeywordLoc(TL.getKeywordLoc());
4224 NewTL.setQualifierRange(TL.getQualifierRange());
4225 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00004226 TypeLoc NewTL(Result, TL.getOpaqueData());
4227 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00004228 }
4229 return Result;
4230}
4231
4232template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004233QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4234 PackExpansionTypeLoc TL) {
Douglas Gregor1d65ebb2011-01-05 19:06:29 +00004235 llvm_unreachable("Caller must expansion pack expansion types");
Douglas Gregor7536dd52010-12-20 02:24:11 +00004236 return QualType();
4237}
4238
4239template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004240QualType
4241TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004242 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004243 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004244 TLB.pushFullCopy(TL);
4245 return TL.getType();
4246}
4247
4248template<typename Derived>
4249QualType
4250TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004251 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004252 // ObjCObjectType is never dependent.
4253 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004254 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004255}
Mike Stump1eb44332009-09-09 15:08:12 +00004256
4257template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004258QualType
4259TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004260 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004261 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004262 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004263 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004264}
4265
Douglas Gregor577f75a2009-08-04 16:50:30 +00004266//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004267// Statement transformation
4268//===----------------------------------------------------------------------===//
4269template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004270StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004271TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004272 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004273}
4274
4275template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004276StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004277TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4278 return getDerived().TransformCompoundStmt(S, false);
4279}
4280
4281template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004282StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004283TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004284 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004285 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004286 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004287 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004288 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4289 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004290 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004291 if (Result.isInvalid()) {
4292 // Immediately fail if this was a DeclStmt, since it's very
4293 // likely that this will cause problems for future statements.
4294 if (isa<DeclStmt>(*B))
4295 return StmtError();
4296
4297 // Otherwise, just keep processing substatements and fail later.
4298 SubStmtInvalid = true;
4299 continue;
4300 }
Mike Stump1eb44332009-09-09 15:08:12 +00004301
Douglas Gregor43959a92009-08-20 07:17:43 +00004302 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4303 Statements.push_back(Result.takeAs<Stmt>());
4304 }
Mike Stump1eb44332009-09-09 15:08:12 +00004305
John McCall7114cba2010-08-27 19:56:05 +00004306 if (SubStmtInvalid)
4307 return StmtError();
4308
Douglas Gregor43959a92009-08-20 07:17:43 +00004309 if (!getDerived().AlwaysRebuild() &&
4310 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004311 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004312
4313 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4314 move_arg(Statements),
4315 S->getRBracLoc(),
4316 IsStmtExpr);
4317}
Mike Stump1eb44332009-09-09 15:08:12 +00004318
Douglas Gregor43959a92009-08-20 07:17:43 +00004319template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004320StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004321TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004322 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004323 {
4324 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004325 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004326
Eli Friedman264c1f82009-11-19 03:14:00 +00004327 // Transform the left-hand case value.
4328 LHS = getDerived().TransformExpr(S->getLHS());
4329 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004330 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004331
Eli Friedman264c1f82009-11-19 03:14:00 +00004332 // Transform the right-hand case value (for the GNU case-range extension).
4333 RHS = getDerived().TransformExpr(S->getRHS());
4334 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004335 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004336 }
Mike Stump1eb44332009-09-09 15:08:12 +00004337
Douglas Gregor43959a92009-08-20 07:17:43 +00004338 // Build the case statement.
4339 // Case statements are always rebuilt so that they will attached to their
4340 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004341 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004342 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004343 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004344 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004345 S->getColonLoc());
4346 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004347 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004348
Douglas Gregor43959a92009-08-20 07:17:43 +00004349 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004350 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004351 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004352 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004353
Douglas Gregor43959a92009-08-20 07:17:43 +00004354 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004355 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004356}
4357
4358template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004359StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004360TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004361 // Transform the statement following the default case
John McCall60d7b3a2010-08-24 06:29:42 +00004362 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004363 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004364 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004365
Douglas Gregor43959a92009-08-20 07:17:43 +00004366 // Default statements are always rebuilt
4367 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004368 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004369}
Mike Stump1eb44332009-09-09 15:08:12 +00004370
Douglas Gregor43959a92009-08-20 07:17:43 +00004371template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004372StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004373TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004374 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004375 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004376 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004377
Douglas Gregor43959a92009-08-20 07:17:43 +00004378 // FIXME: Pass the real colon location in.
4379 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4380 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +00004381 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00004382}
Mike Stump1eb44332009-09-09 15:08:12 +00004383
Douglas Gregor43959a92009-08-20 07:17:43 +00004384template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004385StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004386TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004387 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004388 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004389 VarDecl *ConditionVar = 0;
4390 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004391 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004392 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004393 getDerived().TransformDefinition(
4394 S->getConditionVariable()->getLocation(),
4395 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004396 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004397 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004398 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004399 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004400
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004401 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004402 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004403
4404 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004405 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004406 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4407 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004408 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004409 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004410
John McCall9ae2f072010-08-23 23:25:46 +00004411 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004412 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004413 }
Sean Huntc3021132010-05-05 15:23:54 +00004414
John McCall9ae2f072010-08-23 23:25:46 +00004415 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4416 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004417 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004418
Douglas Gregor43959a92009-08-20 07:17:43 +00004419 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004420 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00004421 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004422 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004423
Douglas Gregor43959a92009-08-20 07:17:43 +00004424 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004425 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00004426 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004427 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004428
Douglas Gregor43959a92009-08-20 07:17:43 +00004429 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004430 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004431 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004432 Then.get() == S->getThen() &&
4433 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00004434 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004435
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004436 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00004437 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00004438 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004439}
4440
4441template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004442StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004443TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004444 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00004445 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00004446 VarDecl *ConditionVar = 0;
4447 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004448 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00004449 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004450 getDerived().TransformDefinition(
4451 S->getConditionVariable()->getLocation(),
4452 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00004453 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004454 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004455 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00004456 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004457
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004458 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004459 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004460 }
Mike Stump1eb44332009-09-09 15:08:12 +00004461
Douglas Gregor43959a92009-08-20 07:17:43 +00004462 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004463 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00004464 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00004465 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00004466 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004467 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004468
Douglas Gregor43959a92009-08-20 07:17:43 +00004469 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004470 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004471 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004472 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004473
Douglas Gregor43959a92009-08-20 07:17:43 +00004474 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00004475 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4476 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004477}
Mike Stump1eb44332009-09-09 15:08:12 +00004478
Douglas Gregor43959a92009-08-20 07:17:43 +00004479template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004480StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004481TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004482 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004483 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00004484 VarDecl *ConditionVar = 0;
4485 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004486 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00004487 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004488 getDerived().TransformDefinition(
4489 S->getConditionVariable()->getLocation(),
4490 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00004491 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004492 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004493 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00004494 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004495
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004496 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004497 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004498
4499 if (S->getCond()) {
4500 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004501 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4502 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004503 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004504 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00004505 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004506 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004507 }
Mike Stump1eb44332009-09-09 15:08:12 +00004508
John McCall9ae2f072010-08-23 23:25:46 +00004509 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4510 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004511 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004512
Douglas Gregor43959a92009-08-20 07:17:43 +00004513 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004514 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004515 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004516 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004517
Douglas Gregor43959a92009-08-20 07:17:43 +00004518 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004519 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004520 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004521 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00004522 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004523
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004524 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00004525 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004526}
Mike Stump1eb44332009-09-09 15:08:12 +00004527
Douglas Gregor43959a92009-08-20 07:17:43 +00004528template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004529StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004530TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004531 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004532 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004533 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004534 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004535
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004536 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004537 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004538 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004539 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004540
Douglas Gregor43959a92009-08-20 07:17:43 +00004541 if (!getDerived().AlwaysRebuild() &&
4542 Cond.get() == S->getCond() &&
4543 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004544 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004545
John McCall9ae2f072010-08-23 23:25:46 +00004546 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4547 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004548 S->getRParenLoc());
4549}
Mike Stump1eb44332009-09-09 15:08:12 +00004550
Douglas Gregor43959a92009-08-20 07:17:43 +00004551template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004552StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004553TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004554 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00004555 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00004556 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004557 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004558
Douglas Gregor43959a92009-08-20 07:17:43 +00004559 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004560 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004561 VarDecl *ConditionVar = 0;
4562 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004563 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004564 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004565 getDerived().TransformDefinition(
4566 S->getConditionVariable()->getLocation(),
4567 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004568 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004569 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004570 } else {
4571 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004572
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004573 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004574 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004575
4576 if (S->getCond()) {
4577 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004578 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4579 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004580 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004581 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004582
John McCall9ae2f072010-08-23 23:25:46 +00004583 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004584 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004585 }
Mike Stump1eb44332009-09-09 15:08:12 +00004586
John McCall9ae2f072010-08-23 23:25:46 +00004587 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4588 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004589 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004590
Douglas Gregor43959a92009-08-20 07:17:43 +00004591 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00004592 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00004593 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004594 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004595
John McCall9ae2f072010-08-23 23:25:46 +00004596 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4597 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00004598 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004599
Douglas Gregor43959a92009-08-20 07:17:43 +00004600 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004601 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004602 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004603 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004604
Douglas Gregor43959a92009-08-20 07:17:43 +00004605 if (!getDerived().AlwaysRebuild() &&
4606 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00004607 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004608 Inc.get() == S->getInc() &&
4609 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004610 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004611
Douglas Gregor43959a92009-08-20 07:17:43 +00004612 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004613 Init.get(), FullCond, ConditionVar,
4614 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004615}
4616
4617template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004618StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004619TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004620 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00004621 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004622 S->getLabel());
4623}
4624
4625template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004626StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004627TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004628 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00004629 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004630 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004631
Douglas Gregor43959a92009-08-20 07:17:43 +00004632 if (!getDerived().AlwaysRebuild() &&
4633 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00004634 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004635
4636 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004637 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004638}
4639
4640template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004641StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004642TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004643 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004644}
Mike Stump1eb44332009-09-09 15:08:12 +00004645
Douglas Gregor43959a92009-08-20 07:17:43 +00004646template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004647StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004648TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004649 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004650}
Mike Stump1eb44332009-09-09 15:08:12 +00004651
Douglas Gregor43959a92009-08-20 07:17:43 +00004652template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004653StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004654TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004655 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00004656 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004657 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004658
Mike Stump1eb44332009-09-09 15:08:12 +00004659 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00004660 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00004661 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004662}
Mike Stump1eb44332009-09-09 15:08:12 +00004663
Douglas Gregor43959a92009-08-20 07:17:43 +00004664template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004665StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004666TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004667 bool DeclChanged = false;
4668 llvm::SmallVector<Decl *, 4> Decls;
4669 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4670 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00004671 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4672 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00004673 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00004674 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004675
Douglas Gregor43959a92009-08-20 07:17:43 +00004676 if (Transformed != *D)
4677 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00004678
Douglas Gregor43959a92009-08-20 07:17:43 +00004679 Decls.push_back(Transformed);
4680 }
Mike Stump1eb44332009-09-09 15:08:12 +00004681
Douglas Gregor43959a92009-08-20 07:17:43 +00004682 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004683 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004684
4685 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004686 S->getStartLoc(), S->getEndLoc());
4687}
Mike Stump1eb44332009-09-09 15:08:12 +00004688
Douglas Gregor43959a92009-08-20 07:17:43 +00004689template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004690StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004691TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004692 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCall3fa5cae2010-10-26 07:05:15 +00004693 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004694}
4695
4696template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004697StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004698TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00004699
John McCallca0408f2010-08-23 06:44:23 +00004700 ASTOwningVector<Expr*> Constraints(getSema());
4701 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004702 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00004703
John McCall60d7b3a2010-08-24 06:29:42 +00004704 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00004705 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00004706
4707 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00004708
Anders Carlsson703e3942010-01-24 05:50:09 +00004709 // Go through the outputs.
4710 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004711 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004712
Anders Carlsson703e3942010-01-24 05:50:09 +00004713 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004714 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004715
Anders Carlsson703e3942010-01-24 05:50:09 +00004716 // Transform the output expr.
4717 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004718 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004719 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004720 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004721
Anders Carlsson703e3942010-01-24 05:50:09 +00004722 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004723
John McCall9ae2f072010-08-23 23:25:46 +00004724 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004725 }
Sean Huntc3021132010-05-05 15:23:54 +00004726
Anders Carlsson703e3942010-01-24 05:50:09 +00004727 // Go through the inputs.
4728 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004729 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004730
Anders Carlsson703e3942010-01-24 05:50:09 +00004731 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004732 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004733
Anders Carlsson703e3942010-01-24 05:50:09 +00004734 // Transform the input expr.
4735 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004736 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004737 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004738 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004739
Anders Carlsson703e3942010-01-24 05:50:09 +00004740 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004741
John McCall9ae2f072010-08-23 23:25:46 +00004742 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004743 }
Sean Huntc3021132010-05-05 15:23:54 +00004744
Anders Carlsson703e3942010-01-24 05:50:09 +00004745 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004746 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00004747
4748 // Go through the clobbers.
4749 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00004750 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00004751
4752 // No need to transform the asm string literal.
4753 AsmString = SemaRef.Owned(S->getAsmString());
4754
4755 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4756 S->isSimple(),
4757 S->isVolatile(),
4758 S->getNumOutputs(),
4759 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00004760 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004761 move_arg(Constraints),
4762 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00004763 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004764 move_arg(Clobbers),
4765 S->getRParenLoc(),
4766 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00004767}
4768
4769
4770template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004771StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004772TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004773 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00004774 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004775 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004776 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004777
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004778 // Transform the @catch statements (if present).
4779 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004780 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004781 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004782 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004783 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004784 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004785 if (Catch.get() != S->getCatchStmt(I))
4786 AnyCatchChanged = true;
4787 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004788 }
Sean Huntc3021132010-05-05 15:23:54 +00004789
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004790 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00004791 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004792 if (S->getFinallyStmt()) {
4793 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4794 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004795 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004796 }
4797
4798 // If nothing changed, just retain this statement.
4799 if (!getDerived().AlwaysRebuild() &&
4800 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004801 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004802 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004803 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004804
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004805 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00004806 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4807 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004808}
Mike Stump1eb44332009-09-09 15:08:12 +00004809
Douglas Gregor43959a92009-08-20 07:17:43 +00004810template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004811StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004812TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004813 // Transform the @catch parameter, if there is one.
4814 VarDecl *Var = 0;
4815 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4816 TypeSourceInfo *TSInfo = 0;
4817 if (FromVar->getTypeSourceInfo()) {
4818 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4819 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004820 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004821 }
Sean Huntc3021132010-05-05 15:23:54 +00004822
Douglas Gregorbe270a02010-04-26 17:57:08 +00004823 QualType T;
4824 if (TSInfo)
4825 T = TSInfo->getType();
4826 else {
4827 T = getDerived().TransformType(FromVar->getType());
4828 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004829 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004830 }
Sean Huntc3021132010-05-05 15:23:54 +00004831
Douglas Gregorbe270a02010-04-26 17:57:08 +00004832 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4833 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004834 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004835 }
Sean Huntc3021132010-05-05 15:23:54 +00004836
John McCall60d7b3a2010-08-24 06:29:42 +00004837 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004838 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004839 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004840
4841 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004842 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004843 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004844}
Mike Stump1eb44332009-09-09 15:08:12 +00004845
Douglas Gregor43959a92009-08-20 07:17:43 +00004846template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004847StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004848TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004849 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004850 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004851 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004852 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004853
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004854 // If nothing changed, just retain this statement.
4855 if (!getDerived().AlwaysRebuild() &&
4856 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004857 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004858
4859 // Build a new statement.
4860 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004861 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004862}
Mike Stump1eb44332009-09-09 15:08:12 +00004863
Douglas Gregor43959a92009-08-20 07:17:43 +00004864template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004865StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004866TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004867 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004868 if (S->getThrowExpr()) {
4869 Operand = getDerived().TransformExpr(S->getThrowExpr());
4870 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004871 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004872 }
Sean Huntc3021132010-05-05 15:23:54 +00004873
Douglas Gregord1377b22010-04-22 21:44:01 +00004874 if (!getDerived().AlwaysRebuild() &&
4875 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004876 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004877
John McCall9ae2f072010-08-23 23:25:46 +00004878 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004879}
Mike Stump1eb44332009-09-09 15:08:12 +00004880
Douglas Gregor43959a92009-08-20 07:17:43 +00004881template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004882StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004883TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004884 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004885 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004886 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004887 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004888 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004889
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004890 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004891 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004892 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004893 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004894
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004895 // If nothing change, just retain the current statement.
4896 if (!getDerived().AlwaysRebuild() &&
4897 Object.get() == S->getSynchExpr() &&
4898 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004899 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004900
4901 // Build a new statement.
4902 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004903 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004904}
4905
4906template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004907StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004908TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004909 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004910 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004911 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004912 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004913 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004914
Douglas Gregorc3203e72010-04-22 23:10:45 +00004915 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00004916 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004917 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004918 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004919
Douglas Gregorc3203e72010-04-22 23:10:45 +00004920 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004921 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004922 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004923 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004924
Douglas Gregorc3203e72010-04-22 23:10:45 +00004925 // If nothing changed, just retain this statement.
4926 if (!getDerived().AlwaysRebuild() &&
4927 Element.get() == S->getElement() &&
4928 Collection.get() == S->getCollection() &&
4929 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004930 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004931
Douglas Gregorc3203e72010-04-22 23:10:45 +00004932 // Build a new statement.
4933 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4934 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004935 Element.get(),
4936 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00004937 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004938 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004939}
4940
4941
4942template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004943StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004944TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4945 // Transform the exception declaration, if any.
4946 VarDecl *Var = 0;
4947 if (S->getExceptionDecl()) {
4948 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00004949 TypeSourceInfo *T = getDerived().TransformType(
4950 ExceptionDecl->getTypeSourceInfo());
4951 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00004952 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004953
Douglas Gregor83cb9422010-09-09 17:09:21 +00004954 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00004955 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00004956 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00004957 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00004958 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004959 }
Mike Stump1eb44332009-09-09 15:08:12 +00004960
Douglas Gregor43959a92009-08-20 07:17:43 +00004961 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00004962 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004963 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004964 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004965
Douglas Gregor43959a92009-08-20 07:17:43 +00004966 if (!getDerived().AlwaysRebuild() &&
4967 !Var &&
4968 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00004969 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004970
4971 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4972 Var,
John McCall9ae2f072010-08-23 23:25:46 +00004973 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004974}
Mike Stump1eb44332009-09-09 15:08:12 +00004975
Douglas Gregor43959a92009-08-20 07:17:43 +00004976template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004977StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004978TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4979 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004980 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004981 = getDerived().TransformCompoundStmt(S->getTryBlock());
4982 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004983 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004984
Douglas Gregor43959a92009-08-20 07:17:43 +00004985 // Transform the handlers.
4986 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004987 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00004988 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004989 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004990 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4991 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004992 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004993
Douglas Gregor43959a92009-08-20 07:17:43 +00004994 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4995 Handlers.push_back(Handler.takeAs<Stmt>());
4996 }
Mike Stump1eb44332009-09-09 15:08:12 +00004997
Douglas Gregor43959a92009-08-20 07:17:43 +00004998 if (!getDerived().AlwaysRebuild() &&
4999 TryBlock.get() == S->getTryBlock() &&
5000 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005001 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00005002
John McCall9ae2f072010-08-23 23:25:46 +00005003 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00005004 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00005005}
Mike Stump1eb44332009-09-09 15:08:12 +00005006
Douglas Gregor43959a92009-08-20 07:17:43 +00005007//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00005008// Expression transformation
5009//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00005010template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005011ExprResult
John McCall454feb92009-12-08 09:21:05 +00005012TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005013 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005014}
Mike Stump1eb44332009-09-09 15:08:12 +00005015
5016template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005017ExprResult
John McCall454feb92009-12-08 09:21:05 +00005018TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00005019 NestedNameSpecifier *Qualifier = 0;
5020 if (E->getQualifier()) {
5021 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005022 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00005023 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005024 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005025 }
John McCalldbd872f2009-12-08 09:08:17 +00005026
5027 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005028 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5029 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005030 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005031 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005032
John McCallec8045d2010-08-17 21:27:17 +00005033 DeclarationNameInfo NameInfo = E->getNameInfo();
5034 if (NameInfo.getName()) {
5035 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5036 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005037 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005038 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005039
5040 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005041 Qualifier == E->getQualifier() &&
5042 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005043 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005044 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005045
5046 // Mark it referenced in the new context regardless.
5047 // FIXME: this is a bit instantiation-specific.
5048 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5049
John McCall3fa5cae2010-10-26 07:05:15 +00005050 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005051 }
John McCalldbd872f2009-12-08 09:08:17 +00005052
5053 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005054 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005055 TemplateArgs = &TransArgs;
5056 TransArgs.setLAngleLoc(E->getLAngleLoc());
5057 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005058 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5059 E->getNumTemplateArgs(),
5060 TransArgs))
5061 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005062 }
5063
Douglas Gregora2813ce2009-10-23 18:54:35 +00005064 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005065 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005066}
Mike Stump1eb44332009-09-09 15:08:12 +00005067
Douglas Gregorb98b1992009-08-11 05:31:07 +00005068template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005069ExprResult
John McCall454feb92009-12-08 09:21:05 +00005070TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005071 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005072}
Mike Stump1eb44332009-09-09 15:08:12 +00005073
Douglas Gregorb98b1992009-08-11 05:31:07 +00005074template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005075ExprResult
John McCall454feb92009-12-08 09:21:05 +00005076TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005077 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005078}
Mike Stump1eb44332009-09-09 15:08:12 +00005079
Douglas Gregorb98b1992009-08-11 05:31:07 +00005080template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005081ExprResult
John McCall454feb92009-12-08 09:21:05 +00005082TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005083 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005084}
Mike Stump1eb44332009-09-09 15:08:12 +00005085
Douglas Gregorb98b1992009-08-11 05:31:07 +00005086template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005087ExprResult
John McCall454feb92009-12-08 09:21:05 +00005088TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005089 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005090}
Mike Stump1eb44332009-09-09 15:08:12 +00005091
Douglas Gregorb98b1992009-08-11 05:31:07 +00005092template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005093ExprResult
John McCall454feb92009-12-08 09:21:05 +00005094TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005095 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005096}
5097
5098template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005099ExprResult
John McCall454feb92009-12-08 09:21:05 +00005100TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005101 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005102 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005103 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005104
Douglas Gregorb98b1992009-08-11 05:31:07 +00005105 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005106 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005107
John McCall9ae2f072010-08-23 23:25:46 +00005108 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005109 E->getRParen());
5110}
5111
Mike Stump1eb44332009-09-09 15:08:12 +00005112template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005113ExprResult
John McCall454feb92009-12-08 09:21:05 +00005114TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005115 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005116 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005117 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005118
Douglas Gregorb98b1992009-08-11 05:31:07 +00005119 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005120 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005121
Douglas Gregorb98b1992009-08-11 05:31:07 +00005122 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5123 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005124 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005125}
Mike Stump1eb44332009-09-09 15:08:12 +00005126
Douglas Gregorb98b1992009-08-11 05:31:07 +00005127template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005128ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005129TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5130 // Transform the type.
5131 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5132 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005133 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005134
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005135 // Transform all of the components into components similar to what the
5136 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005137 // FIXME: It would be slightly more efficient in the non-dependent case to
5138 // just map FieldDecls, rather than requiring the rebuilder to look for
5139 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005140 // template code that we don't care.
5141 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005142 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005143 typedef OffsetOfExpr::OffsetOfNode Node;
5144 llvm::SmallVector<Component, 4> Components;
5145 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5146 const Node &ON = E->getComponent(I);
5147 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005148 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005149 Comp.LocStart = ON.getRange().getBegin();
5150 Comp.LocEnd = ON.getRange().getEnd();
5151 switch (ON.getKind()) {
5152 case Node::Array: {
5153 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005154 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005155 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005156 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005157
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005158 ExprChanged = ExprChanged || Index.get() != FromIndex;
5159 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005160 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005161 break;
5162 }
Sean Huntc3021132010-05-05 15:23:54 +00005163
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005164 case Node::Field:
5165 case Node::Identifier:
5166 Comp.isBrackets = false;
5167 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005168 if (!Comp.U.IdentInfo)
5169 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005170
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005171 break;
Sean Huntc3021132010-05-05 15:23:54 +00005172
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005173 case Node::Base:
5174 // Will be recomputed during the rebuild.
5175 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005176 }
Sean Huntc3021132010-05-05 15:23:54 +00005177
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005178 Components.push_back(Comp);
5179 }
Sean Huntc3021132010-05-05 15:23:54 +00005180
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005181 // If nothing changed, retain the existing expression.
5182 if (!getDerived().AlwaysRebuild() &&
5183 Type == E->getTypeSourceInfo() &&
5184 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005185 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00005186
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005187 // Build a new offsetof expression.
5188 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5189 Components.data(), Components.size(),
5190 E->getRParenLoc());
5191}
5192
5193template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005194ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00005195TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5196 assert(getDerived().AlreadyTransformed(E->getType()) &&
5197 "opaque value expression requires transformation");
5198 return SemaRef.Owned(E);
5199}
5200
5201template<typename Derived>
5202ExprResult
John McCall454feb92009-12-08 09:21:05 +00005203TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005204 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00005205 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00005206
John McCalla93c9342009-12-07 02:54:59 +00005207 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00005208 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005209 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005210
John McCall5ab75172009-11-04 07:28:41 +00005211 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00005212 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005213
John McCall5ab75172009-11-04 07:28:41 +00005214 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005215 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005216 E->getSourceRange());
5217 }
Mike Stump1eb44332009-09-09 15:08:12 +00005218
John McCall60d7b3a2010-08-24 06:29:42 +00005219 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00005220 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005221 // C++0x [expr.sizeof]p1:
5222 // The operand is either an expression, which is an unevaluated operand
5223 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00005224 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005225
Douglas Gregorb98b1992009-08-11 05:31:07 +00005226 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5227 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005228 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005229
Douglas Gregorb98b1992009-08-11 05:31:07 +00005230 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005231 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005232 }
Mike Stump1eb44332009-09-09 15:08:12 +00005233
John McCall9ae2f072010-08-23 23:25:46 +00005234 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005235 E->isSizeOf(),
5236 E->getSourceRange());
5237}
Mike Stump1eb44332009-09-09 15:08:12 +00005238
Douglas Gregorb98b1992009-08-11 05:31:07 +00005239template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005240ExprResult
John McCall454feb92009-12-08 09:21:05 +00005241TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005242 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005243 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005244 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005245
John McCall60d7b3a2010-08-24 06:29:42 +00005246 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005247 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005248 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005249
5250
Douglas Gregorb98b1992009-08-11 05:31:07 +00005251 if (!getDerived().AlwaysRebuild() &&
5252 LHS.get() == E->getLHS() &&
5253 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005254 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005255
John McCall9ae2f072010-08-23 23:25:46 +00005256 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005257 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005258 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005259 E->getRBracketLoc());
5260}
Mike Stump1eb44332009-09-09 15:08:12 +00005261
5262template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005263ExprResult
John McCall454feb92009-12-08 09:21:05 +00005264TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005265 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00005266 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005267 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005268 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005269
5270 // Transform arguments.
5271 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005272 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005273 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5274 &ArgChanged))
5275 return ExprError();
5276
Douglas Gregorb98b1992009-08-11 05:31:07 +00005277 if (!getDerived().AlwaysRebuild() &&
5278 Callee.get() == E->getCallee() &&
5279 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005280 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005281
Douglas Gregorb98b1992009-08-11 05:31:07 +00005282 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00005283 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005284 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00005285 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005286 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005287 E->getRParenLoc());
5288}
Mike Stump1eb44332009-09-09 15:08:12 +00005289
5290template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005291ExprResult
John McCall454feb92009-12-08 09:21:05 +00005292TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005293 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005294 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005295 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005296
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005297 NestedNameSpecifier *Qualifier = 0;
5298 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00005299 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005300 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005301 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00005302 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00005303 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005304 }
Mike Stump1eb44332009-09-09 15:08:12 +00005305
Eli Friedmanf595cc42009-12-04 06:40:45 +00005306 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005307 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5308 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005309 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00005310 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005311
John McCall6bb80172010-03-30 21:47:33 +00005312 NamedDecl *FoundDecl = E->getFoundDecl();
5313 if (FoundDecl == E->getMemberDecl()) {
5314 FoundDecl = Member;
5315 } else {
5316 FoundDecl = cast_or_null<NamedDecl>(
5317 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5318 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00005319 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00005320 }
5321
Douglas Gregorb98b1992009-08-11 05:31:07 +00005322 if (!getDerived().AlwaysRebuild() &&
5323 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005324 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005325 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00005326 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00005327 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00005328
Anders Carlsson1f240322009-12-22 05:24:09 +00005329 // Mark it referenced in the new context regardless.
5330 // FIXME: this is a bit instantiation-specific.
5331 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00005332 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00005333 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005334
John McCalld5532b62009-11-23 01:53:49 +00005335 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00005336 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00005337 TransArgs.setLAngleLoc(E->getLAngleLoc());
5338 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005339 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5340 E->getNumTemplateArgs(),
5341 TransArgs))
5342 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005343 }
Sean Huntc3021132010-05-05 15:23:54 +00005344
Douglas Gregorb98b1992009-08-11 05:31:07 +00005345 // FIXME: Bogus source location for the operator
5346 SourceLocation FakeOperatorLoc
5347 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5348
John McCallc2233c52010-01-15 08:34:02 +00005349 // FIXME: to do this check properly, we will need to preserve the
5350 // first-qualifier-in-scope here, just in case we had a dependent
5351 // base (and therefore couldn't do the check) and a
5352 // nested-name-qualifier (and therefore could do the lookup).
5353 NamedDecl *FirstQualifierInScope = 0;
5354
John McCall9ae2f072010-08-23 23:25:46 +00005355 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005356 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005357 Qualifier,
5358 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005359 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005360 Member,
John McCall6bb80172010-03-30 21:47:33 +00005361 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00005362 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00005363 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00005364 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005365}
Mike Stump1eb44332009-09-09 15:08:12 +00005366
Douglas Gregorb98b1992009-08-11 05:31:07 +00005367template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005368ExprResult
John McCall454feb92009-12-08 09:21:05 +00005369TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005370 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005371 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005372 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005373
John McCall60d7b3a2010-08-24 06:29:42 +00005374 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005375 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005376 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005377
Douglas Gregorb98b1992009-08-11 05:31:07 +00005378 if (!getDerived().AlwaysRebuild() &&
5379 LHS.get() == E->getLHS() &&
5380 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005381 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005382
Douglas Gregorb98b1992009-08-11 05:31:07 +00005383 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005384 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005385}
5386
Mike Stump1eb44332009-09-09 15:08:12 +00005387template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005388ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005389TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00005390 CompoundAssignOperator *E) {
5391 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005392}
Mike Stump1eb44332009-09-09 15:08:12 +00005393
Douglas Gregorb98b1992009-08-11 05:31:07 +00005394template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005395ExprResult
John McCall454feb92009-12-08 09:21:05 +00005396TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005397 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005398 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005399 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005400
John McCall60d7b3a2010-08-24 06:29:42 +00005401 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005402 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005403 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005404
John McCall60d7b3a2010-08-24 06:29:42 +00005405 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005406 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005407 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005408
Douglas Gregorb98b1992009-08-11 05:31:07 +00005409 if (!getDerived().AlwaysRebuild() &&
5410 Cond.get() == E->getCond() &&
5411 LHS.get() == E->getLHS() &&
5412 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005413 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005414
John McCall9ae2f072010-08-23 23:25:46 +00005415 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005416 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005417 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005418 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005419 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005420}
Mike Stump1eb44332009-09-09 15:08:12 +00005421
5422template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005423ExprResult
John McCall454feb92009-12-08 09:21:05 +00005424TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005425 // Implicit casts are eliminated during transformation, since they
5426 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00005427 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005428}
Mike Stump1eb44332009-09-09 15:08:12 +00005429
Douglas Gregorb98b1992009-08-11 05:31:07 +00005430template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005431ExprResult
John McCall454feb92009-12-08 09:21:05 +00005432TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005433 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5434 if (!Type)
5435 return ExprError();
5436
John McCall60d7b3a2010-08-24 06:29:42 +00005437 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005438 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005439 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005440 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005441
Douglas Gregorb98b1992009-08-11 05:31:07 +00005442 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005443 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005444 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005445 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005446
John McCall9d125032010-01-15 18:39:57 +00005447 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005448 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005449 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005450 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005451}
Mike Stump1eb44332009-09-09 15:08:12 +00005452
Douglas Gregorb98b1992009-08-11 05:31:07 +00005453template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005454ExprResult
John McCall454feb92009-12-08 09:21:05 +00005455TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00005456 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5457 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5458 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005459 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005460
John McCall60d7b3a2010-08-24 06:29:42 +00005461 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005462 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005463 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005464
Douglas Gregorb98b1992009-08-11 05:31:07 +00005465 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00005466 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005467 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00005468 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005469
John McCall1d7d8d62010-01-19 22:33:45 +00005470 // Note: the expression type doesn't necessarily match the
5471 // type-as-written, but that's okay, because it should always be
5472 // derivable from the initializer.
5473
John McCall42f56b52010-01-18 19:35:47 +00005474 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005475 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00005476 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005477}
Mike Stump1eb44332009-09-09 15:08:12 +00005478
Douglas Gregorb98b1992009-08-11 05:31:07 +00005479template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005480ExprResult
John McCall454feb92009-12-08 09:21:05 +00005481TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005482 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005483 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005484 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005485
Douglas Gregorb98b1992009-08-11 05:31:07 +00005486 if (!getDerived().AlwaysRebuild() &&
5487 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00005488 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005489
Douglas Gregorb98b1992009-08-11 05:31:07 +00005490 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00005491 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005492 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00005493 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005494 E->getAccessorLoc(),
5495 E->getAccessor());
5496}
Mike Stump1eb44332009-09-09 15:08:12 +00005497
Douglas Gregorb98b1992009-08-11 05:31:07 +00005498template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005499ExprResult
John McCall454feb92009-12-08 09:21:05 +00005500TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005501 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00005502
John McCallca0408f2010-08-23 06:44:23 +00005503 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005504 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5505 Inits, &InitChanged))
5506 return ExprError();
5507
Douglas Gregorb98b1992009-08-11 05:31:07 +00005508 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005509 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005510
Douglas Gregorb98b1992009-08-11 05:31:07 +00005511 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00005512 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005513}
Mike Stump1eb44332009-09-09 15:08:12 +00005514
Douglas Gregorb98b1992009-08-11 05:31:07 +00005515template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005516ExprResult
John McCall454feb92009-12-08 09:21:05 +00005517TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005518 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00005519
Douglas Gregor43959a92009-08-20 07:17:43 +00005520 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00005521 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005522 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005523 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005524
Douglas Gregor43959a92009-08-20 07:17:43 +00005525 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00005526 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005527 bool ExprChanged = false;
5528 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5529 DEnd = E->designators_end();
5530 D != DEnd; ++D) {
5531 if (D->isFieldDesignator()) {
5532 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5533 D->getDotLoc(),
5534 D->getFieldLoc()));
5535 continue;
5536 }
Mike Stump1eb44332009-09-09 15:08:12 +00005537
Douglas Gregorb98b1992009-08-11 05:31:07 +00005538 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00005539 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005540 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005541 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005542
5543 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005544 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005545
Douglas Gregorb98b1992009-08-11 05:31:07 +00005546 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5547 ArrayExprs.push_back(Index.release());
5548 continue;
5549 }
Mike Stump1eb44332009-09-09 15:08:12 +00005550
Douglas Gregorb98b1992009-08-11 05:31:07 +00005551 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00005552 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00005553 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5554 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005555 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005556
John McCall60d7b3a2010-08-24 06:29:42 +00005557 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005558 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005559 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005560
5561 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005562 End.get(),
5563 D->getLBracketLoc(),
5564 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005565
Douglas Gregorb98b1992009-08-11 05:31:07 +00005566 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5567 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00005568
Douglas Gregorb98b1992009-08-11 05:31:07 +00005569 ArrayExprs.push_back(Start.release());
5570 ArrayExprs.push_back(End.release());
5571 }
Mike Stump1eb44332009-09-09 15:08:12 +00005572
Douglas Gregorb98b1992009-08-11 05:31:07 +00005573 if (!getDerived().AlwaysRebuild() &&
5574 Init.get() == E->getInit() &&
5575 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005576 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005577
Douglas Gregorb98b1992009-08-11 05:31:07 +00005578 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5579 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005580 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005581}
Mike Stump1eb44332009-09-09 15:08:12 +00005582
Douglas Gregorb98b1992009-08-11 05:31:07 +00005583template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005584ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005585TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00005586 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00005587 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00005588
Douglas Gregor5557b252009-10-28 00:29:27 +00005589 // FIXME: Will we ever have proper type location here? Will we actually
5590 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00005591 QualType T = getDerived().TransformType(E->getType());
5592 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005593 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005594
Douglas Gregorb98b1992009-08-11 05:31:07 +00005595 if (!getDerived().AlwaysRebuild() &&
5596 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005597 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005598
Douglas Gregorb98b1992009-08-11 05:31:07 +00005599 return getDerived().RebuildImplicitValueInitExpr(T);
5600}
Mike Stump1eb44332009-09-09 15:08:12 +00005601
Douglas Gregorb98b1992009-08-11 05:31:07 +00005602template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005603ExprResult
John McCall454feb92009-12-08 09:21:05 +00005604TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00005605 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5606 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005607 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005608
John McCall60d7b3a2010-08-24 06:29:42 +00005609 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005610 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005611 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005612
Douglas Gregorb98b1992009-08-11 05:31:07 +00005613 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005614 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005615 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005616 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005617
John McCall9ae2f072010-08-23 23:25:46 +00005618 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005619 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005620}
5621
5622template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005623ExprResult
John McCall454feb92009-12-08 09:21:05 +00005624TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005625 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005626 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005627 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5628 &ArgumentChanged))
5629 return ExprError();
5630
Douglas Gregorb98b1992009-08-11 05:31:07 +00005631 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5632 move_arg(Inits),
5633 E->getRParenLoc());
5634}
Mike Stump1eb44332009-09-09 15:08:12 +00005635
Douglas Gregorb98b1992009-08-11 05:31:07 +00005636/// \brief Transform an address-of-label expression.
5637///
5638/// By default, the transformation of an address-of-label expression always
5639/// rebuilds the expression, so that the label identifier can be resolved to
5640/// the corresponding label statement by semantic analysis.
5641template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005642ExprResult
John McCall454feb92009-12-08 09:21:05 +00005643TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005644 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5645 E->getLabel());
5646}
Mike Stump1eb44332009-09-09 15:08:12 +00005647
5648template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005649ExprResult
John McCall454feb92009-12-08 09:21:05 +00005650TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005651 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00005652 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5653 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005654 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005655
Douglas Gregorb98b1992009-08-11 05:31:07 +00005656 if (!getDerived().AlwaysRebuild() &&
5657 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005658 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005659
5660 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005661 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005662 E->getRParenLoc());
5663}
Mike Stump1eb44332009-09-09 15:08:12 +00005664
Douglas Gregorb98b1992009-08-11 05:31:07 +00005665template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005666ExprResult
John McCall454feb92009-12-08 09:21:05 +00005667TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005668 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005669 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005670 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005671
John McCall60d7b3a2010-08-24 06:29:42 +00005672 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005673 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005674 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005675
John McCall60d7b3a2010-08-24 06:29:42 +00005676 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005677 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005678 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005679
Douglas Gregorb98b1992009-08-11 05:31:07 +00005680 if (!getDerived().AlwaysRebuild() &&
5681 Cond.get() == E->getCond() &&
5682 LHS.get() == E->getLHS() &&
5683 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005684 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005685
Douglas Gregorb98b1992009-08-11 05:31:07 +00005686 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005687 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005688 E->getRParenLoc());
5689}
Mike Stump1eb44332009-09-09 15:08:12 +00005690
Douglas Gregorb98b1992009-08-11 05:31:07 +00005691template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005692ExprResult
John McCall454feb92009-12-08 09:21:05 +00005693TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005694 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005695}
5696
5697template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005698ExprResult
John McCall454feb92009-12-08 09:21:05 +00005699TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00005700 switch (E->getOperator()) {
5701 case OO_New:
5702 case OO_Delete:
5703 case OO_Array_New:
5704 case OO_Array_Delete:
5705 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00005706 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005707
Douglas Gregor668d6d92009-12-13 20:44:55 +00005708 case OO_Call: {
5709 // This is a call to an object's operator().
5710 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5711
5712 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005713 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005714 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005715 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005716
5717 // FIXME: Poor location information
5718 SourceLocation FakeLParenLoc
5719 = SemaRef.PP.getLocForEndOfToken(
5720 static_cast<Expr *>(Object.get())->getLocEnd());
5721
5722 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00005723 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005724 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5725 Args))
5726 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005727
John McCall9ae2f072010-08-23 23:25:46 +00005728 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00005729 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00005730 E->getLocEnd());
5731 }
5732
5733#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5734 case OO_##Name:
5735#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5736#include "clang/Basic/OperatorKinds.def"
5737 case OO_Subscript:
5738 // Handled below.
5739 break;
5740
5741 case OO_Conditional:
5742 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00005743 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005744
5745 case OO_None:
5746 case NUM_OVERLOADED_OPERATORS:
5747 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00005748 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005749 }
5750
John McCall60d7b3a2010-08-24 06:29:42 +00005751 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005752 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005753 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005754
John McCall60d7b3a2010-08-24 06:29:42 +00005755 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005756 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005757 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005758
John McCall60d7b3a2010-08-24 06:29:42 +00005759 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005760 if (E->getNumArgs() == 2) {
5761 Second = getDerived().TransformExpr(E->getArg(1));
5762 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005763 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005764 }
Mike Stump1eb44332009-09-09 15:08:12 +00005765
Douglas Gregorb98b1992009-08-11 05:31:07 +00005766 if (!getDerived().AlwaysRebuild() &&
5767 Callee.get() == E->getCallee() &&
5768 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005769 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00005770 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005771
Douglas Gregorb98b1992009-08-11 05:31:07 +00005772 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5773 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005774 Callee.get(),
5775 First.get(),
5776 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005777}
Mike Stump1eb44332009-09-09 15:08:12 +00005778
Douglas Gregorb98b1992009-08-11 05:31:07 +00005779template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005780ExprResult
John McCall454feb92009-12-08 09:21:05 +00005781TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5782 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005783}
Mike Stump1eb44332009-09-09 15:08:12 +00005784
Douglas Gregorb98b1992009-08-11 05:31:07 +00005785template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005786ExprResult
John McCall454feb92009-12-08 09:21:05 +00005787TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005788 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5789 if (!Type)
5790 return ExprError();
5791
John McCall60d7b3a2010-08-24 06:29:42 +00005792 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005793 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005794 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005795 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005796
Douglas Gregorb98b1992009-08-11 05:31:07 +00005797 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005798 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005799 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005800 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005801
Douglas Gregorb98b1992009-08-11 05:31:07 +00005802 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005803 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005804 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5805 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5806 SourceLocation FakeRParenLoc
5807 = SemaRef.PP.getLocForEndOfToken(
5808 E->getSubExpr()->getSourceRange().getEnd());
5809 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005810 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005811 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005812 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005813 FakeRAngleLoc,
5814 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005815 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005816 FakeRParenLoc);
5817}
Mike Stump1eb44332009-09-09 15:08:12 +00005818
Douglas Gregorb98b1992009-08-11 05:31:07 +00005819template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005820ExprResult
John McCall454feb92009-12-08 09:21:05 +00005821TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5822 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005823}
Mike Stump1eb44332009-09-09 15:08:12 +00005824
5825template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005826ExprResult
John McCall454feb92009-12-08 09:21:05 +00005827TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5828 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005829}
5830
Douglas Gregorb98b1992009-08-11 05:31:07 +00005831template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005832ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005833TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005834 CXXReinterpretCastExpr *E) {
5835 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005836}
Mike Stump1eb44332009-09-09 15:08:12 +00005837
Douglas Gregorb98b1992009-08-11 05:31:07 +00005838template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005839ExprResult
John McCall454feb92009-12-08 09:21:05 +00005840TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5841 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005842}
Mike Stump1eb44332009-09-09 15:08:12 +00005843
Douglas Gregorb98b1992009-08-11 05:31:07 +00005844template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005845ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005846TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005847 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005848 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5849 if (!Type)
5850 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005851
John McCall60d7b3a2010-08-24 06:29:42 +00005852 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005853 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005854 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005855 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005856
Douglas Gregorb98b1992009-08-11 05:31:07 +00005857 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005858 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005859 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005860 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005861
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005862 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005863 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005864 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005865 E->getRParenLoc());
5866}
Mike Stump1eb44332009-09-09 15:08:12 +00005867
Douglas Gregorb98b1992009-08-11 05:31:07 +00005868template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005869ExprResult
John McCall454feb92009-12-08 09:21:05 +00005870TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005871 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005872 TypeSourceInfo *TInfo
5873 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5874 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005875 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005876
Douglas Gregorb98b1992009-08-11 05:31:07 +00005877 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005878 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005879 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005880
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005881 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5882 E->getLocStart(),
5883 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005884 E->getLocEnd());
5885 }
Mike Stump1eb44332009-09-09 15:08:12 +00005886
Douglas Gregorb98b1992009-08-11 05:31:07 +00005887 // We don't know whether the expression is potentially evaluated until
5888 // after we perform semantic analysis, so the expression is potentially
5889 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005890 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00005891 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005892
John McCall60d7b3a2010-08-24 06:29:42 +00005893 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005894 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005895 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005896
Douglas Gregorb98b1992009-08-11 05:31:07 +00005897 if (!getDerived().AlwaysRebuild() &&
5898 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005899 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005900
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005901 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5902 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005903 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005904 E->getLocEnd());
5905}
5906
5907template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005908ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00005909TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5910 if (E->isTypeOperand()) {
5911 TypeSourceInfo *TInfo
5912 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5913 if (!TInfo)
5914 return ExprError();
5915
5916 if (!getDerived().AlwaysRebuild() &&
5917 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005918 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005919
5920 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5921 E->getLocStart(),
5922 TInfo,
5923 E->getLocEnd());
5924 }
5925
5926 // We don't know whether the expression is potentially evaluated until
5927 // after we perform semantic analysis, so the expression is potentially
5928 // potentially evaluated.
5929 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5930
5931 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5932 if (SubExpr.isInvalid())
5933 return ExprError();
5934
5935 if (!getDerived().AlwaysRebuild() &&
5936 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005937 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005938
5939 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5940 E->getLocStart(),
5941 SubExpr.get(),
5942 E->getLocEnd());
5943}
5944
5945template<typename Derived>
5946ExprResult
John McCall454feb92009-12-08 09:21:05 +00005947TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005948 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005949}
Mike Stump1eb44332009-09-09 15:08:12 +00005950
Douglas Gregorb98b1992009-08-11 05:31:07 +00005951template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005952ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005953TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005954 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005955 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005956}
Mike Stump1eb44332009-09-09 15:08:12 +00005957
Douglas Gregorb98b1992009-08-11 05:31:07 +00005958template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005959ExprResult
John McCall454feb92009-12-08 09:21:05 +00005960TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005961 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5962 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5963 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00005964
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005965 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005966 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005967
Douglas Gregor828a1972010-01-07 23:12:05 +00005968 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005969}
Mike Stump1eb44332009-09-09 15:08:12 +00005970
Douglas Gregorb98b1992009-08-11 05:31:07 +00005971template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005972ExprResult
John McCall454feb92009-12-08 09:21:05 +00005973TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005974 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005975 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005976 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005977
Douglas Gregorb98b1992009-08-11 05:31:07 +00005978 if (!getDerived().AlwaysRebuild() &&
5979 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005980 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005981
John McCall9ae2f072010-08-23 23:25:46 +00005982 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005983}
Mike Stump1eb44332009-09-09 15:08:12 +00005984
Douglas Gregorb98b1992009-08-11 05:31:07 +00005985template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005986ExprResult
John McCall454feb92009-12-08 09:21:05 +00005987TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005988 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005989 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5990 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005991 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00005992 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005993
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005994 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005995 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00005996 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005997
Douglas Gregor036aed12009-12-23 23:03:06 +00005998 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005999}
Mike Stump1eb44332009-09-09 15:08:12 +00006000
Douglas Gregorb98b1992009-08-11 05:31:07 +00006001template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006002ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00006003TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6004 CXXScalarValueInitExpr *E) {
6005 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6006 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006007 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00006008
Douglas Gregorb98b1992009-08-11 05:31:07 +00006009 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006010 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006011 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006012
Douglas Gregorab6677e2010-09-08 00:15:04 +00006013 return getDerived().RebuildCXXScalarValueInitExpr(T,
6014 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006015 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006016}
Mike Stump1eb44332009-09-09 15:08:12 +00006017
Douglas Gregorb98b1992009-08-11 05:31:07 +00006018template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006019ExprResult
John McCall454feb92009-12-08 09:21:05 +00006020TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006021 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006022 TypeSourceInfo *AllocTypeInfo
6023 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6024 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006025 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006026
Douglas Gregorb98b1992009-08-11 05:31:07 +00006027 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006028 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006029 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006030 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006031
Douglas Gregorb98b1992009-08-11 05:31:07 +00006032 // Transform the placement arguments (if any).
6033 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006034 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006035 if (getDerived().TransformExprs(E->getPlacementArgs(),
6036 E->getNumPlacementArgs(), true,
6037 PlacementArgs, &ArgumentChanged))
6038 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006039
Douglas Gregor43959a92009-08-20 07:17:43 +00006040 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00006041 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006042 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6043 ConstructorArgs, &ArgumentChanged))
6044 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006045
Douglas Gregor1af74512010-02-26 00:38:10 +00006046 // Transform constructor, new operator, and delete operator.
6047 CXXConstructorDecl *Constructor = 0;
6048 if (E->getConstructor()) {
6049 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006050 getDerived().TransformDecl(E->getLocStart(),
6051 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006052 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006053 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006054 }
6055
6056 FunctionDecl *OperatorNew = 0;
6057 if (E->getOperatorNew()) {
6058 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006059 getDerived().TransformDecl(E->getLocStart(),
6060 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006061 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006062 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006063 }
6064
6065 FunctionDecl *OperatorDelete = 0;
6066 if (E->getOperatorDelete()) {
6067 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006068 getDerived().TransformDecl(E->getLocStart(),
6069 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006070 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006071 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006072 }
Sean Huntc3021132010-05-05 15:23:54 +00006073
Douglas Gregorb98b1992009-08-11 05:31:07 +00006074 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006075 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006076 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006077 Constructor == E->getConstructor() &&
6078 OperatorNew == E->getOperatorNew() &&
6079 OperatorDelete == E->getOperatorDelete() &&
6080 !ArgumentChanged) {
6081 // Mark any declarations we need as referenced.
6082 // FIXME: instantiation-specific.
6083 if (Constructor)
6084 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6085 if (OperatorNew)
6086 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6087 if (OperatorDelete)
6088 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00006089 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006090 }
Mike Stump1eb44332009-09-09 15:08:12 +00006091
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006092 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006093 if (!ArraySize.get()) {
6094 // If no array size was specified, but the new expression was
6095 // instantiated with an array type (e.g., "new T" where T is
6096 // instantiated with "int[4]"), extract the outer bound from the
6097 // array type as our array size. We do this with constant and
6098 // dependently-sized array types.
6099 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6100 if (!ArrayT) {
6101 // Do nothing
6102 } else if (const ConstantArrayType *ConsArrayT
6103 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00006104 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006105 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6106 ConsArrayT->getSize(),
6107 SemaRef.Context.getSizeType(),
6108 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006109 AllocType = ConsArrayT->getElementType();
6110 } else if (const DependentSizedArrayType *DepArrayT
6111 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6112 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00006113 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006114 AllocType = DepArrayT->getElementType();
6115 }
6116 }
6117 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006118
Douglas Gregorb98b1992009-08-11 05:31:07 +00006119 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6120 E->isGlobalNew(),
6121 /*FIXME:*/E->getLocStart(),
6122 move_arg(PlacementArgs),
6123 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00006124 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006125 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006126 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00006127 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006128 /*FIXME:*/E->getLocStart(),
6129 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00006130 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006131}
Mike Stump1eb44332009-09-09 15:08:12 +00006132
Douglas Gregorb98b1992009-08-11 05:31:07 +00006133template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006134ExprResult
John McCall454feb92009-12-08 09:21:05 +00006135TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006136 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006137 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006138 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006139
Douglas Gregor1af74512010-02-26 00:38:10 +00006140 // Transform the delete operator, if known.
6141 FunctionDecl *OperatorDelete = 0;
6142 if (E->getOperatorDelete()) {
6143 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006144 getDerived().TransformDecl(E->getLocStart(),
6145 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006146 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006147 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006148 }
Sean Huntc3021132010-05-05 15:23:54 +00006149
Douglas Gregorb98b1992009-08-11 05:31:07 +00006150 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006151 Operand.get() == E->getArgument() &&
6152 OperatorDelete == E->getOperatorDelete()) {
6153 // Mark any declarations we need as referenced.
6154 // FIXME: instantiation-specific.
6155 if (OperatorDelete)
6156 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00006157
6158 if (!E->getArgument()->isTypeDependent()) {
6159 QualType Destroyed = SemaRef.Context.getBaseElementType(
6160 E->getDestroyedType());
6161 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6162 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6163 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6164 SemaRef.LookupDestructor(Record));
6165 }
6166 }
6167
John McCall3fa5cae2010-10-26 07:05:15 +00006168 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006169 }
Mike Stump1eb44332009-09-09 15:08:12 +00006170
Douglas Gregorb98b1992009-08-11 05:31:07 +00006171 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6172 E->isGlobalDelete(),
6173 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00006174 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006175}
Mike Stump1eb44332009-09-09 15:08:12 +00006176
Douglas Gregorb98b1992009-08-11 05:31:07 +00006177template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006178ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00006179TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00006180 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006181 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00006182 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006183 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006184
John McCallb3d87482010-08-24 05:47:05 +00006185 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006186 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006187 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006188 E->getOperatorLoc(),
6189 E->isArrow()? tok::arrow : tok::period,
6190 ObjectTypePtr,
6191 MayBePseudoDestructor);
6192 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006193 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006194
John McCallb3d87482010-08-24 05:47:05 +00006195 QualType ObjectType = ObjectTypePtr.get();
John McCall43fed0d2010-11-12 08:19:04 +00006196 NestedNameSpecifier *Qualifier = E->getQualifier();
6197 if (Qualifier) {
6198 Qualifier
6199 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6200 E->getQualifierRange(),
6201 ObjectType);
6202 if (!Qualifier)
6203 return ExprError();
6204 }
Mike Stump1eb44332009-09-09 15:08:12 +00006205
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006206 PseudoDestructorTypeStorage Destroyed;
6207 if (E->getDestroyedTypeInfo()) {
6208 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00006209 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6210 ObjectType, 0, Qualifier);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006211 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006212 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006213 Destroyed = DestroyedTypeInfo;
6214 } else if (ObjectType->isDependentType()) {
6215 // We aren't likely to be able to resolve the identifier down to a type
6216 // now anyway, so just retain the identifier.
6217 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6218 E->getDestroyedTypeLoc());
6219 } else {
6220 // Look for a destructor known with the given name.
6221 CXXScopeSpec SS;
6222 if (Qualifier) {
6223 SS.setScopeRep(Qualifier);
6224 SS.setRange(E->getQualifierRange());
6225 }
Sean Huntc3021132010-05-05 15:23:54 +00006226
John McCallb3d87482010-08-24 05:47:05 +00006227 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006228 *E->getDestroyedTypeIdentifier(),
6229 E->getDestroyedTypeLoc(),
6230 /*Scope=*/0,
6231 SS, ObjectTypePtr,
6232 false);
6233 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006234 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006235
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006236 Destroyed
6237 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6238 E->getDestroyedTypeLoc());
6239 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006240
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006241 TypeSourceInfo *ScopeTypeInfo = 0;
6242 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00006243 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006244 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006245 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00006246 }
Sean Huntc3021132010-05-05 15:23:54 +00006247
John McCall9ae2f072010-08-23 23:25:46 +00006248 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006249 E->getOperatorLoc(),
6250 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006251 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006252 E->getQualifierRange(),
6253 ScopeTypeInfo,
6254 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006255 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006256 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00006257}
Mike Stump1eb44332009-09-09 15:08:12 +00006258
Douglas Gregora71d8192009-09-04 17:36:40 +00006259template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006260ExprResult
John McCallba135432009-11-21 08:51:07 +00006261TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00006262 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00006263 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6264
6265 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6266 Sema::LookupOrdinaryName);
6267
6268 // Transform all the decls.
6269 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6270 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006271 NamedDecl *InstD = static_cast<NamedDecl*>(
6272 getDerived().TransformDecl(Old->getNameLoc(),
6273 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006274 if (!InstD) {
6275 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6276 // This can happen because of dependent hiding.
6277 if (isa<UsingShadowDecl>(*I))
6278 continue;
6279 else
John McCallf312b1e2010-08-26 23:41:50 +00006280 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006281 }
John McCallf7a1a742009-11-24 19:00:30 +00006282
6283 // Expand using declarations.
6284 if (isa<UsingDecl>(InstD)) {
6285 UsingDecl *UD = cast<UsingDecl>(InstD);
6286 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6287 E = UD->shadow_end(); I != E; ++I)
6288 R.addDecl(*I);
6289 continue;
6290 }
6291
6292 R.addDecl(InstD);
6293 }
6294
6295 // Resolve a kind, but don't do any further analysis. If it's
6296 // ambiguous, the callee needs to deal with it.
6297 R.resolveKind();
6298
6299 // Rebuild the nested-name qualifier, if present.
6300 CXXScopeSpec SS;
6301 NestedNameSpecifier *Qualifier = 0;
6302 if (Old->getQualifier()) {
6303 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006304 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00006305 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006306 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006307
John McCallf7a1a742009-11-24 19:00:30 +00006308 SS.setScopeRep(Qualifier);
6309 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00006310 }
6311
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006312 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00006313 CXXRecordDecl *NamingClass
6314 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6315 Old->getNameLoc(),
6316 Old->getNamingClass()));
6317 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006318 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006319
Douglas Gregor66c45152010-04-27 16:10:10 +00006320 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00006321 }
6322
6323 // If we have no template arguments, it's a normal declaration name.
6324 if (!Old->hasExplicitTemplateArgs())
6325 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6326
6327 // If we have template arguments, rebuild them, then rebuild the
6328 // templateid expression.
6329 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006330 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6331 Old->getNumTemplateArgs(),
6332 TransArgs))
6333 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00006334
6335 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6336 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006337}
Mike Stump1eb44332009-09-09 15:08:12 +00006338
Douglas Gregorb98b1992009-08-11 05:31:07 +00006339template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006340ExprResult
John McCall454feb92009-12-08 09:21:05 +00006341TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006342 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6343 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006344 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006345
Douglas Gregorb98b1992009-08-11 05:31:07 +00006346 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006347 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006348 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006349
Mike Stump1eb44332009-09-09 15:08:12 +00006350 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006351 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006352 T,
6353 E->getLocEnd());
6354}
Mike Stump1eb44332009-09-09 15:08:12 +00006355
Douglas Gregorb98b1992009-08-11 05:31:07 +00006356template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006357ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00006358TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6359 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6360 if (!LhsT)
6361 return ExprError();
6362
6363 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6364 if (!RhsT)
6365 return ExprError();
6366
6367 if (!getDerived().AlwaysRebuild() &&
6368 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6369 return SemaRef.Owned(E);
6370
6371 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6372 E->getLocStart(),
6373 LhsT, RhsT,
6374 E->getLocEnd());
6375}
6376
6377template<typename Derived>
6378ExprResult
John McCall865d4472009-11-19 22:55:06 +00006379TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006380 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006381 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00006382 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006383 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006384 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00006385 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006386
John McCall43fed0d2010-11-12 08:19:04 +00006387 // TODO: If this is a conversion-function-id, verify that the
6388 // destination type name (if present) resolves the same way after
6389 // instantiation as it did in the local scope.
6390
Abramo Bagnara25777432010-08-11 22:01:17 +00006391 DeclarationNameInfo NameInfo
6392 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6393 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006394 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006395
John McCallf7a1a742009-11-24 19:00:30 +00006396 if (!E->hasExplicitTemplateArgs()) {
6397 if (!getDerived().AlwaysRebuild() &&
6398 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006399 // Note: it is sufficient to compare the Name component of NameInfo:
6400 // if name has not changed, DNLoc has not changed either.
6401 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00006402 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006403
John McCallf7a1a742009-11-24 19:00:30 +00006404 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6405 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006406 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006407 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00006408 }
John McCalld5532b62009-11-23 01:53:49 +00006409
6410 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006411 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6412 E->getNumTemplateArgs(),
6413 TransArgs))
6414 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006415
John McCallf7a1a742009-11-24 19:00:30 +00006416 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6417 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006418 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006419 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006420}
6421
6422template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006423ExprResult
John McCall454feb92009-12-08 09:21:05 +00006424TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00006425 // CXXConstructExprs are always implicit, so when we have a
6426 // 1-argument construction we just transform that argument.
6427 if (E->getNumArgs() == 1 ||
6428 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6429 return getDerived().TransformExpr(E->getArg(0));
6430
Douglas Gregorb98b1992009-08-11 05:31:07 +00006431 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6432
6433 QualType T = getDerived().TransformType(E->getType());
6434 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006435 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006436
6437 CXXConstructorDecl *Constructor
6438 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006439 getDerived().TransformDecl(E->getLocStart(),
6440 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006441 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006442 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006443
Douglas Gregorb98b1992009-08-11 05:31:07 +00006444 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006445 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006446 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6447 &ArgumentChanged))
6448 return ExprError();
6449
Douglas Gregorb98b1992009-08-11 05:31:07 +00006450 if (!getDerived().AlwaysRebuild() &&
6451 T == E->getType() &&
6452 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00006453 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00006454 // Mark the constructor as referenced.
6455 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00006456 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006457 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00006458 }
Mike Stump1eb44332009-09-09 15:08:12 +00006459
Douglas Gregor4411d2e2009-12-14 16:27:04 +00006460 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6461 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00006462 move_arg(Args),
6463 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00006464 E->getConstructionKind(),
6465 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006466}
Mike Stump1eb44332009-09-09 15:08:12 +00006467
Douglas Gregorb98b1992009-08-11 05:31:07 +00006468/// \brief Transform a C++ temporary-binding expression.
6469///
Douglas Gregor51326552009-12-24 18:51:59 +00006470/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6471/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006472template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006473ExprResult
John McCall454feb92009-12-08 09:21:05 +00006474TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006475 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006476}
Mike Stump1eb44332009-09-09 15:08:12 +00006477
John McCall4765fa02010-12-06 08:20:24 +00006478/// \brief Transform a C++ expression that contains cleanups that should
6479/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006480///
John McCall4765fa02010-12-06 08:20:24 +00006481/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00006482/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006483template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006484ExprResult
John McCall4765fa02010-12-06 08:20:24 +00006485TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006486 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006487}
Mike Stump1eb44332009-09-09 15:08:12 +00006488
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006490ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006491TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00006492 CXXTemporaryObjectExpr *E) {
6493 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6494 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006495 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006496
Douglas Gregorb98b1992009-08-11 05:31:07 +00006497 CXXConstructorDecl *Constructor
6498 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00006499 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006500 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006501 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006502 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006503
Douglas Gregorb98b1992009-08-11 05:31:07 +00006504 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006505 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006506 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00006507 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6508 &ArgumentChanged))
6509 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006510
Douglas Gregorb98b1992009-08-11 05:31:07 +00006511 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006512 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006513 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00006514 !ArgumentChanged) {
6515 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00006516 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006517 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00006518 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00006519
6520 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6521 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006522 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006523 E->getLocEnd());
6524}
Mike Stump1eb44332009-09-09 15:08:12 +00006525
Douglas Gregorb98b1992009-08-11 05:31:07 +00006526template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006527ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006528TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00006529 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00006530 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6531 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006532 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006533
Douglas Gregorb98b1992009-08-11 05:31:07 +00006534 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006535 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006536 Args.reserve(E->arg_size());
6537 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6538 &ArgumentChanged))
6539 return ExprError();
6540
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006542 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006543 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006544 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006545
Douglas Gregorb98b1992009-08-11 05:31:07 +00006546 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00006547 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006548 E->getLParenLoc(),
6549 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006550 E->getRParenLoc());
6551}
Mike Stump1eb44332009-09-09 15:08:12 +00006552
Douglas Gregorb98b1992009-08-11 05:31:07 +00006553template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006554ExprResult
John McCall865d4472009-11-19 22:55:06 +00006555TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006556 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006557 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006558 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006559 Expr *OldBase;
6560 QualType BaseType;
6561 QualType ObjectType;
6562 if (!E->isImplicitAccess()) {
6563 OldBase = E->getBase();
6564 Base = getDerived().TransformExpr(OldBase);
6565 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006566 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006567
John McCallaa81e162009-12-01 22:10:20 +00006568 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00006569 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00006570 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006571 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006572 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006573 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00006574 ObjectTy,
6575 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00006576 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006577 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006578
John McCallb3d87482010-08-24 05:47:05 +00006579 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00006580 BaseType = ((Expr*) Base.get())->getType();
6581 } else {
6582 OldBase = 0;
6583 BaseType = getDerived().TransformType(E->getBaseType());
6584 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6585 }
Mike Stump1eb44332009-09-09 15:08:12 +00006586
Douglas Gregor6cd21982009-10-20 05:58:46 +00006587 // Transform the first part of the nested-name-specifier that qualifies
6588 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00006589 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00006590 = getDerived().TransformFirstQualifierInScope(
6591 E->getFirstQualifierFoundInScope(),
6592 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006593
Douglas Gregora38c6872009-09-03 16:14:30 +00006594 NestedNameSpecifier *Qualifier = 0;
6595 if (E->getQualifier()) {
6596 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6597 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00006598 ObjectType,
6599 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00006600 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006601 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00006602 }
Mike Stump1eb44332009-09-09 15:08:12 +00006603
John McCall43fed0d2010-11-12 08:19:04 +00006604 // TODO: If this is a conversion-function-id, verify that the
6605 // destination type name (if present) resolves the same way after
6606 // instantiation as it did in the local scope.
6607
Abramo Bagnara25777432010-08-11 22:01:17 +00006608 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00006609 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00006610 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006611 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006612
John McCallaa81e162009-12-01 22:10:20 +00006613 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006614 // This is a reference to a member without an explicitly-specified
6615 // template argument list. Optimize for this common case.
6616 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00006617 Base.get() == OldBase &&
6618 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006619 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006620 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006621 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00006622 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006623
John McCall9ae2f072010-08-23 23:25:46 +00006624 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006625 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006626 E->isArrow(),
6627 E->getOperatorLoc(),
6628 Qualifier,
6629 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00006630 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006631 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006632 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006633 }
6634
John McCalld5532b62009-11-23 01:53:49 +00006635 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006636 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6637 E->getNumTemplateArgs(),
6638 TransArgs))
6639 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006640
John McCall9ae2f072010-08-23 23:25:46 +00006641 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006642 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006643 E->isArrow(),
6644 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006645 Qualifier,
6646 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006647 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006648 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006649 &TransArgs);
6650}
6651
6652template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006653ExprResult
John McCall454feb92009-12-08 09:21:05 +00006654TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00006655 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006656 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006657 QualType BaseType;
6658 if (!Old->isImplicitAccess()) {
6659 Base = getDerived().TransformExpr(Old->getBase());
6660 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006661 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006662 BaseType = ((Expr*) Base.get())->getType();
6663 } else {
6664 BaseType = getDerived().TransformType(Old->getBaseType());
6665 }
John McCall129e2df2009-11-30 22:42:35 +00006666
6667 NestedNameSpecifier *Qualifier = 0;
6668 if (Old->getQualifier()) {
6669 Qualifier
6670 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006671 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00006672 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00006673 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006674 }
6675
Abramo Bagnara25777432010-08-11 22:01:17 +00006676 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00006677 Sema::LookupOrdinaryName);
6678
6679 // Transform all the decls.
6680 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6681 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006682 NamedDecl *InstD = static_cast<NamedDecl*>(
6683 getDerived().TransformDecl(Old->getMemberLoc(),
6684 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006685 if (!InstD) {
6686 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6687 // This can happen because of dependent hiding.
6688 if (isa<UsingShadowDecl>(*I))
6689 continue;
6690 else
John McCallf312b1e2010-08-26 23:41:50 +00006691 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006692 }
John McCall129e2df2009-11-30 22:42:35 +00006693
6694 // Expand using declarations.
6695 if (isa<UsingDecl>(InstD)) {
6696 UsingDecl *UD = cast<UsingDecl>(InstD);
6697 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6698 E = UD->shadow_end(); I != E; ++I)
6699 R.addDecl(*I);
6700 continue;
6701 }
6702
6703 R.addDecl(InstD);
6704 }
6705
6706 R.resolveKind();
6707
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006708 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00006709 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00006710 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006711 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00006712 Old->getMemberLoc(),
6713 Old->getNamingClass()));
6714 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006715 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006716
Douglas Gregor66c45152010-04-27 16:10:10 +00006717 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006718 }
Sean Huntc3021132010-05-05 15:23:54 +00006719
John McCall129e2df2009-11-30 22:42:35 +00006720 TemplateArgumentListInfo TransArgs;
6721 if (Old->hasExplicitTemplateArgs()) {
6722 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6723 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006724 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6725 Old->getNumTemplateArgs(),
6726 TransArgs))
6727 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006728 }
John McCallc2233c52010-01-15 08:34:02 +00006729
6730 // FIXME: to do this check properly, we will need to preserve the
6731 // first-qualifier-in-scope here, just in case we had a dependent
6732 // base (and therefore couldn't do the check) and a
6733 // nested-name-qualifier (and therefore could do the lookup).
6734 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006735
John McCall9ae2f072010-08-23 23:25:46 +00006736 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006737 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006738 Old->getOperatorLoc(),
6739 Old->isArrow(),
6740 Qualifier,
6741 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006742 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006743 R,
6744 (Old->hasExplicitTemplateArgs()
6745 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006746}
6747
6748template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006749ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006750TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6751 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6752 if (SubExpr.isInvalid())
6753 return ExprError();
6754
6755 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006756 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00006757
6758 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6759}
6760
6761template<typename Derived>
6762ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00006763TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
6764 llvm_unreachable("pack expansion expression in unhandled context");
6765 return ExprError();
6766}
Douglas Gregoree8aff02011-01-04 17:33:58 +00006767
6768template<typename Derived>
6769ExprResult
6770TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6771 // If E is not value-dependent, then nothing will change when we transform it.
6772 // Note: This is an instantiation-centric view.
6773 if (!E->isValueDependent())
6774 return SemaRef.Owned(E);
6775
6776 // Note: None of the implementations of TryExpandParameterPacks can ever
6777 // produce a diagnostic when given only a single unexpanded parameter pack,
6778 // so
6779 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6780 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00006781 bool RetainExpansion = false;
Douglas Gregoree8aff02011-01-04 17:33:58 +00006782 unsigned NumExpansions = 0;
6783 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6784 &Unexpanded, 1,
Douglas Gregord3731192011-01-10 07:32:04 +00006785 ShouldExpand, RetainExpansion,
6786 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00006787 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00006788
Douglas Gregord3731192011-01-10 07:32:04 +00006789 if (!ShouldExpand || RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00006790 return SemaRef.Owned(E);
6791
6792 // We now know the length of the parameter pack, so build a new expression
6793 // that stores that length.
6794 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6795 E->getPackLoc(), E->getRParenLoc(),
6796 NumExpansions);
6797}
6798
Douglas Gregorbe230c32011-01-03 17:17:50 +00006799template<typename Derived>
6800ExprResult
John McCall454feb92009-12-08 09:21:05 +00006801TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006802 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006803}
6804
Mike Stump1eb44332009-09-09 15:08:12 +00006805template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006806ExprResult
John McCall454feb92009-12-08 09:21:05 +00006807TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006808 TypeSourceInfo *EncodedTypeInfo
6809 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6810 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006811 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006812
Douglas Gregorb98b1992009-08-11 05:31:07 +00006813 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006814 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006815 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006816
6817 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006818 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006819 E->getRParenLoc());
6820}
Mike Stump1eb44332009-09-09 15:08:12 +00006821
Douglas Gregorb98b1992009-08-11 05:31:07 +00006822template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006823ExprResult
John McCall454feb92009-12-08 09:21:05 +00006824TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006825 // Transform arguments.
6826 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006827 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006828 Args.reserve(E->getNumArgs());
6829 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6830 &ArgChanged))
6831 return ExprError();
6832
Douglas Gregor92e986e2010-04-22 16:44:27 +00006833 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6834 // Class message: transform the receiver type.
6835 TypeSourceInfo *ReceiverTypeInfo
6836 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6837 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006838 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006839
Douglas Gregor92e986e2010-04-22 16:44:27 +00006840 // If nothing changed, just retain the existing message send.
6841 if (!getDerived().AlwaysRebuild() &&
6842 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006843 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006844
6845 // Build a new class message send.
6846 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6847 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006848 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006849 E->getMethodDecl(),
6850 E->getLeftLoc(),
6851 move_arg(Args),
6852 E->getRightLoc());
6853 }
6854
6855 // Instance message: transform the receiver
6856 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6857 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006858 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006859 = getDerived().TransformExpr(E->getInstanceReceiver());
6860 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006861 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006862
6863 // If nothing changed, just retain the existing message send.
6864 if (!getDerived().AlwaysRebuild() &&
6865 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006866 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006867
Douglas Gregor92e986e2010-04-22 16:44:27 +00006868 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006869 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006870 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006871 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006872 E->getMethodDecl(),
6873 E->getLeftLoc(),
6874 move_arg(Args),
6875 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006876}
6877
Mike Stump1eb44332009-09-09 15:08:12 +00006878template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006879ExprResult
John McCall454feb92009-12-08 09:21:05 +00006880TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006881 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006882}
6883
Mike Stump1eb44332009-09-09 15:08:12 +00006884template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006885ExprResult
John McCall454feb92009-12-08 09:21:05 +00006886TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006887 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006888}
6889
Mike Stump1eb44332009-09-09 15:08:12 +00006890template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006891ExprResult
John McCall454feb92009-12-08 09:21:05 +00006892TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006893 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006894 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006895 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006896 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006897
6898 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006899
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006900 // If nothing changed, just retain the existing expression.
6901 if (!getDerived().AlwaysRebuild() &&
6902 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006903 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006904
John McCall9ae2f072010-08-23 23:25:46 +00006905 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006906 E->getLocation(),
6907 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006908}
6909
Mike Stump1eb44332009-09-09 15:08:12 +00006910template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006911ExprResult
John McCall454feb92009-12-08 09:21:05 +00006912TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00006913 // 'super' and types never change. Property never changes. Just
6914 // retain the existing expression.
6915 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00006916 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006917
Douglas Gregore3303542010-04-26 20:47:02 +00006918 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006919 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00006920 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006921 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006922
Douglas Gregore3303542010-04-26 20:47:02 +00006923 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006924
Douglas Gregore3303542010-04-26 20:47:02 +00006925 // If nothing changed, just retain the existing expression.
6926 if (!getDerived().AlwaysRebuild() &&
6927 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006928 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006929
John McCall12f78a62010-12-02 01:19:52 +00006930 if (E->isExplicitProperty())
6931 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6932 E->getExplicitProperty(),
6933 E->getLocation());
6934
6935 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6936 E->getType(),
6937 E->getImplicitPropertyGetter(),
6938 E->getImplicitPropertySetter(),
6939 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006940}
6941
Mike Stump1eb44332009-09-09 15:08:12 +00006942template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006943ExprResult
John McCall454feb92009-12-08 09:21:05 +00006944TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006945 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006946 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006947 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006948 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006949
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006950 // If nothing changed, just retain the existing expression.
6951 if (!getDerived().AlwaysRebuild() &&
6952 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006953 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006954
John McCall9ae2f072010-08-23 23:25:46 +00006955 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006956 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006957}
6958
Mike Stump1eb44332009-09-09 15:08:12 +00006959template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006960ExprResult
John McCall454feb92009-12-08 09:21:05 +00006961TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006962 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006963 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006964 SubExprs.reserve(E->getNumSubExprs());
6965 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
6966 SubExprs, &ArgumentChanged))
6967 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006968
Douglas Gregorb98b1992009-08-11 05:31:07 +00006969 if (!getDerived().AlwaysRebuild() &&
6970 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006971 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006972
Douglas Gregorb98b1992009-08-11 05:31:07 +00006973 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6974 move_arg(SubExprs),
6975 E->getRParenLoc());
6976}
6977
Mike Stump1eb44332009-09-09 15:08:12 +00006978template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006979ExprResult
John McCall454feb92009-12-08 09:21:05 +00006980TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006981 SourceLocation CaretLoc(E->getExprLoc());
6982
6983 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6984 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6985 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6986 llvm::SmallVector<ParmVarDecl*, 4> Params;
6987 llvm::SmallVector<QualType, 4> ParamTypes;
6988
6989 // Parameter substitution.
Douglas Gregor12c9c002011-01-07 16:43:16 +00006990 // FIXME: Variadic templates
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006991 const BlockDecl *BD = E->getBlockDecl();
6992 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6993 EN = BD->param_end(); P != EN; ++P) {
6994 ParmVarDecl *OldParm = (*P);
6995 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6996 QualType NewType = NewParm->getType();
6997 Params.push_back(NewParm);
6998 ParamTypes.push_back(NewParm->getType());
6999 }
7000
7001 const FunctionType *BExprFunctionType = E->getFunctionType();
7002 QualType BExprResultType = BExprFunctionType->getResultType();
7003 if (!BExprResultType.isNull()) {
7004 if (!BExprResultType->isDependentType())
7005 CurBlock->ReturnType = BExprResultType;
7006 else if (BExprResultType != SemaRef.Context.DependentTy)
7007 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
7008 }
John McCall711c52b2011-01-05 12:14:39 +00007009
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007010 QualType FunctionType = getDerived().RebuildFunctionProtoType(
7011 CurBlock->ReturnType,
7012 ParamTypes.data(),
7013 ParamTypes.size(),
7014 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00007015 0,
7016 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007017 CurBlock->FunctionType = FunctionType;
John McCall711c52b2011-01-05 12:14:39 +00007018
7019 // Set the parameters on the block decl.
7020 if (!Params.empty())
7021 CurBlock->TheDecl->setParams(Params.data(), Params.size());
7022
7023 // Transform the body
7024 StmtResult Body = getDerived().TransformStmt(E->getBody());
7025 if (Body.isInvalid())
7026 return ExprError();
7027
John McCall9ae2f072010-08-23 23:25:46 +00007028 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007029}
7030
Mike Stump1eb44332009-09-09 15:08:12 +00007031template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007032ExprResult
John McCall454feb92009-12-08 09:21:05 +00007033TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007034 NestedNameSpecifier *Qualifier = 0;
7035
7036 ValueDecl *ND
7037 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7038 E->getDecl()));
7039 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00007040 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00007041
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007042 if (!getDerived().AlwaysRebuild() &&
7043 ND == E->getDecl()) {
7044 // Mark it referenced in the new context regardless.
7045 // FIXME: this is a bit instantiation-specific.
7046 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7047
John McCall3fa5cae2010-10-26 07:05:15 +00007048 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007049 }
7050
Abramo Bagnara25777432010-08-11 22:01:17 +00007051 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007052 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00007053 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007054}
Mike Stump1eb44332009-09-09 15:08:12 +00007055
Douglas Gregorb98b1992009-08-11 05:31:07 +00007056//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00007057// Type reconstruction
7058//===----------------------------------------------------------------------===//
7059
Mike Stump1eb44332009-09-09 15:08:12 +00007060template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007061QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7062 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007063 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007064 getDerived().getBaseEntity());
7065}
7066
Mike Stump1eb44332009-09-09 15:08:12 +00007067template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007068QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7069 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007070 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007071 getDerived().getBaseEntity());
7072}
7073
Mike Stump1eb44332009-09-09 15:08:12 +00007074template<typename Derived>
7075QualType
John McCall85737a72009-10-30 00:06:24 +00007076TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7077 bool WrittenAsLValue,
7078 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007079 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00007080 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007081}
7082
7083template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007084QualType
John McCall85737a72009-10-30 00:06:24 +00007085TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7086 QualType ClassType,
7087 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007088 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00007089 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007090}
7091
7092template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007093QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00007094TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7095 ArrayType::ArraySizeModifier SizeMod,
7096 const llvm::APInt *Size,
7097 Expr *SizeExpr,
7098 unsigned IndexTypeQuals,
7099 SourceRange BracketsRange) {
7100 if (SizeExpr || !Size)
7101 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7102 IndexTypeQuals, BracketsRange,
7103 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00007104
7105 QualType Types[] = {
7106 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7107 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7108 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00007109 };
7110 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7111 QualType SizeType;
7112 for (unsigned I = 0; I != NumTypes; ++I)
7113 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7114 SizeType = Types[I];
7115 break;
7116 }
Mike Stump1eb44332009-09-09 15:08:12 +00007117
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007118 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7119 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00007120 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007121 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00007122 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007123}
Mike Stump1eb44332009-09-09 15:08:12 +00007124
Douglas Gregor577f75a2009-08-04 16:50:30 +00007125template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007126QualType
7127TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007128 ArrayType::ArraySizeModifier SizeMod,
7129 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00007130 unsigned IndexTypeQuals,
7131 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007132 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00007133 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007134}
7135
7136template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007137QualType
Mike Stump1eb44332009-09-09 15:08:12 +00007138TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007139 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00007140 unsigned IndexTypeQuals,
7141 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007142 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00007143 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007144}
Mike Stump1eb44332009-09-09 15:08:12 +00007145
Douglas Gregor577f75a2009-08-04 16:50:30 +00007146template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007147QualType
7148TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007149 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007150 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007151 unsigned IndexTypeQuals,
7152 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007153 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007154 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007155 IndexTypeQuals, BracketsRange);
7156}
7157
7158template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007159QualType
7160TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007161 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007162 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007163 unsigned IndexTypeQuals,
7164 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007165 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007166 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007167 IndexTypeQuals, BracketsRange);
7168}
7169
7170template<typename Derived>
7171QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00007172 unsigned NumElements,
7173 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00007174 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00007175 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007176}
Mike Stump1eb44332009-09-09 15:08:12 +00007177
Douglas Gregor577f75a2009-08-04 16:50:30 +00007178template<typename Derived>
7179QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7180 unsigned NumElements,
7181 SourceLocation AttributeLoc) {
7182 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7183 NumElements, true);
7184 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007185 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7186 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00007187 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007188}
Mike Stump1eb44332009-09-09 15:08:12 +00007189
Douglas Gregor577f75a2009-08-04 16:50:30 +00007190template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007191QualType
7192TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00007193 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007194 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00007195 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007196}
Mike Stump1eb44332009-09-09 15:08:12 +00007197
Douglas Gregor577f75a2009-08-04 16:50:30 +00007198template<typename Derived>
7199QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00007200 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007201 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00007202 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00007203 unsigned Quals,
7204 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00007205 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007206 Quals,
7207 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00007208 getDerived().getBaseEntity(),
7209 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007210}
Mike Stump1eb44332009-09-09 15:08:12 +00007211
Douglas Gregor577f75a2009-08-04 16:50:30 +00007212template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00007213QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7214 return SemaRef.Context.getFunctionNoProtoType(T);
7215}
7216
7217template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00007218QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7219 assert(D && "no decl found");
7220 if (D->isInvalidDecl()) return QualType();
7221
Douglas Gregor92e986e2010-04-22 16:44:27 +00007222 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00007223 TypeDecl *Ty;
7224 if (isa<UsingDecl>(D)) {
7225 UsingDecl *Using = cast<UsingDecl>(D);
7226 assert(Using->isTypeName() &&
7227 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7228
7229 // A valid resolved using typename decl points to exactly one type decl.
7230 assert(++Using->shadow_begin() == Using->shadow_end());
7231 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00007232
John McCalled976492009-12-04 22:46:56 +00007233 } else {
7234 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7235 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7236 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7237 }
7238
7239 return SemaRef.Context.getTypeDeclType(Ty);
7240}
7241
7242template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007243QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7244 SourceLocation Loc) {
7245 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007246}
7247
7248template<typename Derived>
7249QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7250 return SemaRef.Context.getTypeOfType(Underlying);
7251}
7252
7253template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007254QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7255 SourceLocation Loc) {
7256 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007257}
7258
7259template<typename Derived>
7260QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00007261 TemplateName Template,
7262 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00007263 const TemplateArgumentListInfo &TemplateArgs) {
7264 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007265}
Mike Stump1eb44332009-09-09 15:08:12 +00007266
Douglas Gregordcee1a12009-08-06 05:28:30 +00007267template<typename Derived>
7268NestedNameSpecifier *
7269TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7270 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00007271 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007272 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00007273 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00007274 CXXScopeSpec SS;
7275 // FIXME: The source location information is all wrong.
7276 SS.setRange(Range);
7277 SS.setScopeRep(Prefix);
7278 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00007279 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00007280 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007281 ObjectType,
7282 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00007283 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00007284}
7285
7286template<typename Derived>
7287NestedNameSpecifier *
7288TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7289 SourceRange Range,
7290 NamespaceDecl *NS) {
7291 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7292}
7293
7294template<typename Derived>
7295NestedNameSpecifier *
7296TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7297 SourceRange Range,
7298 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00007299 QualType T) {
7300 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00007301 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00007302 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00007303 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7304 T.getTypePtr());
7305 }
Mike Stump1eb44332009-09-09 15:08:12 +00007306
Douglas Gregordcee1a12009-08-06 05:28:30 +00007307 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7308 return 0;
7309}
Mike Stump1eb44332009-09-09 15:08:12 +00007310
Douglas Gregord1067e52009-08-06 06:41:21 +00007311template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007312TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007313TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7314 bool TemplateKW,
7315 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00007316 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00007317 Template);
7318}
7319
7320template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007321TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007322TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007323 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007324 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +00007325 QualType ObjectType,
7326 NamedDecl *FirstQualifierInScope) {
Douglas Gregord1067e52009-08-06 06:41:21 +00007327 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007328 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00007329 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00007330 UnqualifiedId Name;
7331 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00007332 Sema::TemplateTy Template;
7333 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7334 /*FIXME:*/getDerived().getBaseLocation(),
7335 SS,
7336 Name,
John McCallb3d87482010-08-24 05:47:05 +00007337 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007338 /*EnteringContext=*/false,
7339 Template);
John McCall43fed0d2010-11-12 08:19:04 +00007340 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00007341}
Mike Stump1eb44332009-09-09 15:08:12 +00007342
Douglas Gregorb98b1992009-08-11 05:31:07 +00007343template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007344TemplateName
7345TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7346 OverloadedOperatorKind Operator,
7347 QualType ObjectType) {
7348 CXXScopeSpec SS;
7349 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7350 SS.setScopeRep(Qualifier);
7351 UnqualifiedId Name;
7352 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7353 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7354 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00007355 Sema::TemplateTy Template;
7356 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007357 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007358 SS,
7359 Name,
John McCallb3d87482010-08-24 05:47:05 +00007360 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007361 /*EnteringContext=*/false,
7362 Template);
7363 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007364}
Sean Huntc3021132010-05-05 15:23:54 +00007365
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007366template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007367ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007368TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7369 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007370 Expr *OrigCallee,
7371 Expr *First,
7372 Expr *Second) {
7373 Expr *Callee = OrigCallee->IgnoreParenCasts();
7374 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00007375
Douglas Gregorb98b1992009-08-11 05:31:07 +00007376 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00007377 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00007378 if (!First->getType()->isOverloadableType() &&
7379 !Second->getType()->isOverloadableType())
7380 return getSema().CreateBuiltinArraySubscriptExpr(First,
7381 Callee->getLocStart(),
7382 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00007383 } else if (Op == OO_Arrow) {
7384 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00007385 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7386 } else if (Second == 0 || isPostIncDec) {
7387 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007388 // The argument is not of overloadable type, so try to create a
7389 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00007390 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007391 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00007392
John McCall9ae2f072010-08-23 23:25:46 +00007393 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007394 }
7395 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007396 if (!First->getType()->isOverloadableType() &&
7397 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007398 // Neither of the arguments is an overloadable type, so try to
7399 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00007400 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007401 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00007402 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007403 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007404 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007405
Douglas Gregorb98b1992009-08-11 05:31:07 +00007406 return move(Result);
7407 }
7408 }
Mike Stump1eb44332009-09-09 15:08:12 +00007409
7410 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00007411 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00007412 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00007413
John McCall9ae2f072010-08-23 23:25:46 +00007414 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00007415 assert(ULE->requiresADL());
7416
7417 // FIXME: Do we have to check
7418 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00007419 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00007420 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007421 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00007422 }
Mike Stump1eb44332009-09-09 15:08:12 +00007423
Douglas Gregorb98b1992009-08-11 05:31:07 +00007424 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00007425 Expr *Args[2] = { First, Second };
7426 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00007427
Douglas Gregorb98b1992009-08-11 05:31:07 +00007428 // Create the overloaded operator invocation for unary operators.
7429 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00007430 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007431 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00007432 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007433 }
Mike Stump1eb44332009-09-09 15:08:12 +00007434
Sebastian Redlf322ed62009-10-29 20:17:01 +00007435 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00007436 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00007437 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007438 First,
7439 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00007440
Douglas Gregorb98b1992009-08-11 05:31:07 +00007441 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00007442 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007443 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00007444 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7445 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007446 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007447
Mike Stump1eb44332009-09-09 15:08:12 +00007448 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007449}
Mike Stump1eb44332009-09-09 15:08:12 +00007450
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007451template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007452ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00007453TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007454 SourceLocation OperatorLoc,
7455 bool isArrow,
7456 NestedNameSpecifier *Qualifier,
7457 SourceRange QualifierRange,
7458 TypeSourceInfo *ScopeType,
7459 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007460 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007461 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007462 CXXScopeSpec SS;
7463 if (Qualifier) {
7464 SS.setRange(QualifierRange);
7465 SS.setScopeRep(Qualifier);
7466 }
7467
John McCall9ae2f072010-08-23 23:25:46 +00007468 QualType BaseType = Base->getType();
7469 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007470 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00007471 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00007472 !BaseType->getAs<PointerType>()->getPointeeType()
7473 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007474 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00007475 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007476 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007477 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007478 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007479 /*FIXME?*/true);
7480 }
Abramo Bagnara25777432010-08-11 22:01:17 +00007481
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007482 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00007483 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7484 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7485 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7486 NameInfo.setNamedTypeInfo(DestroyedType);
7487
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007488 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00007489
John McCall9ae2f072010-08-23 23:25:46 +00007490 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007491 OperatorLoc, isArrow,
7492 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00007493 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007494 /*TemplateArgs*/ 0);
7495}
7496
Douglas Gregor577f75a2009-08-04 16:50:30 +00007497} // end namespace clang
7498
7499#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H