blob: bc1ac1e6ae9b3308bb51297e4452d923a96317f1 [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
2330 if (ArgChanged)
2331 *ArgChanged = true;
2332 Outputs.push_back(Out.get());
2333 }
2334
2335 continue;
2336 }
2337
Douglas Gregoraa165f82011-01-03 19:04:46 +00002338 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2339 if (Result.isInvalid())
2340 return true;
2341
2342 if (Result.get() != Inputs[I] && ArgChanged)
2343 *ArgChanged = true;
2344
2345 Outputs.push_back(Result.get());
2346 }
2347
2348 return false;
2349}
2350
2351template<typename Derived>
Douglas Gregordcee1a12009-08-06 05:28:30 +00002352NestedNameSpecifier *
2353TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregora38c6872009-09-03 16:14:30 +00002354 SourceRange Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002355 QualType ObjectType,
2356 NamedDecl *FirstQualifierInScope) {
John McCall43fed0d2010-11-12 08:19:04 +00002357 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump1eb44332009-09-09 15:08:12 +00002358
Douglas Gregor43959a92009-08-20 07:17:43 +00002359 // Transform the prefix of this nested name specifier.
Douglas Gregordcee1a12009-08-06 05:28:30 +00002360 if (Prefix) {
Mike Stump1eb44332009-09-09 15:08:12 +00002361 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregorc68afe22009-09-03 21:38:09 +00002362 ObjectType,
2363 FirstQualifierInScope);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002364 if (!Prefix)
2365 return 0;
2366 }
Mike Stump1eb44332009-09-09 15:08:12 +00002367
Douglas Gregordcee1a12009-08-06 05:28:30 +00002368 switch (NNS->getKind()) {
2369 case NestedNameSpecifier::Identifier:
John McCall43fed0d2010-11-12 08:19:04 +00002370 if (Prefix) {
2371 // The object type and qualifier-in-scope really apply to the
2372 // leftmost entity.
2373 ObjectType = QualType();
2374 FirstQualifierInScope = 0;
2375 }
2376
Mike Stump1eb44332009-09-09 15:08:12 +00002377 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregora38c6872009-09-03 16:14:30 +00002378 "Identifier nested-name-specifier with no prefix or object type");
2379 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2380 ObjectType.isNull())
Douglas Gregordcee1a12009-08-06 05:28:30 +00002381 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002382
2383 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00002384 *NNS->getAsIdentifier(),
Douglas Gregorc68afe22009-09-03 21:38:09 +00002385 ObjectType,
2386 FirstQualifierInScope);
Mike Stump1eb44332009-09-09 15:08:12 +00002387
Douglas Gregordcee1a12009-08-06 05:28:30 +00002388 case NestedNameSpecifier::Namespace: {
Mike Stump1eb44332009-09-09 15:08:12 +00002389 NamespaceDecl *NS
Douglas Gregordcee1a12009-08-06 05:28:30 +00002390 = cast_or_null<NamespaceDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002391 getDerived().TransformDecl(Range.getBegin(),
2392 NNS->getAsNamespace()));
Mike Stump1eb44332009-09-09 15:08:12 +00002393 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordcee1a12009-08-06 05:28:30 +00002394 Prefix == NNS->getPrefix() &&
2395 NS == NNS->getAsNamespace())
2396 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002397
Douglas Gregordcee1a12009-08-06 05:28:30 +00002398 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2399 }
Mike Stump1eb44332009-09-09 15:08:12 +00002400
Douglas Gregordcee1a12009-08-06 05:28:30 +00002401 case NestedNameSpecifier::Global:
2402 // There is no meaningful transformation that one could perform on the
2403 // global scope.
2404 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002405
Douglas Gregordcee1a12009-08-06 05:28:30 +00002406 case NestedNameSpecifier::TypeSpecWithTemplate:
2407 case NestedNameSpecifier::TypeSpec: {
Douglas Gregorfbf2c942009-10-29 22:21:39 +00002408 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall43fed0d2010-11-12 08:19:04 +00002409 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2410 ObjectType,
2411 FirstQualifierInScope,
2412 Prefix);
Douglas Gregord1067e52009-08-06 06:41:21 +00002413 if (T.isNull())
2414 return 0;
Mike Stump1eb44332009-09-09 15:08:12 +00002415
Douglas Gregordcee1a12009-08-06 05:28:30 +00002416 if (!getDerived().AlwaysRebuild() &&
2417 Prefix == NNS->getPrefix() &&
2418 T == QualType(NNS->getAsType(), 0))
2419 return NNS;
Mike Stump1eb44332009-09-09 15:08:12 +00002420
2421 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2422 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregoredc90502010-02-25 04:46:04 +00002423 T);
Douglas Gregordcee1a12009-08-06 05:28:30 +00002424 }
2425 }
Mike Stump1eb44332009-09-09 15:08:12 +00002426
Douglas Gregordcee1a12009-08-06 05:28:30 +00002427 // Required to silence a GCC warning
Mike Stump1eb44332009-09-09 15:08:12 +00002428 return 0;
Douglas Gregordcee1a12009-08-06 05:28:30 +00002429}
2430
2431template<typename Derived>
Abramo Bagnara25777432010-08-11 22:01:17 +00002432DeclarationNameInfo
2433TreeTransform<Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002434::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnara25777432010-08-11 22:01:17 +00002435 DeclarationName Name = NameInfo.getName();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002436 if (!Name)
Abramo Bagnara25777432010-08-11 22:01:17 +00002437 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002438
2439 switch (Name.getNameKind()) {
2440 case DeclarationName::Identifier:
2441 case DeclarationName::ObjCZeroArgSelector:
2442 case DeclarationName::ObjCOneArgSelector:
2443 case DeclarationName::ObjCMultiArgSelector:
2444 case DeclarationName::CXXOperatorName:
Sean Hunt3e518bd2009-11-29 07:34:05 +00002445 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregor81499bb2009-09-03 22:13:48 +00002446 case DeclarationName::CXXUsingDirective:
Abramo Bagnara25777432010-08-11 22:01:17 +00002447 return NameInfo;
Mike Stump1eb44332009-09-09 15:08:12 +00002448
Douglas Gregor81499bb2009-09-03 22:13:48 +00002449 case DeclarationName::CXXConstructorName:
2450 case DeclarationName::CXXDestructorName:
2451 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnara25777432010-08-11 22:01:17 +00002452 TypeSourceInfo *NewTInfo;
2453 CanQualType NewCanTy;
2454 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00002455 NewTInfo = getDerived().TransformType(OldTInfo);
2456 if (!NewTInfo)
2457 return DeclarationNameInfo();
2458 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002459 }
2460 else {
2461 NewTInfo = 0;
2462 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall43fed0d2010-11-12 08:19:04 +00002463 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnara25777432010-08-11 22:01:17 +00002464 if (NewT.isNull())
2465 return DeclarationNameInfo();
2466 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2467 }
Mike Stump1eb44332009-09-09 15:08:12 +00002468
Abramo Bagnara25777432010-08-11 22:01:17 +00002469 DeclarationName NewName
2470 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2471 NewCanTy);
2472 DeclarationNameInfo NewNameInfo(NameInfo);
2473 NewNameInfo.setName(NewName);
2474 NewNameInfo.setNamedTypeInfo(NewTInfo);
2475 return NewNameInfo;
Douglas Gregor81499bb2009-09-03 22:13:48 +00002476 }
Mike Stump1eb44332009-09-09 15:08:12 +00002477 }
2478
Abramo Bagnara25777432010-08-11 22:01:17 +00002479 assert(0 && "Unknown name kind.");
2480 return DeclarationNameInfo();
Douglas Gregor81499bb2009-09-03 22:13:48 +00002481}
2482
2483template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00002484TemplateName
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00002485TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall43fed0d2010-11-12 08:19:04 +00002486 QualType ObjectType,
2487 NamedDecl *FirstQualifierInScope) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002488 SourceLocation Loc = getDerived().getBaseLocation();
2489
Douglas Gregord1067e52009-08-06 06:41:21 +00002490 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002491 NestedNameSpecifier *NNS
Douglas Gregord1067e52009-08-06 06:41:21 +00002492 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002493 /*FIXME*/ SourceRange(Loc),
2494 ObjectType,
2495 FirstQualifierInScope);
Douglas Gregord1067e52009-08-06 06:41:21 +00002496 if (!NNS)
2497 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002498
Douglas Gregord1067e52009-08-06 06:41:21 +00002499 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002500 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002501 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002502 if (!TransTemplate)
2503 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002504
Douglas Gregord1067e52009-08-06 06:41:21 +00002505 if (!getDerived().AlwaysRebuild() &&
2506 NNS == QTN->getQualifier() &&
2507 TransTemplate == Template)
2508 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002509
Douglas Gregord1067e52009-08-06 06:41:21 +00002510 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2511 TransTemplate);
2512 }
Mike Stump1eb44332009-09-09 15:08:12 +00002513
John McCallf7a1a742009-11-24 19:00:30 +00002514 // These should be getting filtered out before they make it into the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002515 llvm_unreachable("overloaded template name survived to here");
Douglas Gregord1067e52009-08-06 06:41:21 +00002516 }
Mike Stump1eb44332009-09-09 15:08:12 +00002517
Douglas Gregord1067e52009-08-06 06:41:21 +00002518 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall43fed0d2010-11-12 08:19:04 +00002519 NestedNameSpecifier *NNS = DTN->getQualifier();
2520 if (NNS) {
2521 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2522 /*FIXME:*/SourceRange(Loc),
2523 ObjectType,
2524 FirstQualifierInScope);
2525 if (!NNS) return TemplateName();
2526
2527 // These apply to the scope specifier, not the template.
2528 ObjectType = QualType();
2529 FirstQualifierInScope = 0;
2530 }
Mike Stump1eb44332009-09-09 15:08:12 +00002531
Douglas Gregord1067e52009-08-06 06:41:21 +00002532 if (!getDerived().AlwaysRebuild() &&
Douglas Gregordd62b152009-10-19 22:04:39 +00002533 NNS == DTN->getQualifier() &&
2534 ObjectType.isNull())
Douglas Gregord1067e52009-08-06 06:41:21 +00002535 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002536
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002537 if (DTN->isIdentifier()) {
2538 // FIXME: Bad range
2539 SourceRange QualifierRange(getDerived().getBaseLocation());
2540 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2541 *DTN->getIdentifier(),
John McCall43fed0d2010-11-12 08:19:04 +00002542 ObjectType,
2543 FirstQualifierInScope);
Douglas Gregor1efb6c72010-09-08 23:56:00 +00002544 }
Sean Huntc3021132010-05-05 15:23:54 +00002545
2546 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregorca1bdd72009-11-04 00:56:37 +00002547 ObjectType);
Douglas Gregord1067e52009-08-06 06:41:21 +00002548 }
Mike Stump1eb44332009-09-09 15:08:12 +00002549
Douglas Gregord1067e52009-08-06 06:41:21 +00002550 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump1eb44332009-09-09 15:08:12 +00002551 TemplateDecl *TransTemplate
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002552 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregord1067e52009-08-06 06:41:21 +00002553 if (!TransTemplate)
2554 return TemplateName();
Mike Stump1eb44332009-09-09 15:08:12 +00002555
Douglas Gregord1067e52009-08-06 06:41:21 +00002556 if (!getDerived().AlwaysRebuild() &&
2557 TransTemplate == Template)
2558 return Name;
Mike Stump1eb44332009-09-09 15:08:12 +00002559
Douglas Gregord1067e52009-08-06 06:41:21 +00002560 return TemplateName(TransTemplate);
2561 }
Mike Stump1eb44332009-09-09 15:08:12 +00002562
John McCallf7a1a742009-11-24 19:00:30 +00002563 // These should be getting filtered out before they reach the AST.
John McCall43fed0d2010-11-12 08:19:04 +00002564 llvm_unreachable("overloaded function decl survived to here");
John McCallf7a1a742009-11-24 19:00:30 +00002565 return TemplateName();
Douglas Gregord1067e52009-08-06 06:41:21 +00002566}
2567
2568template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00002569void TreeTransform<Derived>::InventTemplateArgumentLoc(
2570 const TemplateArgument &Arg,
2571 TemplateArgumentLoc &Output) {
2572 SourceLocation Loc = getDerived().getBaseLocation();
2573 switch (Arg.getKind()) {
2574 case TemplateArgument::Null:
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002575 llvm_unreachable("null template argument in TreeTransform");
John McCall833ca992009-10-29 08:12:44 +00002576 break;
2577
2578 case TemplateArgument::Type:
2579 Output = TemplateArgumentLoc(Arg,
John McCalla93c9342009-12-07 02:54:59 +00002580 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Sean Huntc3021132010-05-05 15:23:54 +00002581
John McCall833ca992009-10-29 08:12:44 +00002582 break;
2583
Douglas Gregor788cd062009-11-11 01:00:40 +00002584 case TemplateArgument::Template:
2585 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2586 break;
Douglas Gregora7fc9012011-01-05 18:58:31 +00002587
2588 case TemplateArgument::TemplateExpansion:
2589 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2590 break;
2591
John McCall833ca992009-10-29 08:12:44 +00002592 case TemplateArgument::Expression:
2593 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2594 break;
2595
2596 case TemplateArgument::Declaration:
2597 case TemplateArgument::Integral:
2598 case TemplateArgument::Pack:
John McCall828bff22009-10-29 18:45:58 +00002599 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002600 break;
2601 }
2602}
2603
2604template<typename Derived>
2605bool TreeTransform<Derived>::TransformTemplateArgument(
2606 const TemplateArgumentLoc &Input,
2607 TemplateArgumentLoc &Output) {
2608 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregor670444e2009-08-04 22:27:00 +00002609 switch (Arg.getKind()) {
2610 case TemplateArgument::Null:
2611 case TemplateArgument::Integral:
John McCall833ca992009-10-29 08:12:44 +00002612 Output = Input;
2613 return false;
Mike Stump1eb44332009-09-09 15:08:12 +00002614
Douglas Gregor670444e2009-08-04 22:27:00 +00002615 case TemplateArgument::Type: {
John McCalla93c9342009-12-07 02:54:59 +00002616 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall833ca992009-10-29 08:12:44 +00002617 if (DI == NULL)
John McCalla93c9342009-12-07 02:54:59 +00002618 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall833ca992009-10-29 08:12:44 +00002619
2620 DI = getDerived().TransformType(DI);
2621 if (!DI) return true;
2622
2623 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2624 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002625 }
Mike Stump1eb44332009-09-09 15:08:12 +00002626
Douglas Gregor670444e2009-08-04 22:27:00 +00002627 case TemplateArgument::Declaration: {
John McCall833ca992009-10-29 08:12:44 +00002628 // FIXME: we should never have to transform one of these.
Douglas Gregor972e6ce2009-10-27 06:26:26 +00002629 DeclarationName Name;
2630 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2631 Name = ND->getDeclName();
Douglas Gregor788cd062009-11-11 01:00:40 +00002632 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00002633 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall833ca992009-10-29 08:12:44 +00002634 if (!D) return true;
2635
John McCall828bff22009-10-29 18:45:58 +00002636 Expr *SourceExpr = Input.getSourceDeclExpression();
2637 if (SourceExpr) {
2638 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002639 Sema::Unevaluated);
John McCall60d7b3a2010-08-24 06:29:42 +00002640 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCall9ae2f072010-08-23 23:25:46 +00002641 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall828bff22009-10-29 18:45:58 +00002642 }
2643
2644 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall833ca992009-10-29 08:12:44 +00002645 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002646 }
Mike Stump1eb44332009-09-09 15:08:12 +00002647
Douglas Gregor788cd062009-11-11 01:00:40 +00002648 case TemplateArgument::Template: {
Sean Huntc3021132010-05-05 15:23:54 +00002649 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor788cd062009-11-11 01:00:40 +00002650 TemplateName Template
2651 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2652 if (Template.isNull())
2653 return true;
Sean Huntc3021132010-05-05 15:23:54 +00002654
Douglas Gregor788cd062009-11-11 01:00:40 +00002655 Output = TemplateArgumentLoc(TemplateArgument(Template),
2656 Input.getTemplateQualifierRange(),
2657 Input.getTemplateNameLoc());
2658 return false;
2659 }
Douglas Gregora7fc9012011-01-05 18:58:31 +00002660
2661 case TemplateArgument::TemplateExpansion:
2662 llvm_unreachable("Caller should expand pack expansions");
2663
Douglas Gregor670444e2009-08-04 22:27:00 +00002664 case TemplateArgument::Expression: {
2665 // Template argument expressions are not potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00002666 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallf312b1e2010-08-26 23:41:50 +00002667 Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00002668
John McCall833ca992009-10-29 08:12:44 +00002669 Expr *InputExpr = Input.getSourceExpression();
2670 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2671
John McCall60d7b3a2010-08-24 06:29:42 +00002672 ExprResult E
John McCall833ca992009-10-29 08:12:44 +00002673 = getDerived().TransformExpr(InputExpr);
2674 if (E.isInvalid()) return true;
John McCall9ae2f072010-08-23 23:25:46 +00002675 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall833ca992009-10-29 08:12:44 +00002676 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002677 }
Mike Stump1eb44332009-09-09 15:08:12 +00002678
Douglas Gregor670444e2009-08-04 22:27:00 +00002679 case TemplateArgument::Pack: {
2680 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2681 TransformedArgs.reserve(Arg.pack_size());
Mike Stump1eb44332009-09-09 15:08:12 +00002682 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregor670444e2009-08-04 22:27:00 +00002683 AEnd = Arg.pack_end();
2684 A != AEnd; ++A) {
Mike Stump1eb44332009-09-09 15:08:12 +00002685
John McCall833ca992009-10-29 08:12:44 +00002686 // FIXME: preserve source information here when we start
2687 // caring about parameter packs.
2688
John McCall828bff22009-10-29 18:45:58 +00002689 TemplateArgumentLoc InputArg;
2690 TemplateArgumentLoc OutputArg;
2691 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2692 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall833ca992009-10-29 08:12:44 +00002693 return true;
2694
John McCall828bff22009-10-29 18:45:58 +00002695 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregor670444e2009-08-04 22:27:00 +00002696 }
Douglas Gregor910f8002010-11-07 23:05:16 +00002697
2698 TemplateArgument *TransformedArgsPtr
2699 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2700 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2701 TransformedArgsPtr);
2702 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2703 TransformedArgs.size()),
2704 Input.getLocInfo());
John McCall833ca992009-10-29 08:12:44 +00002705 return false;
Douglas Gregor670444e2009-08-04 22:27:00 +00002706 }
2707 }
Mike Stump1eb44332009-09-09 15:08:12 +00002708
Douglas Gregor670444e2009-08-04 22:27:00 +00002709 // Work around bogus GCC warning
John McCall833ca992009-10-29 08:12:44 +00002710 return true;
Douglas Gregor670444e2009-08-04 22:27:00 +00002711}
2712
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002713/// \brief Iterator adaptor that invents template argument location information
2714/// for each of the template arguments in its underlying iterator.
2715template<typename Derived, typename InputIterator>
2716class TemplateArgumentLocInventIterator {
2717 TreeTransform<Derived> &Self;
2718 InputIterator Iter;
2719
2720public:
2721 typedef TemplateArgumentLoc value_type;
2722 typedef TemplateArgumentLoc reference;
2723 typedef typename std::iterator_traits<InputIterator>::difference_type
2724 difference_type;
2725 typedef std::input_iterator_tag iterator_category;
2726
2727 class pointer {
2728 TemplateArgumentLoc Arg;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002729
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002730 public:
2731 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2732
2733 const TemplateArgumentLoc *operator->() const { return &Arg; }
2734 };
2735
2736 TemplateArgumentLocInventIterator() { }
2737
2738 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2739 InputIterator Iter)
2740 : Self(Self), Iter(Iter) { }
2741
2742 TemplateArgumentLocInventIterator &operator++() {
2743 ++Iter;
2744 return *this;
Douglas Gregorfcc12532010-12-20 17:31:10 +00002745 }
2746
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002747 TemplateArgumentLocInventIterator operator++(int) {
2748 TemplateArgumentLocInventIterator Old(*this);
2749 ++(*this);
2750 return Old;
2751 }
2752
2753 reference operator*() const {
2754 TemplateArgumentLoc Result;
2755 Self.InventTemplateArgumentLoc(*Iter, Result);
2756 return Result;
2757 }
2758
2759 pointer operator->() const { return pointer(**this); }
2760
2761 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2762 const TemplateArgumentLocInventIterator &Y) {
2763 return X.Iter == Y.Iter;
2764 }
Douglas Gregorfcc12532010-12-20 17:31:10 +00002765
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002766 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2767 const TemplateArgumentLocInventIterator &Y) {
2768 return X.Iter != Y.Iter;
2769 }
2770};
2771
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002772template<typename Derived>
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002773template<typename InputIterator>
2774bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2775 InputIterator Last,
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002776 TemplateArgumentListInfo &Outputs) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002777 for (; First != Last; ++First) {
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002778 TemplateArgumentLoc Out;
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002779 TemplateArgumentLoc In = *First;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002780
2781 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2782 // Unpack argument packs, which we translate them into separate
2783 // arguments.
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00002784 // FIXME: We could do much better if we could guarantee that the
2785 // TemplateArgumentLocInfo for the pack expansion would be usable for
2786 // all of the template arguments in the argument pack.
2787 typedef TemplateArgumentLocInventIterator<Derived,
2788 TemplateArgument::pack_iterator>
2789 PackLocIterator;
2790 if (TransformTemplateArguments(PackLocIterator(*this,
2791 In.getArgument().pack_begin()),
2792 PackLocIterator(*this,
2793 In.getArgument().pack_end()),
2794 Outputs))
2795 return true;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002796
2797 continue;
2798 }
2799
2800 if (In.getArgument().isPackExpansion()) {
2801 // We have a pack expansion, for which we will be substituting into
2802 // the pattern.
2803 SourceLocation Ellipsis;
2804 TemplateArgumentLoc Pattern
2805 = In.getPackExpansionPattern(Ellipsis, getSema().Context);
2806
2807 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2808 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2809 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2810
2811 // Determine whether the set of unexpanded parameter packs can and should
2812 // be expanded.
2813 bool Expand = true;
Douglas Gregord3731192011-01-10 07:32:04 +00002814 bool RetainExpansion = false;
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002815 unsigned NumExpansions = 0;
2816 if (getDerived().TryExpandParameterPacks(Ellipsis,
2817 Pattern.getSourceRange(),
2818 Unexpanded.data(),
2819 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00002820 Expand,
2821 RetainExpansion,
2822 NumExpansions))
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002823 return true;
2824
2825 if (!Expand) {
2826 // The transform has determined that we should perform a simple
2827 // transformation on the pack expansion, producing another pack
2828 // expansion.
2829 TemplateArgumentLoc OutPattern;
2830 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2831 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2832 return true;
2833
2834 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis);
2835 if (Out.getArgument().isNull())
2836 return true;
2837
2838 Outputs.addArgument(Out);
2839 continue;
2840 }
2841
2842 // The transform has determined that we should perform an elementwise
2843 // expansion of the pattern. Do so.
2844 for (unsigned I = 0; I != NumExpansions; ++I) {
2845 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2846
2847 if (getDerived().TransformTemplateArgument(Pattern, Out))
2848 return true;
2849
2850 Outputs.addArgument(Out);
2851 }
2852
Douglas Gregor3cae5c92011-01-10 20:53:55 +00002853 // If we're supposed to retain a pack expansion, do so by temporarily
2854 // forgetting the partially-substituted parameter pack.
2855 if (RetainExpansion) {
2856 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2857
2858 if (getDerived().TransformTemplateArgument(Pattern, Out))
2859 return true;
2860
2861 Out = getDerived().RebuildPackExpansion(Out, Ellipsis);
2862 if (Out.getArgument().isNull())
2863 return true;
2864
2865 Outputs.addArgument(Out);
2866 }
Douglas Gregord3731192011-01-10 07:32:04 +00002867
Douglas Gregor8491ffe2010-12-20 22:05:00 +00002868 continue;
2869 }
2870
2871 // The simple case:
2872 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00002873 return true;
2874
2875 Outputs.addArgument(Out);
2876 }
2877
2878 return false;
2879
2880}
2881
Douglas Gregor577f75a2009-08-04 16:50:30 +00002882//===----------------------------------------------------------------------===//
2883// Type transformation
2884//===----------------------------------------------------------------------===//
2885
2886template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002887QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00002888 if (getDerived().AlreadyTransformed(T))
2889 return T;
Mike Stump1eb44332009-09-09 15:08:12 +00002890
John McCalla2becad2009-10-21 00:40:46 +00002891 // Temporary workaround. All of these transformations should
2892 // eventually turn into transformations on TypeLocs.
John McCalla93c9342009-12-07 02:54:59 +00002893 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCall4802a312009-10-21 00:44:26 +00002894 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Sean Huntc3021132010-05-05 15:23:54 +00002895
John McCall43fed0d2010-11-12 08:19:04 +00002896 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall0953e762009-09-24 19:53:00 +00002897
John McCalla2becad2009-10-21 00:40:46 +00002898 if (!NewDI)
2899 return QualType();
2900
2901 return NewDI->getType();
2902}
2903
2904template<typename Derived>
John McCall43fed0d2010-11-12 08:19:04 +00002905TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCalla2becad2009-10-21 00:40:46 +00002906 if (getDerived().AlreadyTransformed(DI->getType()))
2907 return DI;
2908
2909 TypeLocBuilder TLB;
2910
2911 TypeLoc TL = DI->getTypeLoc();
2912 TLB.reserve(TL.getFullDataSize());
2913
John McCall43fed0d2010-11-12 08:19:04 +00002914 QualType Result = getDerived().TransformType(TLB, TL);
John McCalla2becad2009-10-21 00:40:46 +00002915 if (Result.isNull())
2916 return 0;
2917
John McCalla93c9342009-12-07 02:54:59 +00002918 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCalla2becad2009-10-21 00:40:46 +00002919}
2920
2921template<typename Derived>
2922QualType
John McCall43fed0d2010-11-12 08:19:04 +00002923TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00002924 switch (T.getTypeLocClass()) {
2925#define ABSTRACT_TYPELOC(CLASS, PARENT)
2926#define TYPELOC(CLASS, PARENT) \
2927 case TypeLoc::CLASS: \
John McCall43fed0d2010-11-12 08:19:04 +00002928 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCalla2becad2009-10-21 00:40:46 +00002929#include "clang/AST/TypeLocNodes.def"
Douglas Gregor577f75a2009-08-04 16:50:30 +00002930 }
Mike Stump1eb44332009-09-09 15:08:12 +00002931
Jeffrey Yasskin9f61aa92009-12-12 05:05:38 +00002932 llvm_unreachable("unhandled type loc!");
John McCalla2becad2009-10-21 00:40:46 +00002933 return QualType();
2934}
2935
2936/// FIXME: By default, this routine adds type qualifiers only to types
2937/// that can have qualifiers, and silently suppresses those qualifiers
2938/// that are not permitted (e.g., qualifiers on reference or function
2939/// types). This is the right thing for template instantiation, but
2940/// probably not for other clients.
2941template<typename Derived>
2942QualType
2943TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00002944 QualifiedTypeLoc T) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00002945 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCalla2becad2009-10-21 00:40:46 +00002946
John McCall43fed0d2010-11-12 08:19:04 +00002947 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCalla2becad2009-10-21 00:40:46 +00002948 if (Result.isNull())
2949 return QualType();
2950
2951 // Silently suppress qualifiers if the result type can't be qualified.
2952 // FIXME: this is the right thing for template instantiation, but
2953 // probably not for other clients.
2954 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregor577f75a2009-08-04 16:50:30 +00002955 return Result;
Mike Stump1eb44332009-09-09 15:08:12 +00002956
John McCall28654742010-06-05 06:41:15 +00002957 if (!Quals.empty()) {
2958 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2959 TLB.push<QualifiedTypeLoc>(Result);
2960 // No location information to preserve.
2961 }
John McCalla2becad2009-10-21 00:40:46 +00002962
2963 return Result;
2964}
2965
John McCall43fed0d2010-11-12 08:19:04 +00002966/// \brief Transforms a type that was written in a scope specifier,
2967/// given an object type, the results of unqualified lookup, and
2968/// an already-instantiated prefix.
2969///
2970/// The object type is provided iff the scope specifier qualifies the
2971/// member of a dependent member-access expression. The prefix is
2972/// provided iff the the scope specifier in which this appears has a
2973/// prefix.
2974///
2975/// This is private to TreeTransform.
2976template<typename Derived>
2977QualType
2978TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
2979 QualType ObjectType,
2980 NamedDecl *UnqualLookup,
2981 NestedNameSpecifier *Prefix) {
2982 if (getDerived().AlreadyTransformed(T))
2983 return T;
2984
2985 TypeSourceInfo *TSI =
2986 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
2987
2988 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
2989 UnqualLookup, Prefix);
2990 if (!TSI) return QualType();
2991 return TSI->getType();
2992}
2993
2994template<typename Derived>
2995TypeSourceInfo *
2996TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
2997 QualType ObjectType,
2998 NamedDecl *UnqualLookup,
2999 NestedNameSpecifier *Prefix) {
3000 // TODO: in some cases, we might be some verification to do here.
3001 if (ObjectType.isNull())
3002 return getDerived().TransformType(TSI);
3003
3004 QualType T = TSI->getType();
3005 if (getDerived().AlreadyTransformed(T))
3006 return TSI;
3007
3008 TypeLocBuilder TLB;
3009 QualType Result;
3010
3011 if (isa<TemplateSpecializationType>(T)) {
3012 TemplateSpecializationTypeLoc TL
3013 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3014
3015 TemplateName Template =
3016 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3017 ObjectType, UnqualLookup);
3018 if (Template.isNull()) return 0;
3019
3020 Result = getDerived()
3021 .TransformTemplateSpecializationType(TLB, TL, Template);
3022 } else if (isa<DependentTemplateSpecializationType>(T)) {
3023 DependentTemplateSpecializationTypeLoc TL
3024 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3025
3026 Result = getDerived()
3027 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3028 } else {
3029 // Nothing special needs to be done for these.
3030 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3031 }
3032
3033 if (Result.isNull()) return 0;
3034 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3035}
3036
John McCalla2becad2009-10-21 00:40:46 +00003037template <class TyLoc> static inline
3038QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3039 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3040 NewT.setNameLoc(T.getNameLoc());
3041 return T.getType();
3042}
3043
John McCalla2becad2009-10-21 00:40:46 +00003044template<typename Derived>
3045QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003046 BuiltinTypeLoc T) {
Douglas Gregorddf889a2010-01-18 18:04:31 +00003047 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3048 NewT.setBuiltinLoc(T.getBuiltinLoc());
3049 if (T.needsExtraLocalData())
3050 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3051 return T.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003052}
Mike Stump1eb44332009-09-09 15:08:12 +00003053
Douglas Gregor577f75a2009-08-04 16:50:30 +00003054template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003055QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003056 ComplexTypeLoc T) {
John McCalla2becad2009-10-21 00:40:46 +00003057 // FIXME: recurse?
3058 return TransformTypeSpecType(TLB, T);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003059}
Mike Stump1eb44332009-09-09 15:08:12 +00003060
Douglas Gregor577f75a2009-08-04 16:50:30 +00003061template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003062QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003063 PointerTypeLoc TL) {
Sean Huntc3021132010-05-05 15:23:54 +00003064 QualType PointeeType
3065 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003066 if (PointeeType.isNull())
3067 return QualType();
3068
3069 QualType Result = TL.getType();
John McCallc12c5bb2010-05-15 11:32:37 +00003070 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00003071 // A dependent pointer type 'T *' has is being transformed such
3072 // that an Objective-C class type is being replaced for 'T'. The
3073 // resulting pointer type is an ObjCObjectPointerType, not a
3074 // PointerType.
John McCallc12c5bb2010-05-15 11:32:37 +00003075 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Sean Huntc3021132010-05-05 15:23:54 +00003076
John McCallc12c5bb2010-05-15 11:32:37 +00003077 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3078 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregor92e986e2010-04-22 16:44:27 +00003079 return Result;
3080 }
John McCall43fed0d2010-11-12 08:19:04 +00003081
Douglas Gregor92e986e2010-04-22 16:44:27 +00003082 if (getDerived().AlwaysRebuild() ||
3083 PointeeType != TL.getPointeeLoc().getType()) {
3084 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3085 if (Result.isNull())
3086 return QualType();
3087 }
Sean Huntc3021132010-05-05 15:23:54 +00003088
Douglas Gregor92e986e2010-04-22 16:44:27 +00003089 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3090 NewT.setSigilLoc(TL.getSigilLoc());
Sean Huntc3021132010-05-05 15:23:54 +00003091 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003092}
Mike Stump1eb44332009-09-09 15:08:12 +00003093
3094template<typename Derived>
3095QualType
John McCalla2becad2009-10-21 00:40:46 +00003096TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003097 BlockPointerTypeLoc TL) {
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003098 QualType PointeeType
Sean Huntc3021132010-05-05 15:23:54 +00003099 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3100 if (PointeeType.isNull())
3101 return QualType();
3102
3103 QualType Result = TL.getType();
3104 if (getDerived().AlwaysRebuild() ||
3105 PointeeType != TL.getPointeeLoc().getType()) {
3106 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003107 TL.getSigilLoc());
3108 if (Result.isNull())
3109 return QualType();
3110 }
3111
Douglas Gregor39968ad2010-04-22 16:50:51 +00003112 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregordb93c4a2010-04-22 16:46:21 +00003113 NewT.setSigilLoc(TL.getSigilLoc());
3114 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003115}
3116
John McCall85737a72009-10-30 00:06:24 +00003117/// Transforms a reference type. Note that somewhat paradoxically we
3118/// don't care whether the type itself is an l-value type or an r-value
3119/// type; we only care if the type was *written* as an l-value type
3120/// or an r-value type.
3121template<typename Derived>
3122QualType
3123TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003124 ReferenceTypeLoc TL) {
John McCall85737a72009-10-30 00:06:24 +00003125 const ReferenceType *T = TL.getTypePtr();
3126
3127 // Note that this works with the pointee-as-written.
3128 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3129 if (PointeeType.isNull())
3130 return QualType();
3131
3132 QualType Result = TL.getType();
3133 if (getDerived().AlwaysRebuild() ||
3134 PointeeType != T->getPointeeTypeAsWritten()) {
3135 Result = getDerived().RebuildReferenceType(PointeeType,
3136 T->isSpelledAsLValue(),
3137 TL.getSigilLoc());
3138 if (Result.isNull())
3139 return QualType();
3140 }
3141
3142 // r-value references can be rebuilt as l-value references.
3143 ReferenceTypeLoc NewTL;
3144 if (isa<LValueReferenceType>(Result))
3145 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3146 else
3147 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3148 NewTL.setSigilLoc(TL.getSigilLoc());
3149
3150 return Result;
3151}
3152
Mike Stump1eb44332009-09-09 15:08:12 +00003153template<typename Derived>
3154QualType
John McCalla2becad2009-10-21 00:40:46 +00003155TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003156 LValueReferenceTypeLoc TL) {
3157 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003158}
3159
Mike Stump1eb44332009-09-09 15:08:12 +00003160template<typename Derived>
3161QualType
John McCalla2becad2009-10-21 00:40:46 +00003162TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003163 RValueReferenceTypeLoc TL) {
3164 return TransformReferenceType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003165}
Mike Stump1eb44332009-09-09 15:08:12 +00003166
Douglas Gregor577f75a2009-08-04 16:50:30 +00003167template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003168QualType
John McCalla2becad2009-10-21 00:40:46 +00003169TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003170 MemberPointerTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003171 MemberPointerType *T = TL.getTypePtr();
3172
3173 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003174 if (PointeeType.isNull())
3175 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003176
John McCalla2becad2009-10-21 00:40:46 +00003177 // TODO: preserve source information for this.
3178 QualType ClassType
3179 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003180 if (ClassType.isNull())
3181 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003182
John McCalla2becad2009-10-21 00:40:46 +00003183 QualType Result = TL.getType();
3184 if (getDerived().AlwaysRebuild() ||
3185 PointeeType != T->getPointeeType() ||
3186 ClassType != QualType(T->getClass(), 0)) {
John McCall85737a72009-10-30 00:06:24 +00003187 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3188 TL.getStarLoc());
John McCalla2becad2009-10-21 00:40:46 +00003189 if (Result.isNull())
3190 return QualType();
3191 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00003192
John McCalla2becad2009-10-21 00:40:46 +00003193 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3194 NewTL.setSigilLoc(TL.getSigilLoc());
3195
3196 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003197}
3198
Mike Stump1eb44332009-09-09 15:08:12 +00003199template<typename Derived>
3200QualType
John McCalla2becad2009-10-21 00:40:46 +00003201TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003202 ConstantArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003203 ConstantArrayType *T = TL.getTypePtr();
3204 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003205 if (ElementType.isNull())
3206 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003207
John McCalla2becad2009-10-21 00:40:46 +00003208 QualType Result = TL.getType();
3209 if (getDerived().AlwaysRebuild() ||
3210 ElementType != T->getElementType()) {
3211 Result = getDerived().RebuildConstantArrayType(ElementType,
3212 T->getSizeModifier(),
3213 T->getSize(),
John McCall85737a72009-10-30 00:06:24 +00003214 T->getIndexTypeCVRQualifiers(),
3215 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003216 if (Result.isNull())
3217 return QualType();
3218 }
Sean Huntc3021132010-05-05 15:23:54 +00003219
John McCalla2becad2009-10-21 00:40:46 +00003220 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3221 NewTL.setLBracketLoc(TL.getLBracketLoc());
3222 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003223
John McCalla2becad2009-10-21 00:40:46 +00003224 Expr *Size = TL.getSizeExpr();
3225 if (Size) {
John McCallf312b1e2010-08-26 23:41:50 +00003226 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003227 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3228 }
3229 NewTL.setSizeExpr(Size);
3230
3231 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003232}
Mike Stump1eb44332009-09-09 15:08:12 +00003233
Douglas Gregor577f75a2009-08-04 16:50:30 +00003234template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003235QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCalla2becad2009-10-21 00:40:46 +00003236 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003237 IncompleteArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003238 IncompleteArrayType *T = TL.getTypePtr();
3239 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003240 if (ElementType.isNull())
3241 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003242
John McCalla2becad2009-10-21 00:40:46 +00003243 QualType Result = TL.getType();
3244 if (getDerived().AlwaysRebuild() ||
3245 ElementType != T->getElementType()) {
3246 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00003247 T->getSizeModifier(),
John McCall85737a72009-10-30 00:06:24 +00003248 T->getIndexTypeCVRQualifiers(),
3249 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003250 if (Result.isNull())
3251 return QualType();
3252 }
Sean Huntc3021132010-05-05 15:23:54 +00003253
John McCalla2becad2009-10-21 00:40:46 +00003254 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3255 NewTL.setLBracketLoc(TL.getLBracketLoc());
3256 NewTL.setRBracketLoc(TL.getRBracketLoc());
3257 NewTL.setSizeExpr(0);
3258
3259 return Result;
3260}
3261
3262template<typename Derived>
3263QualType
3264TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003265 VariableArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003266 VariableArrayType *T = TL.getTypePtr();
3267 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3268 if (ElementType.isNull())
3269 return QualType();
3270
3271 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003272 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003273
John McCall60d7b3a2010-08-24 06:29:42 +00003274 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003275 = getDerived().TransformExpr(T->getSizeExpr());
3276 if (SizeResult.isInvalid())
3277 return QualType();
3278
John McCall9ae2f072010-08-23 23:25:46 +00003279 Expr *Size = SizeResult.take();
John McCalla2becad2009-10-21 00:40:46 +00003280
3281 QualType Result = TL.getType();
3282 if (getDerived().AlwaysRebuild() ||
3283 ElementType != T->getElementType() ||
3284 Size != T->getSizeExpr()) {
3285 Result = getDerived().RebuildVariableArrayType(ElementType,
3286 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003287 Size,
John McCalla2becad2009-10-21 00:40:46 +00003288 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003289 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003290 if (Result.isNull())
3291 return QualType();
3292 }
Sean Huntc3021132010-05-05 15:23:54 +00003293
John McCalla2becad2009-10-21 00:40:46 +00003294 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3295 NewTL.setLBracketLoc(TL.getLBracketLoc());
3296 NewTL.setRBracketLoc(TL.getRBracketLoc());
3297 NewTL.setSizeExpr(Size);
3298
3299 return Result;
3300}
3301
3302template<typename Derived>
3303QualType
3304TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003305 DependentSizedArrayTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003306 DependentSizedArrayType *T = TL.getTypePtr();
3307 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3308 if (ElementType.isNull())
3309 return QualType();
3310
3311 // Array bounds are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003312 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCalla2becad2009-10-21 00:40:46 +00003313
John McCall60d7b3a2010-08-24 06:29:42 +00003314 ExprResult SizeResult
John McCalla2becad2009-10-21 00:40:46 +00003315 = getDerived().TransformExpr(T->getSizeExpr());
3316 if (SizeResult.isInvalid())
3317 return QualType();
3318
3319 Expr *Size = static_cast<Expr*>(SizeResult.get());
3320
3321 QualType Result = TL.getType();
3322 if (getDerived().AlwaysRebuild() ||
3323 ElementType != T->getElementType() ||
3324 Size != T->getSizeExpr()) {
3325 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3326 T->getSizeModifier(),
John McCall9ae2f072010-08-23 23:25:46 +00003327 Size,
John McCalla2becad2009-10-21 00:40:46 +00003328 T->getIndexTypeCVRQualifiers(),
John McCall85737a72009-10-30 00:06:24 +00003329 TL.getBracketsRange());
John McCalla2becad2009-10-21 00:40:46 +00003330 if (Result.isNull())
3331 return QualType();
3332 }
3333 else SizeResult.take();
3334
3335 // We might have any sort of array type now, but fortunately they
3336 // all have the same location layout.
3337 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3338 NewTL.setLBracketLoc(TL.getLBracketLoc());
3339 NewTL.setRBracketLoc(TL.getRBracketLoc());
3340 NewTL.setSizeExpr(Size);
3341
3342 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003343}
Mike Stump1eb44332009-09-09 15:08:12 +00003344
3345template<typename Derived>
Douglas Gregor577f75a2009-08-04 16:50:30 +00003346QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCalla2becad2009-10-21 00:40:46 +00003347 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003348 DependentSizedExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003349 DependentSizedExtVectorType *T = TL.getTypePtr();
3350
3351 // FIXME: ext vector locs should be nested
Douglas Gregor577f75a2009-08-04 16:50:30 +00003352 QualType ElementType = getDerived().TransformType(T->getElementType());
3353 if (ElementType.isNull())
3354 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003355
Douglas Gregor670444e2009-08-04 22:27:00 +00003356 // Vector sizes are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003357 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregor670444e2009-08-04 22:27:00 +00003358
John McCall60d7b3a2010-08-24 06:29:42 +00003359 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003360 if (Size.isInvalid())
3361 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003362
John McCalla2becad2009-10-21 00:40:46 +00003363 QualType Result = TL.getType();
3364 if (getDerived().AlwaysRebuild() ||
John McCalleee91c32009-10-23 17:55:45 +00003365 ElementType != T->getElementType() ||
3366 Size.get() != T->getSizeExpr()) {
John McCalla2becad2009-10-21 00:40:46 +00003367 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00003368 Size.take(),
Douglas Gregor577f75a2009-08-04 16:50:30 +00003369 T->getAttributeLoc());
John McCalla2becad2009-10-21 00:40:46 +00003370 if (Result.isNull())
3371 return QualType();
3372 }
John McCalla2becad2009-10-21 00:40:46 +00003373
3374 // Result might be dependent or not.
3375 if (isa<DependentSizedExtVectorType>(Result)) {
3376 DependentSizedExtVectorTypeLoc NewTL
3377 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3378 NewTL.setNameLoc(TL.getNameLoc());
3379 } else {
3380 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3381 NewTL.setNameLoc(TL.getNameLoc());
3382 }
3383
3384 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003385}
Mike Stump1eb44332009-09-09 15:08:12 +00003386
3387template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003388QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003389 VectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003390 VectorType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003391 QualType ElementType = getDerived().TransformType(T->getElementType());
3392 if (ElementType.isNull())
3393 return QualType();
3394
John McCalla2becad2009-10-21 00:40:46 +00003395 QualType Result = TL.getType();
3396 if (getDerived().AlwaysRebuild() ||
3397 ElementType != T->getElementType()) {
John Thompson82287d12010-02-05 00:12:22 +00003398 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsone86d78c2010-11-10 21:56:12 +00003399 T->getVectorKind());
John McCalla2becad2009-10-21 00:40:46 +00003400 if (Result.isNull())
3401 return QualType();
3402 }
Sean Huntc3021132010-05-05 15:23:54 +00003403
John McCalla2becad2009-10-21 00:40:46 +00003404 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3405 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump1eb44332009-09-09 15:08:12 +00003406
John McCalla2becad2009-10-21 00:40:46 +00003407 return Result;
3408}
3409
3410template<typename Derived>
3411QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003412 ExtVectorTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003413 VectorType *T = TL.getTypePtr();
3414 QualType ElementType = getDerived().TransformType(T->getElementType());
3415 if (ElementType.isNull())
3416 return QualType();
3417
3418 QualType Result = TL.getType();
3419 if (getDerived().AlwaysRebuild() ||
3420 ElementType != T->getElementType()) {
3421 Result = getDerived().RebuildExtVectorType(ElementType,
3422 T->getNumElements(),
3423 /*FIXME*/ SourceLocation());
3424 if (Result.isNull())
3425 return QualType();
3426 }
Sean Huntc3021132010-05-05 15:23:54 +00003427
John McCalla2becad2009-10-21 00:40:46 +00003428 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3429 NewTL.setNameLoc(TL.getNameLoc());
3430
3431 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003432}
Mike Stump1eb44332009-09-09 15:08:12 +00003433
3434template<typename Derived>
John McCall21ef0fa2010-03-11 09:03:00 +00003435ParmVarDecl *
3436TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
3437 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
3438 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
3439 if (!NewDI)
3440 return 0;
3441
3442 if (NewDI == OldDI)
3443 return OldParm;
3444 else
3445 return ParmVarDecl::Create(SemaRef.Context,
3446 OldParm->getDeclContext(),
3447 OldParm->getLocation(),
3448 OldParm->getIdentifier(),
3449 NewDI->getType(),
3450 NewDI,
3451 OldParm->getStorageClass(),
Douglas Gregor16573fa2010-04-19 22:54:31 +00003452 OldParm->getStorageClassAsWritten(),
John McCall21ef0fa2010-03-11 09:03:00 +00003453 /* DefArg */ NULL);
3454}
3455
3456template<typename Derived>
3457bool TreeTransform<Derived>::
Douglas Gregora009b592011-01-07 00:20:55 +00003458 TransformFunctionTypeParams(SourceLocation Loc,
3459 ParmVarDecl **Params, unsigned NumParams,
3460 const QualType *ParamTypes,
3461 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3462 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3463 for (unsigned i = 0; i != NumParams; ++i) {
3464 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003465 if (OldParm->isParameterPack()) {
3466 // We have a function parameter pack that may need to be expanded.
3467 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall21ef0fa2010-03-11 09:03:00 +00003468
Douglas Gregor603cfb42011-01-05 23:12:31 +00003469 // Find the parameter packs that could be expanded.
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003470 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3471 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3472 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3473 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003474
3475 // Determine whether we should expand the parameter packs.
3476 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003477 bool RetainExpansion = false;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003478 unsigned NumExpansions = 0;
Douglas Gregorc8a16fb2011-01-05 23:16:57 +00003479 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3480 Pattern.getSourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003481 Unexpanded.data(),
3482 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003483 ShouldExpand,
3484 RetainExpansion,
3485 NumExpansions)) {
Douglas Gregor603cfb42011-01-05 23:12:31 +00003486 return true;
3487 }
3488
3489 if (ShouldExpand) {
3490 // Expand the function parameter pack into multiple, separate
3491 // parameters.
Douglas Gregor12c9c002011-01-07 16:43:16 +00003492 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003493 for (unsigned I = 0; I != NumExpansions; ++I) {
3494 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3495 ParmVarDecl *NewParm
3496 = getDerived().TransformFunctionTypeParam(OldParm);
3497 if (!NewParm)
3498 return true;
3499
Douglas Gregora009b592011-01-07 00:20:55 +00003500 OutParamTypes.push_back(NewParm->getType());
3501 if (PVars)
3502 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003503 }
Douglas Gregord3731192011-01-10 07:32:04 +00003504
3505 // If we're supposed to retain a pack expansion, do so by temporarily
3506 // forgetting the partially-substituted parameter pack.
3507 if (RetainExpansion) {
3508 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3509 ParmVarDecl *NewParm
3510 = getDerived().TransformFunctionTypeParam(OldParm);
3511 if (!NewParm)
3512 return true;
3513
3514 OutParamTypes.push_back(NewParm->getType());
3515 if (PVars)
3516 PVars->push_back(NewParm);
3517 }
3518
Douglas Gregor603cfb42011-01-05 23:12:31 +00003519 // We're done with the pack expansion.
3520 continue;
3521 }
3522
3523 // We'll substitute the parameter now without expanding the pack
3524 // expansion.
3525 }
3526
3527 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3528 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
John McCall21ef0fa2010-03-11 09:03:00 +00003529 if (!NewParm)
3530 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003531
Douglas Gregora009b592011-01-07 00:20:55 +00003532 OutParamTypes.push_back(NewParm->getType());
3533 if (PVars)
3534 PVars->push_back(NewParm);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003535 continue;
3536 }
John McCall21ef0fa2010-03-11 09:03:00 +00003537
3538 // Deal with the possibility that we don't have a parameter
3539 // declaration for this parameter.
Douglas Gregora009b592011-01-07 00:20:55 +00003540 QualType OldType = ParamTypes[i];
Douglas Gregor603cfb42011-01-05 23:12:31 +00003541 bool IsPackExpansion = false;
3542 if (const PackExpansionType *Expansion
3543 = dyn_cast<PackExpansionType>(OldType)) {
3544 // We have a function parameter pack that may need to be expanded.
3545 QualType Pattern = Expansion->getPattern();
3546 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3547 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3548
3549 // Determine whether we should expand the parameter packs.
3550 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00003551 bool RetainExpansion = false;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003552 unsigned NumExpansions = 0;
Douglas Gregora009b592011-01-07 00:20:55 +00003553 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor603cfb42011-01-05 23:12:31 +00003554 Unexpanded.data(),
3555 Unexpanded.size(),
Douglas Gregord3731192011-01-10 07:32:04 +00003556 ShouldExpand,
3557 RetainExpansion,
3558 NumExpansions)) {
John McCall21ef0fa2010-03-11 09:03:00 +00003559 return true;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003560 }
3561
3562 if (ShouldExpand) {
3563 // Expand the function parameter pack into multiple, separate
3564 // parameters.
3565 for (unsigned I = 0; I != NumExpansions; ++I) {
3566 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3567 QualType NewType = getDerived().TransformType(Pattern);
3568 if (NewType.isNull())
3569 return true;
John McCall21ef0fa2010-03-11 09:03:00 +00003570
Douglas Gregora009b592011-01-07 00:20:55 +00003571 OutParamTypes.push_back(NewType);
3572 if (PVars)
3573 PVars->push_back(0);
Douglas Gregor603cfb42011-01-05 23:12:31 +00003574 }
3575
3576 // We're done with the pack expansion.
3577 continue;
3578 }
3579
Douglas Gregor3cae5c92011-01-10 20:53:55 +00003580 // If we're supposed to retain a pack expansion, do so by temporarily
3581 // forgetting the partially-substituted parameter pack.
3582 if (RetainExpansion) {
3583 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3584 QualType NewType = getDerived().TransformType(Pattern);
3585 if (NewType.isNull())
3586 return true;
3587
3588 OutParamTypes.push_back(NewType);
3589 if (PVars)
3590 PVars->push_back(0);
3591 }
Douglas Gregord3731192011-01-10 07:32:04 +00003592
Douglas Gregor603cfb42011-01-05 23:12:31 +00003593 // We'll substitute the parameter now without expanding the pack
3594 // expansion.
3595 OldType = Expansion->getPattern();
3596 IsPackExpansion = true;
3597 }
3598
3599 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3600 QualType NewType = getDerived().TransformType(OldType);
3601 if (NewType.isNull())
3602 return true;
3603
3604 if (IsPackExpansion)
3605 NewType = getSema().Context.getPackExpansionType(NewType);
3606
Douglas Gregora009b592011-01-07 00:20:55 +00003607 OutParamTypes.push_back(NewType);
3608 if (PVars)
3609 PVars->push_back(0);
John McCall21ef0fa2010-03-11 09:03:00 +00003610 }
3611
3612 return false;
Douglas Gregor603cfb42011-01-05 23:12:31 +00003613 }
John McCall21ef0fa2010-03-11 09:03:00 +00003614
3615template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00003616QualType
John McCalla2becad2009-10-21 00:40:46 +00003617TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003618 FunctionProtoTypeLoc TL) {
Douglas Gregor7e010a02010-08-31 00:26:14 +00003619 // Transform the parameters and return type.
3620 //
3621 // We instantiate in source order, with the return type first followed by
3622 // the parameters, because users tend to expect this (even if they shouldn't
3623 // rely on it!).
3624 //
Douglas Gregordab60ad2010-10-01 18:44:50 +00003625 // When the function has a trailing return type, we instantiate the
3626 // parameters before the return type, since the return type can then refer
3627 // to the parameters themselves (via decltype, sizeof, etc.).
3628 //
Douglas Gregor577f75a2009-08-04 16:50:30 +00003629 llvm::SmallVector<QualType, 4> ParamTypes;
John McCalla2becad2009-10-21 00:40:46 +00003630 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor895162d2010-04-30 18:55:50 +00003631 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor7e010a02010-08-31 00:26:14 +00003632
Douglas Gregordab60ad2010-10-01 18:44:50 +00003633 QualType ResultType;
3634
3635 if (TL.getTrailingReturn()) {
Douglas Gregora009b592011-01-07 00:20:55 +00003636 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3637 TL.getParmArray(),
3638 TL.getNumArgs(),
3639 TL.getTypePtr()->arg_type_begin(),
3640 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003641 return QualType();
3642
3643 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3644 if (ResultType.isNull())
3645 return QualType();
3646 }
3647 else {
3648 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3649 if (ResultType.isNull())
3650 return QualType();
3651
Douglas Gregora009b592011-01-07 00:20:55 +00003652 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3653 TL.getParmArray(),
3654 TL.getNumArgs(),
3655 TL.getTypePtr()->arg_type_begin(),
3656 ParamTypes, &ParamDecls))
Douglas Gregordab60ad2010-10-01 18:44:50 +00003657 return QualType();
3658 }
3659
John McCalla2becad2009-10-21 00:40:46 +00003660 QualType Result = TL.getType();
3661 if (getDerived().AlwaysRebuild() ||
3662 ResultType != T->getResultType() ||
Douglas Gregorbd5f9f72011-01-07 19:27:47 +00003663 T->getNumArgs() != ParamTypes.size() ||
John McCalla2becad2009-10-21 00:40:46 +00003664 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3665 Result = getDerived().RebuildFunctionProtoType(ResultType,
3666 ParamTypes.data(),
3667 ParamTypes.size(),
3668 T->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00003669 T->getTypeQuals(),
3670 T->getExtInfo());
John McCalla2becad2009-10-21 00:40:46 +00003671 if (Result.isNull())
3672 return QualType();
3673 }
Mike Stump1eb44332009-09-09 15:08:12 +00003674
John McCalla2becad2009-10-21 00:40:46 +00003675 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3676 NewTL.setLParenLoc(TL.getLParenLoc());
3677 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003678 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCalla2becad2009-10-21 00:40:46 +00003679 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3680 NewTL.setArg(i, ParamDecls[i]);
3681
3682 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003683}
Mike Stump1eb44332009-09-09 15:08:12 +00003684
Douglas Gregor577f75a2009-08-04 16:50:30 +00003685template<typename Derived>
3686QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCalla2becad2009-10-21 00:40:46 +00003687 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003688 FunctionNoProtoTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003689 FunctionNoProtoType *T = TL.getTypePtr();
3690 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3691 if (ResultType.isNull())
3692 return QualType();
3693
3694 QualType Result = TL.getType();
3695 if (getDerived().AlwaysRebuild() ||
3696 ResultType != T->getResultType())
3697 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3698
3699 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3700 NewTL.setLParenLoc(TL.getLParenLoc());
3701 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregordab60ad2010-10-01 18:44:50 +00003702 NewTL.setTrailingReturn(false);
John McCalla2becad2009-10-21 00:40:46 +00003703
3704 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003705}
Mike Stump1eb44332009-09-09 15:08:12 +00003706
John McCalled976492009-12-04 22:46:56 +00003707template<typename Derived> QualType
3708TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003709 UnresolvedUsingTypeLoc TL) {
John McCalled976492009-12-04 22:46:56 +00003710 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003711 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCalled976492009-12-04 22:46:56 +00003712 if (!D)
3713 return QualType();
3714
3715 QualType Result = TL.getType();
3716 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3717 Result = getDerived().RebuildUnresolvedUsingType(D);
3718 if (Result.isNull())
3719 return QualType();
3720 }
3721
3722 // We might get an arbitrary type spec type back. We should at
3723 // least always get a type spec type, though.
3724 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3725 NewTL.setNameLoc(TL.getNameLoc());
3726
3727 return Result;
3728}
3729
Douglas Gregor577f75a2009-08-04 16:50:30 +00003730template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003731QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003732 TypedefTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003733 TypedefType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003734 TypedefDecl *Typedef
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003735 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3736 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003737 if (!Typedef)
3738 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003739
John McCalla2becad2009-10-21 00:40:46 +00003740 QualType Result = TL.getType();
3741 if (getDerived().AlwaysRebuild() ||
3742 Typedef != T->getDecl()) {
3743 Result = getDerived().RebuildTypedefType(Typedef);
3744 if (Result.isNull())
3745 return QualType();
3746 }
Mike Stump1eb44332009-09-09 15:08:12 +00003747
John McCalla2becad2009-10-21 00:40:46 +00003748 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3749 NewTL.setNameLoc(TL.getNameLoc());
3750
3751 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003752}
Mike Stump1eb44332009-09-09 15:08:12 +00003753
Douglas Gregor577f75a2009-08-04 16:50:30 +00003754template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003755QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003756 TypeOfExprTypeLoc TL) {
Douglas Gregor670444e2009-08-04 22:27:00 +00003757 // typeof expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003758 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003759
John McCall60d7b3a2010-08-24 06:29:42 +00003760 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003761 if (E.isInvalid())
3762 return QualType();
3763
John McCalla2becad2009-10-21 00:40:46 +00003764 QualType Result = TL.getType();
3765 if (getDerived().AlwaysRebuild() ||
John McCallcfb708c2010-01-13 20:03:27 +00003766 E.get() != TL.getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003767 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCalla2becad2009-10-21 00:40:46 +00003768 if (Result.isNull())
3769 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003770 }
John McCalla2becad2009-10-21 00:40:46 +00003771 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003772
John McCalla2becad2009-10-21 00:40:46 +00003773 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003774 NewTL.setTypeofLoc(TL.getTypeofLoc());
3775 NewTL.setLParenLoc(TL.getLParenLoc());
3776 NewTL.setRParenLoc(TL.getRParenLoc());
John McCalla2becad2009-10-21 00:40:46 +00003777
3778 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003779}
Mike Stump1eb44332009-09-09 15:08:12 +00003780
3781template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003782QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003783 TypeOfTypeLoc TL) {
John McCallcfb708c2010-01-13 20:03:27 +00003784 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3785 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3786 if (!New_Under_TI)
Douglas Gregor577f75a2009-08-04 16:50:30 +00003787 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003788
John McCalla2becad2009-10-21 00:40:46 +00003789 QualType Result = TL.getType();
John McCallcfb708c2010-01-13 20:03:27 +00003790 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3791 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCalla2becad2009-10-21 00:40:46 +00003792 if (Result.isNull())
3793 return QualType();
3794 }
Mike Stump1eb44332009-09-09 15:08:12 +00003795
John McCalla2becad2009-10-21 00:40:46 +00003796 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCallcfb708c2010-01-13 20:03:27 +00003797 NewTL.setTypeofLoc(TL.getTypeofLoc());
3798 NewTL.setLParenLoc(TL.getLParenLoc());
3799 NewTL.setRParenLoc(TL.getRParenLoc());
3800 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCalla2becad2009-10-21 00:40:46 +00003801
3802 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003803}
Mike Stump1eb44332009-09-09 15:08:12 +00003804
3805template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003806QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003807 DecltypeTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003808 DecltypeType *T = TL.getTypePtr();
3809
Douglas Gregor670444e2009-08-04 22:27:00 +00003810 // decltype expressions are not potentially evaluated contexts
John McCallf312b1e2010-08-26 23:41:50 +00003811 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00003812
John McCall60d7b3a2010-08-24 06:29:42 +00003813 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003814 if (E.isInvalid())
3815 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003816
John McCalla2becad2009-10-21 00:40:46 +00003817 QualType Result = TL.getType();
3818 if (getDerived().AlwaysRebuild() ||
3819 E.get() != T->getUnderlyingExpr()) {
John McCall2a984ca2010-10-12 00:20:44 +00003820 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00003821 if (Result.isNull())
3822 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003823 }
John McCalla2becad2009-10-21 00:40:46 +00003824 else E.take();
Mike Stump1eb44332009-09-09 15:08:12 +00003825
John McCalla2becad2009-10-21 00:40:46 +00003826 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3827 NewTL.setNameLoc(TL.getNameLoc());
3828
3829 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003830}
3831
3832template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003833QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003834 RecordTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003835 RecordType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003836 RecordDecl *Record
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003837 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3838 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003839 if (!Record)
3840 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003841
John McCalla2becad2009-10-21 00:40:46 +00003842 QualType Result = TL.getType();
3843 if (getDerived().AlwaysRebuild() ||
3844 Record != T->getDecl()) {
3845 Result = getDerived().RebuildRecordType(Record);
3846 if (Result.isNull())
3847 return QualType();
3848 }
Mike Stump1eb44332009-09-09 15:08:12 +00003849
John McCalla2becad2009-10-21 00:40:46 +00003850 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3851 NewTL.setNameLoc(TL.getNameLoc());
3852
3853 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003854}
Mike Stump1eb44332009-09-09 15:08:12 +00003855
3856template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00003857QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003858 EnumTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003859 EnumType *T = TL.getTypePtr();
Douglas Gregor577f75a2009-08-04 16:50:30 +00003860 EnumDecl *Enum
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00003861 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3862 T->getDecl()));
Douglas Gregor577f75a2009-08-04 16:50:30 +00003863 if (!Enum)
3864 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003865
John McCalla2becad2009-10-21 00:40:46 +00003866 QualType Result = TL.getType();
3867 if (getDerived().AlwaysRebuild() ||
3868 Enum != T->getDecl()) {
3869 Result = getDerived().RebuildEnumType(Enum);
3870 if (Result.isNull())
3871 return QualType();
3872 }
Mike Stump1eb44332009-09-09 15:08:12 +00003873
John McCalla2becad2009-10-21 00:40:46 +00003874 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3875 NewTL.setNameLoc(TL.getNameLoc());
3876
3877 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00003878}
John McCall7da24312009-09-05 00:15:47 +00003879
John McCall3cb0ebd2010-03-10 03:28:59 +00003880template<typename Derived>
3881QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3882 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003883 InjectedClassNameTypeLoc TL) {
John McCall3cb0ebd2010-03-10 03:28:59 +00003884 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3885 TL.getTypePtr()->getDecl());
3886 if (!D) return QualType();
3887
3888 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3889 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3890 return T;
3891}
3892
Douglas Gregor577f75a2009-08-04 16:50:30 +00003893template<typename Derived>
3894QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003895 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003896 TemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003897 return TransformTypeSpecType(TLB, TL);
Douglas Gregor577f75a2009-08-04 16:50:30 +00003898}
3899
Mike Stump1eb44332009-09-09 15:08:12 +00003900template<typename Derived>
John McCall49a832b2009-10-18 09:09:24 +00003901QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCalla2becad2009-10-21 00:40:46 +00003902 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003903 SubstTemplateTypeParmTypeLoc TL) {
John McCalla2becad2009-10-21 00:40:46 +00003904 return TransformTypeSpecType(TLB, TL);
John McCall49a832b2009-10-18 09:09:24 +00003905}
3906
3907template<typename Derived>
John McCall833ca992009-10-29 08:12:44 +00003908QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00003909 TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00003910 TemplateSpecializationTypeLoc TL) {
John McCall833ca992009-10-29 08:12:44 +00003911 const TemplateSpecializationType *T = TL.getTypePtr();
3912
Mike Stump1eb44332009-09-09 15:08:12 +00003913 TemplateName Template
John McCall43fed0d2010-11-12 08:19:04 +00003914 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregor577f75a2009-08-04 16:50:30 +00003915 if (Template.isNull())
3916 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00003917
John McCall43fed0d2010-11-12 08:19:04 +00003918 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3919}
3920
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003921namespace {
3922 /// \brief Simple iterator that traverses the template arguments in a
3923 /// container that provides a \c getArgLoc() member function.
3924 ///
3925 /// This iterator is intended to be used with the iterator form of
3926 /// \c TreeTransform<Derived>::TransformTemplateArguments().
3927 template<typename ArgLocContainer>
3928 class TemplateArgumentLocContainerIterator {
3929 ArgLocContainer *Container;
3930 unsigned Index;
3931
3932 public:
3933 typedef TemplateArgumentLoc value_type;
3934 typedef TemplateArgumentLoc reference;
3935 typedef int difference_type;
3936 typedef std::input_iterator_tag iterator_category;
3937
3938 class pointer {
3939 TemplateArgumentLoc Arg;
3940
3941 public:
3942 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3943
3944 const TemplateArgumentLoc *operator->() const {
3945 return &Arg;
3946 }
3947 };
3948
3949
3950 TemplateArgumentLocContainerIterator() {}
3951
3952 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
3953 unsigned Index)
3954 : Container(&Container), Index(Index) { }
3955
3956 TemplateArgumentLocContainerIterator &operator++() {
3957 ++Index;
3958 return *this;
3959 }
3960
3961 TemplateArgumentLocContainerIterator operator++(int) {
3962 TemplateArgumentLocContainerIterator Old(*this);
3963 ++(*this);
3964 return Old;
3965 }
3966
3967 TemplateArgumentLoc operator*() const {
3968 return Container->getArgLoc(Index);
3969 }
3970
3971 pointer operator->() const {
3972 return pointer(Container->getArgLoc(Index));
3973 }
3974
3975 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00003976 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003977 return X.Container == Y.Container && X.Index == Y.Index;
3978 }
3979
3980 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregorf7dd6992010-12-21 21:51:48 +00003981 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003982 return !(X == Y);
3983 }
3984 };
3985}
3986
3987
John McCall43fed0d2010-11-12 08:19:04 +00003988template <typename Derived>
3989QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
3990 TypeLocBuilder &TLB,
3991 TemplateSpecializationTypeLoc TL,
3992 TemplateName Template) {
John McCalld5532b62009-11-23 01:53:49 +00003993 TemplateArgumentListInfo NewTemplateArgs;
3994 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
3995 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00003996 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
3997 ArgIterator;
3998 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
3999 ArgIterator(TL, TL.getNumArgs()),
4000 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004001 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004002
John McCall833ca992009-10-29 08:12:44 +00004003 // FIXME: maybe don't rebuild if all the template arguments are the same.
4004
4005 QualType Result =
4006 getDerived().RebuildTemplateSpecializationType(Template,
4007 TL.getTemplateNameLoc(),
John McCalld5532b62009-11-23 01:53:49 +00004008 NewTemplateArgs);
John McCall833ca992009-10-29 08:12:44 +00004009
4010 if (!Result.isNull()) {
4011 TemplateSpecializationTypeLoc NewTL
4012 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4013 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4014 NewTL.setLAngleLoc(TL.getLAngleLoc());
4015 NewTL.setRAngleLoc(TL.getRAngleLoc());
4016 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4017 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004018 }
Mike Stump1eb44332009-09-09 15:08:12 +00004019
John McCall833ca992009-10-29 08:12:44 +00004020 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004021}
Mike Stump1eb44332009-09-09 15:08:12 +00004022
4023template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004024QualType
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004025TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004026 ElaboratedTypeLoc TL) {
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004027 ElaboratedType *T = TL.getTypePtr();
4028
4029 NestedNameSpecifier *NNS = 0;
4030 // NOTE: the qualifier in an ElaboratedType is optional.
4031 if (T->getQualifier() != 0) {
4032 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004033 TL.getQualifierRange());
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004034 if (!NNS)
4035 return QualType();
4036 }
Mike Stump1eb44332009-09-09 15:08:12 +00004037
John McCall43fed0d2010-11-12 08:19:04 +00004038 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4039 if (NamedT.isNull())
4040 return QualType();
Daniel Dunbara63db842010-05-14 16:34:09 +00004041
John McCalla2becad2009-10-21 00:40:46 +00004042 QualType Result = TL.getType();
4043 if (getDerived().AlwaysRebuild() ||
4044 NNS != T->getQualifier() ||
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004045 NamedT != T->getNamedType()) {
John McCall21e413f2010-11-04 19:04:38 +00004046 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4047 T->getKeyword(), NNS, NamedT);
John McCalla2becad2009-10-21 00:40:46 +00004048 if (Result.isNull())
4049 return QualType();
4050 }
Douglas Gregor577f75a2009-08-04 16:50:30 +00004051
Abramo Bagnara465d41b2010-05-11 21:36:43 +00004052 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004053 NewTL.setKeywordLoc(TL.getKeywordLoc());
4054 NewTL.setQualifierRange(TL.getQualifierRange());
John McCalla2becad2009-10-21 00:40:46 +00004055
4056 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004057}
Mike Stump1eb44332009-09-09 15:08:12 +00004058
4059template<typename Derived>
John McCall9d156a72011-01-06 01:58:22 +00004060QualType TreeTransform<Derived>::TransformAttributedType(
4061 TypeLocBuilder &TLB,
4062 AttributedTypeLoc TL) {
4063 const AttributedType *oldType = TL.getTypePtr();
4064 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4065 if (modifiedType.isNull())
4066 return QualType();
4067
4068 QualType result = TL.getType();
4069
4070 // FIXME: dependent operand expressions?
4071 if (getDerived().AlwaysRebuild() ||
4072 modifiedType != oldType->getModifiedType()) {
4073 // TODO: this is really lame; we should really be rebuilding the
4074 // equivalent type from first principles.
4075 QualType equivalentType
4076 = getDerived().TransformType(oldType->getEquivalentType());
4077 if (equivalentType.isNull())
4078 return QualType();
4079 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4080 modifiedType,
4081 equivalentType);
4082 }
4083
4084 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4085 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4086 if (TL.hasAttrOperand())
4087 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4088 if (TL.hasAttrExprOperand())
4089 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4090 else if (TL.hasAttrEnumOperand())
4091 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4092
4093 return result;
4094}
4095
4096template<typename Derived>
Abramo Bagnara075f8f12010-12-10 16:29:40 +00004097QualType
4098TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4099 ParenTypeLoc TL) {
4100 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4101 if (Inner.isNull())
4102 return QualType();
4103
4104 QualType Result = TL.getType();
4105 if (getDerived().AlwaysRebuild() ||
4106 Inner != TL.getInnerLoc().getType()) {
4107 Result = getDerived().RebuildParenType(Inner);
4108 if (Result.isNull())
4109 return QualType();
4110 }
4111
4112 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4113 NewTL.setLParenLoc(TL.getLParenLoc());
4114 NewTL.setRParenLoc(TL.getRParenLoc());
4115 return Result;
4116}
4117
4118template<typename Derived>
Douglas Gregor4714c122010-03-31 17:34:00 +00004119QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004120 DependentNameTypeLoc TL) {
Douglas Gregor4714c122010-03-31 17:34:00 +00004121 DependentNameType *T = TL.getTypePtr();
John McCall833ca992009-10-29 08:12:44 +00004122
Douglas Gregor577f75a2009-08-04 16:50:30 +00004123 NestedNameSpecifier *NNS
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004124 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004125 TL.getQualifierRange());
Douglas Gregor577f75a2009-08-04 16:50:30 +00004126 if (!NNS)
4127 return QualType();
Mike Stump1eb44332009-09-09 15:08:12 +00004128
John McCall33500952010-06-11 00:33:02 +00004129 QualType Result
4130 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4131 T->getIdentifier(),
4132 TL.getKeywordLoc(),
4133 TL.getQualifierRange(),
4134 TL.getNameLoc());
John McCalla2becad2009-10-21 00:40:46 +00004135 if (Result.isNull())
4136 return QualType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004137
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004138 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4139 QualType NamedT = ElabT->getNamedType();
John McCall33500952010-06-11 00:33:02 +00004140 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4141
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004142 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4143 NewTL.setKeywordLoc(TL.getKeywordLoc());
4144 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00004145 } else {
Abramo Bagnarae4da7a02010-05-19 21:37:53 +00004146 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4147 NewTL.setKeywordLoc(TL.getKeywordLoc());
4148 NewTL.setQualifierRange(TL.getQualifierRange());
4149 NewTL.setNameLoc(TL.getNameLoc());
4150 }
John McCalla2becad2009-10-21 00:40:46 +00004151 return Result;
Douglas Gregor577f75a2009-08-04 16:50:30 +00004152}
Mike Stump1eb44332009-09-09 15:08:12 +00004153
Douglas Gregor577f75a2009-08-04 16:50:30 +00004154template<typename Derived>
John McCall33500952010-06-11 00:33:02 +00004155QualType TreeTransform<Derived>::
4156 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004157 DependentTemplateSpecializationTypeLoc TL) {
John McCall33500952010-06-11 00:33:02 +00004158 DependentTemplateSpecializationType *T = TL.getTypePtr();
4159
4160 NestedNameSpecifier *NNS
4161 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall43fed0d2010-11-12 08:19:04 +00004162 TL.getQualifierRange());
John McCall33500952010-06-11 00:33:02 +00004163 if (!NNS)
4164 return QualType();
4165
John McCall43fed0d2010-11-12 08:19:04 +00004166 return getDerived()
4167 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4168}
4169
4170template<typename Derived>
4171QualType TreeTransform<Derived>::
4172 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4173 DependentTemplateSpecializationTypeLoc TL,
4174 NestedNameSpecifier *NNS) {
4175 DependentTemplateSpecializationType *T = TL.getTypePtr();
4176
John McCall33500952010-06-11 00:33:02 +00004177 TemplateArgumentListInfo NewTemplateArgs;
4178 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4179 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor7ca7ac42010-12-20 23:36:19 +00004180
4181 typedef TemplateArgumentLocContainerIterator<
4182 DependentTemplateSpecializationTypeLoc> ArgIterator;
4183 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4184 ArgIterator(TL, TL.getNumArgs()),
4185 NewTemplateArgs))
Douglas Gregor7f61f2f2010-12-20 17:42:22 +00004186 return QualType();
John McCall33500952010-06-11 00:33:02 +00004187
Douglas Gregor1efb6c72010-09-08 23:56:00 +00004188 QualType Result
4189 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4190 NNS,
4191 TL.getQualifierRange(),
4192 T->getIdentifier(),
4193 TL.getNameLoc(),
4194 NewTemplateArgs);
John McCall33500952010-06-11 00:33:02 +00004195 if (Result.isNull())
4196 return QualType();
4197
4198 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4199 QualType NamedT = ElabT->getNamedType();
4200
4201 // Copy information relevant to the template specialization.
4202 TemplateSpecializationTypeLoc NamedTL
4203 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4204 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4205 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4206 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4207 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4208
4209 // Copy information relevant to the elaborated type.
4210 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4211 NewTL.setKeywordLoc(TL.getKeywordLoc());
4212 NewTL.setQualifierRange(TL.getQualifierRange());
4213 } else {
Douglas Gregore2872d02010-06-17 16:03:49 +00004214 TypeLoc NewTL(Result, TL.getOpaqueData());
4215 TLB.pushFullCopy(NewTL);
John McCall33500952010-06-11 00:33:02 +00004216 }
4217 return Result;
4218}
4219
4220template<typename Derived>
Douglas Gregor7536dd52010-12-20 02:24:11 +00004221QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4222 PackExpansionTypeLoc TL) {
Douglas Gregor1d65ebb2011-01-05 19:06:29 +00004223 llvm_unreachable("Caller must expansion pack expansion types");
Douglas Gregor7536dd52010-12-20 02:24:11 +00004224 return QualType();
4225}
4226
4227template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004228QualType
4229TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004230 ObjCInterfaceTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004231 // ObjCInterfaceType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004232 TLB.pushFullCopy(TL);
4233 return TL.getType();
4234}
4235
4236template<typename Derived>
4237QualType
4238TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004239 ObjCObjectTypeLoc TL) {
John McCallc12c5bb2010-05-15 11:32:37 +00004240 // ObjCObjectType is never dependent.
4241 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004242 return TL.getType();
Douglas Gregor577f75a2009-08-04 16:50:30 +00004243}
Mike Stump1eb44332009-09-09 15:08:12 +00004244
4245template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00004246QualType
4247TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall43fed0d2010-11-12 08:19:04 +00004248 ObjCObjectPointerTypeLoc TL) {
Douglas Gregoref57c612010-04-22 17:28:13 +00004249 // ObjCObjectPointerType is never dependent.
John McCallc12c5bb2010-05-15 11:32:37 +00004250 TLB.pushFullCopy(TL);
Douglas Gregoref57c612010-04-22 17:28:13 +00004251 return TL.getType();
Argyrios Kyrtzidis24fab412009-09-29 19:42:55 +00004252}
4253
Douglas Gregor577f75a2009-08-04 16:50:30 +00004254//===----------------------------------------------------------------------===//
Douglas Gregor43959a92009-08-20 07:17:43 +00004255// Statement transformation
4256//===----------------------------------------------------------------------===//
4257template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004258StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004259TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004260 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004261}
4262
4263template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004264StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004265TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4266 return getDerived().TransformCompoundStmt(S, false);
4267}
4268
4269template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004270StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004271TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregor43959a92009-08-20 07:17:43 +00004272 bool IsStmtExpr) {
John McCall7114cba2010-08-27 19:56:05 +00004273 bool SubStmtInvalid = false;
Douglas Gregor43959a92009-08-20 07:17:43 +00004274 bool SubStmtChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004275 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregor43959a92009-08-20 07:17:43 +00004276 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4277 B != BEnd; ++B) {
John McCall60d7b3a2010-08-24 06:29:42 +00004278 StmtResult Result = getDerived().TransformStmt(*B);
John McCall7114cba2010-08-27 19:56:05 +00004279 if (Result.isInvalid()) {
4280 // Immediately fail if this was a DeclStmt, since it's very
4281 // likely that this will cause problems for future statements.
4282 if (isa<DeclStmt>(*B))
4283 return StmtError();
4284
4285 // Otherwise, just keep processing substatements and fail later.
4286 SubStmtInvalid = true;
4287 continue;
4288 }
Mike Stump1eb44332009-09-09 15:08:12 +00004289
Douglas Gregor43959a92009-08-20 07:17:43 +00004290 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4291 Statements.push_back(Result.takeAs<Stmt>());
4292 }
Mike Stump1eb44332009-09-09 15:08:12 +00004293
John McCall7114cba2010-08-27 19:56:05 +00004294 if (SubStmtInvalid)
4295 return StmtError();
4296
Douglas Gregor43959a92009-08-20 07:17:43 +00004297 if (!getDerived().AlwaysRebuild() &&
4298 !SubStmtChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004299 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004300
4301 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4302 move_arg(Statements),
4303 S->getRBracLoc(),
4304 IsStmtExpr);
4305}
Mike Stump1eb44332009-09-09 15:08:12 +00004306
Douglas Gregor43959a92009-08-20 07:17:43 +00004307template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004308StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004309TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004310 ExprResult LHS, RHS;
Eli Friedman264c1f82009-11-19 03:14:00 +00004311 {
4312 // The case value expressions are not potentially evaluated.
John McCallf312b1e2010-08-26 23:41:50 +00004313 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00004314
Eli Friedman264c1f82009-11-19 03:14:00 +00004315 // Transform the left-hand case value.
4316 LHS = getDerived().TransformExpr(S->getLHS());
4317 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004318 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004319
Eli Friedman264c1f82009-11-19 03:14:00 +00004320 // Transform the right-hand case value (for the GNU case-range extension).
4321 RHS = getDerived().TransformExpr(S->getRHS());
4322 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004323 return StmtError();
Eli Friedman264c1f82009-11-19 03:14:00 +00004324 }
Mike Stump1eb44332009-09-09 15:08:12 +00004325
Douglas Gregor43959a92009-08-20 07:17:43 +00004326 // Build the case statement.
4327 // Case statements are always rebuilt so that they will attached to their
4328 // transformed switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004329 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004330 LHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004331 S->getEllipsisLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004332 RHS.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004333 S->getColonLoc());
4334 if (Case.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004335 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004336
Douglas Gregor43959a92009-08-20 07:17:43 +00004337 // Transform the statement following the case
John McCall60d7b3a2010-08-24 06:29:42 +00004338 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregor43959a92009-08-20 07:17:43 +00004339 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004340 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004341
Douglas Gregor43959a92009-08-20 07:17:43 +00004342 // Attach the body to the case statement
John McCall9ae2f072010-08-23 23:25:46 +00004343 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004344}
4345
4346template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004347StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004348TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004349 // Transform the statement following the default 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 // Default statements are always rebuilt
4355 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004356 SubStmt.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004357}
Mike Stump1eb44332009-09-09 15:08:12 +00004358
Douglas Gregor43959a92009-08-20 07:17:43 +00004359template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004360StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004361TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
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 // FIXME: Pass the real colon location in.
4367 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4368 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis1a186002010-09-28 14:54:07 +00004369 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregor43959a92009-08-20 07:17:43 +00004370}
Mike Stump1eb44332009-09-09 15:08:12 +00004371
Douglas Gregor43959a92009-08-20 07:17:43 +00004372template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004373StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004374TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004375 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004376 ExprResult Cond;
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004377 VarDecl *ConditionVar = 0;
4378 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004379 ConditionVar
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004380 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004381 getDerived().TransformDefinition(
4382 S->getConditionVariable()->getLocation(),
4383 S->getConditionVariable()));
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004384 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004385 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004386 } else {
Douglas Gregor8cfe5a72009-11-23 23:44:04 +00004387 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004388
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004389 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004390 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004391
4392 // Convert the condition to a boolean value.
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004393 if (S->getCond()) {
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004394 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4395 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004396 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004397 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004398
John McCall9ae2f072010-08-23 23:25:46 +00004399 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004400 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004401 }
Sean Huntc3021132010-05-05 15:23:54 +00004402
John McCall9ae2f072010-08-23 23:25:46 +00004403 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4404 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004405 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004406
Douglas Gregor43959a92009-08-20 07:17:43 +00004407 // Transform the "then" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004408 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregor43959a92009-08-20 07:17:43 +00004409 if (Then.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004410 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004411
Douglas Gregor43959a92009-08-20 07:17:43 +00004412 // Transform the "else" branch.
John McCall60d7b3a2010-08-24 06:29:42 +00004413 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregor43959a92009-08-20 07:17:43 +00004414 if (Else.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004415 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004416
Douglas Gregor43959a92009-08-20 07:17:43 +00004417 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004418 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004419 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004420 Then.get() == S->getThen() &&
4421 Else.get() == S->getElse())
John McCall3fa5cae2010-10-26 07:05:15 +00004422 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004423
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004424 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidis44aa1f32010-11-20 02:04:01 +00004425 Then.get(),
John McCall9ae2f072010-08-23 23:25:46 +00004426 S->getElseLoc(), Else.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004427}
4428
4429template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004430StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004431TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004432 // Transform the condition.
John McCall60d7b3a2010-08-24 06:29:42 +00004433 ExprResult Cond;
Douglas Gregord3d53012009-11-24 17:07:59 +00004434 VarDecl *ConditionVar = 0;
4435 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004436 ConditionVar
Douglas Gregord3d53012009-11-24 17:07:59 +00004437 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004438 getDerived().TransformDefinition(
4439 S->getConditionVariable()->getLocation(),
4440 S->getConditionVariable()));
Douglas Gregord3d53012009-11-24 17:07:59 +00004441 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004442 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004443 } else {
Douglas Gregord3d53012009-11-24 17:07:59 +00004444 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004445
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004446 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004447 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004448 }
Mike Stump1eb44332009-09-09 15:08:12 +00004449
Douglas Gregor43959a92009-08-20 07:17:43 +00004450 // Rebuild the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004451 StmtResult Switch
John McCall9ae2f072010-08-23 23:25:46 +00004452 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregor586596f2010-05-06 17:25:47 +00004453 ConditionVar);
Douglas Gregor43959a92009-08-20 07:17:43 +00004454 if (Switch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004455 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004456
Douglas Gregor43959a92009-08-20 07:17:43 +00004457 // Transform the body of the switch statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004458 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004459 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004460 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004461
Douglas Gregor43959a92009-08-20 07:17:43 +00004462 // Complete the switch statement.
John McCall9ae2f072010-08-23 23:25:46 +00004463 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4464 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004465}
Mike Stump1eb44332009-09-09 15:08:12 +00004466
Douglas Gregor43959a92009-08-20 07:17:43 +00004467template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004468StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004469TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004470 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004471 ExprResult Cond;
Douglas Gregor5656e142009-11-24 21:15:44 +00004472 VarDecl *ConditionVar = 0;
4473 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004474 ConditionVar
Douglas Gregor5656e142009-11-24 21:15:44 +00004475 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004476 getDerived().TransformDefinition(
4477 S->getConditionVariable()->getLocation(),
4478 S->getConditionVariable()));
Douglas Gregor5656e142009-11-24 21:15:44 +00004479 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004480 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004481 } else {
Douglas Gregor5656e142009-11-24 21:15:44 +00004482 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004483
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004484 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004485 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004486
4487 if (S->getCond()) {
4488 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004489 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4490 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004491 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004492 return StmtError();
John McCall9ae2f072010-08-23 23:25:46 +00004493 Cond = CondE;
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004494 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004495 }
Mike Stump1eb44332009-09-09 15:08:12 +00004496
John McCall9ae2f072010-08-23 23:25:46 +00004497 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4498 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004499 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004500
Douglas Gregor43959a92009-08-20 07:17:43 +00004501 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004502 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004503 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004504 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004505
Douglas Gregor43959a92009-08-20 07:17:43 +00004506 if (!getDerived().AlwaysRebuild() &&
John McCall9ae2f072010-08-23 23:25:46 +00004507 FullCond.get() == S->getCond() &&
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004508 ConditionVar == S->getConditionVariable() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004509 Body.get() == S->getBody())
John McCall9ae2f072010-08-23 23:25:46 +00004510 return Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004511
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004512 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCall9ae2f072010-08-23 23:25:46 +00004513 ConditionVar, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004514}
Mike Stump1eb44332009-09-09 15:08:12 +00004515
Douglas Gregor43959a92009-08-20 07:17:43 +00004516template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004517StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004518TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004519 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004520 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004521 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004522 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004523
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004524 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004525 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004526 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004527 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004528
Douglas Gregor43959a92009-08-20 07:17:43 +00004529 if (!getDerived().AlwaysRebuild() &&
4530 Cond.get() == S->getCond() &&
4531 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004532 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004533
John McCall9ae2f072010-08-23 23:25:46 +00004534 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4535 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004536 S->getRParenLoc());
4537}
Mike Stump1eb44332009-09-09 15:08:12 +00004538
Douglas Gregor43959a92009-08-20 07:17:43 +00004539template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004540StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004541TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004542 // Transform the initialization statement
John McCall60d7b3a2010-08-24 06:29:42 +00004543 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregor43959a92009-08-20 07:17:43 +00004544 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004545 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004546
Douglas Gregor43959a92009-08-20 07:17:43 +00004547 // Transform the condition
John McCall60d7b3a2010-08-24 06:29:42 +00004548 ExprResult Cond;
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004549 VarDecl *ConditionVar = 0;
4550 if (S->getConditionVariable()) {
Sean Huntc3021132010-05-05 15:23:54 +00004551 ConditionVar
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004552 = cast_or_null<VarDecl>(
Douglas Gregoraac571c2010-03-01 17:25:41 +00004553 getDerived().TransformDefinition(
4554 S->getConditionVariable()->getLocation(),
4555 S->getConditionVariable()));
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004556 if (!ConditionVar)
John McCallf312b1e2010-08-26 23:41:50 +00004557 return StmtError();
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004558 } else {
4559 Cond = getDerived().TransformExpr(S->getCond());
Sean Huntc3021132010-05-05 15:23:54 +00004560
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004561 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004562 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004563
4564 if (S->getCond()) {
4565 // Convert the condition to a boolean value.
Douglas Gregor8491ffe2010-12-20 22:05:00 +00004566 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4567 Cond.get());
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004568 if (CondE.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004569 return StmtError();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004570
John McCall9ae2f072010-08-23 23:25:46 +00004571 Cond = CondE.get();
Douglas Gregorafa0fef2010-05-08 23:34:38 +00004572 }
Douglas Gregor99e9b4d2009-11-25 00:27:52 +00004573 }
Mike Stump1eb44332009-09-09 15:08:12 +00004574
John McCall9ae2f072010-08-23 23:25:46 +00004575 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4576 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallf312b1e2010-08-26 23:41:50 +00004577 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004578
Douglas Gregor43959a92009-08-20 07:17:43 +00004579 // Transform the increment
John McCall60d7b3a2010-08-24 06:29:42 +00004580 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregor43959a92009-08-20 07:17:43 +00004581 if (Inc.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004582 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004583
John McCall9ae2f072010-08-23 23:25:46 +00004584 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4585 if (S->getInc() && !FullInc.get())
John McCallf312b1e2010-08-26 23:41:50 +00004586 return StmtError();
Douglas Gregoreaa18e42010-05-08 22:20:28 +00004587
Douglas Gregor43959a92009-08-20 07:17:43 +00004588 // Transform the body
John McCall60d7b3a2010-08-24 06:29:42 +00004589 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregor43959a92009-08-20 07:17:43 +00004590 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004591 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004592
Douglas Gregor43959a92009-08-20 07:17:43 +00004593 if (!getDerived().AlwaysRebuild() &&
4594 Init.get() == S->getInit() &&
John McCall9ae2f072010-08-23 23:25:46 +00004595 FullCond.get() == S->getCond() &&
Douglas Gregor43959a92009-08-20 07:17:43 +00004596 Inc.get() == S->getInc() &&
4597 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004598 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004599
Douglas Gregor43959a92009-08-20 07:17:43 +00004600 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004601 Init.get(), FullCond, ConditionVar,
4602 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004603}
4604
4605template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004606StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004607TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004608 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump1eb44332009-09-09 15:08:12 +00004609 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004610 S->getLabel());
4611}
4612
4613template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004614StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004615TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004616 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregor43959a92009-08-20 07:17:43 +00004617 if (Target.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004618 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004619
Douglas Gregor43959a92009-08-20 07:17:43 +00004620 if (!getDerived().AlwaysRebuild() &&
4621 Target.get() == S->getTarget())
John McCall3fa5cae2010-10-26 07:05:15 +00004622 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004623
4624 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004625 Target.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004626}
4627
4628template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004629StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004630TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004631 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004632}
Mike Stump1eb44332009-09-09 15:08:12 +00004633
Douglas Gregor43959a92009-08-20 07:17:43 +00004634template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004635StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004636TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCall3fa5cae2010-10-26 07:05:15 +00004637 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004638}
Mike Stump1eb44332009-09-09 15:08:12 +00004639
Douglas Gregor43959a92009-08-20 07:17:43 +00004640template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004641StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004642TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004643 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregor43959a92009-08-20 07:17:43 +00004644 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004645 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004646
Mike Stump1eb44332009-09-09 15:08:12 +00004647 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregor43959a92009-08-20 07:17:43 +00004648 // to tell whether the return type of the function has changed.
John McCall9ae2f072010-08-23 23:25:46 +00004649 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
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>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004655 bool DeclChanged = false;
4656 llvm::SmallVector<Decl *, 4> Decls;
4657 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4658 D != DEnd; ++D) {
Douglas Gregoraac571c2010-03-01 17:25:41 +00004659 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4660 *D);
Douglas Gregor43959a92009-08-20 07:17:43 +00004661 if (!Transformed)
John McCallf312b1e2010-08-26 23:41:50 +00004662 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004663
Douglas Gregor43959a92009-08-20 07:17:43 +00004664 if (Transformed != *D)
4665 DeclChanged = true;
Mike Stump1eb44332009-09-09 15:08:12 +00004666
Douglas Gregor43959a92009-08-20 07:17:43 +00004667 Decls.push_back(Transformed);
4668 }
Mike Stump1eb44332009-09-09 15:08:12 +00004669
Douglas Gregor43959a92009-08-20 07:17:43 +00004670 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004671 return SemaRef.Owned(S);
Mike Stump1eb44332009-09-09 15:08:12 +00004672
4673 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregor43959a92009-08-20 07:17:43 +00004674 S->getStartLoc(), S->getEndLoc());
4675}
Mike Stump1eb44332009-09-09 15:08:12 +00004676
Douglas Gregor43959a92009-08-20 07:17:43 +00004677template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004678StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004679TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregor43959a92009-08-20 07:17:43 +00004680 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCall3fa5cae2010-10-26 07:05:15 +00004681 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004682}
4683
4684template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004685StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004686TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Sean Huntc3021132010-05-05 15:23:54 +00004687
John McCallca0408f2010-08-23 06:44:23 +00004688 ASTOwningVector<Expr*> Constraints(getSema());
4689 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004690 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlssona5a79f72010-01-30 20:05:21 +00004691
John McCall60d7b3a2010-08-24 06:29:42 +00004692 ExprResult AsmString;
John McCallca0408f2010-08-23 06:44:23 +00004693 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlsson703e3942010-01-24 05:50:09 +00004694
4695 bool ExprsChanged = false;
Sean Huntc3021132010-05-05 15:23:54 +00004696
Anders Carlsson703e3942010-01-24 05:50:09 +00004697 // Go through the outputs.
4698 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004699 Names.push_back(S->getOutputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004700
Anders Carlsson703e3942010-01-24 05:50:09 +00004701 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004702 Constraints.push_back(S->getOutputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004703
Anders Carlsson703e3942010-01-24 05:50:09 +00004704 // Transform the output expr.
4705 Expr *OutputExpr = S->getOutputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004706 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004707 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004708 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004709
Anders Carlsson703e3942010-01-24 05:50:09 +00004710 ExprsChanged |= Result.get() != OutputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004711
John McCall9ae2f072010-08-23 23:25:46 +00004712 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004713 }
Sean Huntc3021132010-05-05 15:23:54 +00004714
Anders Carlsson703e3942010-01-24 05:50:09 +00004715 // Go through the inputs.
4716 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlssonff93dbd2010-01-30 22:25:16 +00004717 Names.push_back(S->getInputIdentifier(I));
Sean Huntc3021132010-05-05 15:23:54 +00004718
Anders Carlsson703e3942010-01-24 05:50:09 +00004719 // No need to transform the constraint literal.
John McCall3fa5cae2010-10-26 07:05:15 +00004720 Constraints.push_back(S->getInputConstraintLiteral(I));
Sean Huntc3021132010-05-05 15:23:54 +00004721
Anders Carlsson703e3942010-01-24 05:50:09 +00004722 // Transform the input expr.
4723 Expr *InputExpr = S->getInputExpr(I);
John McCall60d7b3a2010-08-24 06:29:42 +00004724 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlsson703e3942010-01-24 05:50:09 +00004725 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004726 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004727
Anders Carlsson703e3942010-01-24 05:50:09 +00004728 ExprsChanged |= Result.get() != InputExpr;
Sean Huntc3021132010-05-05 15:23:54 +00004729
John McCall9ae2f072010-08-23 23:25:46 +00004730 Exprs.push_back(Result.get());
Anders Carlsson703e3942010-01-24 05:50:09 +00004731 }
Sean Huntc3021132010-05-05 15:23:54 +00004732
Anders Carlsson703e3942010-01-24 05:50:09 +00004733 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004734 return SemaRef.Owned(S);
Anders Carlsson703e3942010-01-24 05:50:09 +00004735
4736 // Go through the clobbers.
4737 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCall3fa5cae2010-10-26 07:05:15 +00004738 Clobbers.push_back(S->getClobber(I));
Anders Carlsson703e3942010-01-24 05:50:09 +00004739
4740 // No need to transform the asm string literal.
4741 AsmString = SemaRef.Owned(S->getAsmString());
4742
4743 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4744 S->isSimple(),
4745 S->isVolatile(),
4746 S->getNumOutputs(),
4747 S->getNumInputs(),
Anders Carlssona5a79f72010-01-30 20:05:21 +00004748 Names.data(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004749 move_arg(Constraints),
4750 move_arg(Exprs),
John McCall9ae2f072010-08-23 23:25:46 +00004751 AsmString.get(),
Anders Carlsson703e3942010-01-24 05:50:09 +00004752 move_arg(Clobbers),
4753 S->getRParenLoc(),
4754 S->isMSAsm());
Douglas Gregor43959a92009-08-20 07:17:43 +00004755}
4756
4757
4758template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004759StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004760TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004761 // Transform the body of the @try.
John McCall60d7b3a2010-08-24 06:29:42 +00004762 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004763 if (TryBody.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004764 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004765
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004766 // Transform the @catch statements (if present).
4767 bool AnyCatchChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004768 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004769 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004770 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004771 if (Catch.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004772 return StmtError();
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004773 if (Catch.get() != S->getCatchStmt(I))
4774 AnyCatchChanged = true;
4775 CatchStmts.push_back(Catch.release());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004776 }
Sean Huntc3021132010-05-05 15:23:54 +00004777
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004778 // Transform the @finally statement (if present).
John McCall60d7b3a2010-08-24 06:29:42 +00004779 StmtResult Finally;
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004780 if (S->getFinallyStmt()) {
4781 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4782 if (Finally.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004783 return StmtError();
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004784 }
4785
4786 // If nothing changed, just retain this statement.
4787 if (!getDerived().AlwaysRebuild() &&
4788 TryBody.get() == S->getTryBody() &&
Douglas Gregor8f5e3dd2010-04-23 22:50:49 +00004789 !AnyCatchChanged &&
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004790 Finally.get() == S->getFinallyStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00004791 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004792
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004793 // Build a new statement.
John McCall9ae2f072010-08-23 23:25:46 +00004794 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4795 move_arg(CatchStmts), Finally.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004796}
Mike Stump1eb44332009-09-09 15:08:12 +00004797
Douglas Gregor43959a92009-08-20 07:17:43 +00004798template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004799StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004800TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorbe270a02010-04-26 17:57:08 +00004801 // Transform the @catch parameter, if there is one.
4802 VarDecl *Var = 0;
4803 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4804 TypeSourceInfo *TSInfo = 0;
4805 if (FromVar->getTypeSourceInfo()) {
4806 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4807 if (!TSInfo)
John McCallf312b1e2010-08-26 23:41:50 +00004808 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004809 }
Sean Huntc3021132010-05-05 15:23:54 +00004810
Douglas Gregorbe270a02010-04-26 17:57:08 +00004811 QualType T;
4812 if (TSInfo)
4813 T = TSInfo->getType();
4814 else {
4815 T = getDerived().TransformType(FromVar->getType());
4816 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00004817 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004818 }
Sean Huntc3021132010-05-05 15:23:54 +00004819
Douglas Gregorbe270a02010-04-26 17:57:08 +00004820 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4821 if (!Var)
John McCallf312b1e2010-08-26 23:41:50 +00004822 return StmtError();
Douglas Gregorbe270a02010-04-26 17:57:08 +00004823 }
Sean Huntc3021132010-05-05 15:23:54 +00004824
John McCall60d7b3a2010-08-24 06:29:42 +00004825 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorbe270a02010-04-26 17:57:08 +00004826 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004827 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004828
4829 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorbe270a02010-04-26 17:57:08 +00004830 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004831 Var, Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004832}
Mike Stump1eb44332009-09-09 15:08:12 +00004833
Douglas Gregor43959a92009-08-20 07:17:43 +00004834template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004835StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004836TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004837 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004838 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004839 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004840 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004841
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004842 // If nothing changed, just retain this statement.
4843 if (!getDerived().AlwaysRebuild() &&
4844 Body.get() == S->getFinallyBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004845 return SemaRef.Owned(S);
Douglas Gregor4dfdd1b2010-04-22 23:59:56 +00004846
4847 // Build a new statement.
4848 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004849 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004850}
Mike Stump1eb44332009-09-09 15:08:12 +00004851
Douglas Gregor43959a92009-08-20 07:17:43 +00004852template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004853StmtResult
Mike Stump1eb44332009-09-09 15:08:12 +00004854TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCall60d7b3a2010-08-24 06:29:42 +00004855 ExprResult Operand;
Douglas Gregord1377b22010-04-22 21:44:01 +00004856 if (S->getThrowExpr()) {
4857 Operand = getDerived().TransformExpr(S->getThrowExpr());
4858 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004859 return StmtError();
Douglas Gregord1377b22010-04-22 21:44:01 +00004860 }
Sean Huntc3021132010-05-05 15:23:54 +00004861
Douglas Gregord1377b22010-04-22 21:44:01 +00004862 if (!getDerived().AlwaysRebuild() &&
4863 Operand.get() == S->getThrowExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00004864 return getSema().Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004865
John McCall9ae2f072010-08-23 23:25:46 +00004866 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004867}
Mike Stump1eb44332009-09-09 15:08:12 +00004868
Douglas Gregor43959a92009-08-20 07:17:43 +00004869template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004870StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004871TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004872 ObjCAtSynchronizedStmt *S) {
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004873 // Transform the object we are locking.
John McCall60d7b3a2010-08-24 06:29:42 +00004874 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004875 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004876 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004877
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004878 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004879 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004880 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004881 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004882
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004883 // If nothing change, just retain the current statement.
4884 if (!getDerived().AlwaysRebuild() &&
4885 Object.get() == S->getSynchExpr() &&
4886 Body.get() == S->getSynchBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004887 return SemaRef.Owned(S);
Douglas Gregor8fdc13a2010-04-22 22:01:21 +00004888
4889 // Build a new statement.
4890 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004891 Object.get(), Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004892}
4893
4894template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004895StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004896TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump1eb44332009-09-09 15:08:12 +00004897 ObjCForCollectionStmt *S) {
Douglas Gregorc3203e72010-04-22 23:10:45 +00004898 // Transform the element statement.
John McCall60d7b3a2010-08-24 06:29:42 +00004899 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004900 if (Element.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004901 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004902
Douglas Gregorc3203e72010-04-22 23:10:45 +00004903 // Transform the collection expression.
John McCall60d7b3a2010-08-24 06:29:42 +00004904 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004905 if (Collection.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004906 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004907
Douglas Gregorc3203e72010-04-22 23:10:45 +00004908 // Transform the body.
John McCall60d7b3a2010-08-24 06:29:42 +00004909 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorc3203e72010-04-22 23:10:45 +00004910 if (Body.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004911 return StmtError();
Sean Huntc3021132010-05-05 15:23:54 +00004912
Douglas Gregorc3203e72010-04-22 23:10:45 +00004913 // If nothing changed, just retain this statement.
4914 if (!getDerived().AlwaysRebuild() &&
4915 Element.get() == S->getElement() &&
4916 Collection.get() == S->getCollection() &&
4917 Body.get() == S->getBody())
John McCall3fa5cae2010-10-26 07:05:15 +00004918 return SemaRef.Owned(S);
Sean Huntc3021132010-05-05 15:23:54 +00004919
Douglas Gregorc3203e72010-04-22 23:10:45 +00004920 // Build a new statement.
4921 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4922 /*FIXME:*/S->getForLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004923 Element.get(),
4924 Collection.get(),
Douglas Gregorc3203e72010-04-22 23:10:45 +00004925 S->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00004926 Body.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004927}
4928
4929
4930template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004931StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004932TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4933 // Transform the exception declaration, if any.
4934 VarDecl *Var = 0;
4935 if (S->getExceptionDecl()) {
4936 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor83cb9422010-09-09 17:09:21 +00004937 TypeSourceInfo *T = getDerived().TransformType(
4938 ExceptionDecl->getTypeSourceInfo());
4939 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00004940 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004941
Douglas Gregor83cb9422010-09-09 17:09:21 +00004942 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregor43959a92009-08-20 07:17:43 +00004943 ExceptionDecl->getIdentifier(),
Douglas Gregor83cb9422010-09-09 17:09:21 +00004944 ExceptionDecl->getLocation());
Douglas Gregorff331c12010-07-25 18:17:45 +00004945 if (!Var || Var->isInvalidDecl())
John McCallf312b1e2010-08-26 23:41:50 +00004946 return StmtError();
Douglas Gregor43959a92009-08-20 07:17:43 +00004947 }
Mike Stump1eb44332009-09-09 15:08:12 +00004948
Douglas Gregor43959a92009-08-20 07:17:43 +00004949 // Transform the actual exception handler.
John McCall60d7b3a2010-08-24 06:29:42 +00004950 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorff331c12010-07-25 18:17:45 +00004951 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004952 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004953
Douglas Gregor43959a92009-08-20 07:17:43 +00004954 if (!getDerived().AlwaysRebuild() &&
4955 !Var &&
4956 Handler.get() == S->getHandlerBlock())
John McCall3fa5cae2010-10-26 07:05:15 +00004957 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004958
4959 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4960 Var,
John McCall9ae2f072010-08-23 23:25:46 +00004961 Handler.get());
Douglas Gregor43959a92009-08-20 07:17:43 +00004962}
Mike Stump1eb44332009-09-09 15:08:12 +00004963
Douglas Gregor43959a92009-08-20 07:17:43 +00004964template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004965StmtResult
Douglas Gregor43959a92009-08-20 07:17:43 +00004966TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
4967 // Transform the try block itself.
John McCall60d7b3a2010-08-24 06:29:42 +00004968 StmtResult TryBlock
Douglas Gregor43959a92009-08-20 07:17:43 +00004969 = getDerived().TransformCompoundStmt(S->getTryBlock());
4970 if (TryBlock.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004971 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004972
Douglas Gregor43959a92009-08-20 07:17:43 +00004973 // Transform the handlers.
4974 bool HandlerChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00004975 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregor43959a92009-08-20 07:17:43 +00004976 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCall60d7b3a2010-08-24 06:29:42 +00004977 StmtResult Handler
Douglas Gregor43959a92009-08-20 07:17:43 +00004978 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
4979 if (Handler.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00004980 return StmtError();
Mike Stump1eb44332009-09-09 15:08:12 +00004981
Douglas Gregor43959a92009-08-20 07:17:43 +00004982 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
4983 Handlers.push_back(Handler.takeAs<Stmt>());
4984 }
Mike Stump1eb44332009-09-09 15:08:12 +00004985
Douglas Gregor43959a92009-08-20 07:17:43 +00004986 if (!getDerived().AlwaysRebuild() &&
4987 TryBlock.get() == S->getTryBlock() &&
4988 !HandlerChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00004989 return SemaRef.Owned(S);
Douglas Gregor43959a92009-08-20 07:17:43 +00004990
John McCall9ae2f072010-08-23 23:25:46 +00004991 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump1eb44332009-09-09 15:08:12 +00004992 move_arg(Handlers));
Douglas Gregor43959a92009-08-20 07:17:43 +00004993}
Mike Stump1eb44332009-09-09 15:08:12 +00004994
Douglas Gregor43959a92009-08-20 07:17:43 +00004995//===----------------------------------------------------------------------===//
Douglas Gregorb98b1992009-08-11 05:31:07 +00004996// Expression transformation
4997//===----------------------------------------------------------------------===//
Mike Stump1eb44332009-09-09 15:08:12 +00004998template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00004999ExprResult
John McCall454feb92009-12-08 09:21:05 +00005000TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005001 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005002}
Mike Stump1eb44332009-09-09 15:08:12 +00005003
5004template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005005ExprResult
John McCall454feb92009-12-08 09:21:05 +00005006TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregora2813ce2009-10-23 18:54:35 +00005007 NestedNameSpecifier *Qualifier = 0;
5008 if (E->getQualifier()) {
5009 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005010 E->getQualifierRange());
Douglas Gregora2813ce2009-10-23 18:54:35 +00005011 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00005012 return ExprError();
Douglas Gregora2813ce2009-10-23 18:54:35 +00005013 }
John McCalldbd872f2009-12-08 09:08:17 +00005014
5015 ValueDecl *ND
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005016 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5017 E->getDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005018 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00005019 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005020
John McCallec8045d2010-08-17 21:27:17 +00005021 DeclarationNameInfo NameInfo = E->getNameInfo();
5022 if (NameInfo.getName()) {
5023 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5024 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00005025 return ExprError();
John McCallec8045d2010-08-17 21:27:17 +00005026 }
Abramo Bagnara25777432010-08-11 22:01:17 +00005027
5028 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora2813ce2009-10-23 18:54:35 +00005029 Qualifier == E->getQualifier() &&
5030 ND == E->getDecl() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00005031 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCall096832c2010-08-19 23:49:38 +00005032 !E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005033
5034 // Mark it referenced in the new context regardless.
5035 // FIXME: this is a bit instantiation-specific.
5036 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5037
John McCall3fa5cae2010-10-26 07:05:15 +00005038 return SemaRef.Owned(E);
Douglas Gregora2813ce2009-10-23 18:54:35 +00005039 }
John McCalldbd872f2009-12-08 09:08:17 +00005040
5041 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCall096832c2010-08-19 23:49:38 +00005042 if (E->hasExplicitTemplateArgs()) {
John McCalldbd872f2009-12-08 09:08:17 +00005043 TemplateArgs = &TransArgs;
5044 TransArgs.setLAngleLoc(E->getLAngleLoc());
5045 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005046 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5047 E->getNumTemplateArgs(),
5048 TransArgs))
5049 return ExprError();
John McCalldbd872f2009-12-08 09:08:17 +00005050 }
5051
Douglas Gregora2813ce2009-10-23 18:54:35 +00005052 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005053 ND, NameInfo, TemplateArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005054}
Mike Stump1eb44332009-09-09 15:08:12 +00005055
Douglas Gregorb98b1992009-08-11 05:31:07 +00005056template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005057ExprResult
John McCall454feb92009-12-08 09:21:05 +00005058TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005059 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005060}
Mike Stump1eb44332009-09-09 15:08:12 +00005061
Douglas Gregorb98b1992009-08-11 05:31:07 +00005062template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005063ExprResult
John McCall454feb92009-12-08 09:21:05 +00005064TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005065 return SemaRef.Owned(E);
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>::TransformImaginaryLiteral(ImaginaryLiteral *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>::TransformStringLiteral(StringLiteral *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>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005083 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005084}
5085
5086template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005087ExprResult
John McCall454feb92009-12-08 09:21:05 +00005088TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005089 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005090 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005091 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005092
Douglas Gregorb98b1992009-08-11 05:31:07 +00005093 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005094 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005095
John McCall9ae2f072010-08-23 23:25:46 +00005096 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005097 E->getRParen());
5098}
5099
Mike Stump1eb44332009-09-09 15:08:12 +00005100template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005101ExprResult
John McCall454feb92009-12-08 09:21:05 +00005102TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005103 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005104 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005105 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005106
Douglas Gregorb98b1992009-08-11 05:31:07 +00005107 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005108 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005109
Douglas Gregorb98b1992009-08-11 05:31:07 +00005110 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5111 E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005112 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005113}
Mike Stump1eb44332009-09-09 15:08:12 +00005114
Douglas Gregorb98b1992009-08-11 05:31:07 +00005115template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005116ExprResult
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005117TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5118 // Transform the type.
5119 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5120 if (!Type)
John McCallf312b1e2010-08-26 23:41:50 +00005121 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005122
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005123 // Transform all of the components into components similar to what the
5124 // parser uses.
Sean Huntc3021132010-05-05 15:23:54 +00005125 // FIXME: It would be slightly more efficient in the non-dependent case to
5126 // just map FieldDecls, rather than requiring the rebuilder to look for
5127 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005128 // template code that we don't care.
5129 bool ExprChanged = false;
John McCallf312b1e2010-08-26 23:41:50 +00005130 typedef Sema::OffsetOfComponent Component;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005131 typedef OffsetOfExpr::OffsetOfNode Node;
5132 llvm::SmallVector<Component, 4> Components;
5133 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5134 const Node &ON = E->getComponent(I);
5135 Component Comp;
Douglas Gregor72be24f2010-04-30 20:35:01 +00005136 Comp.isBrackets = true;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005137 Comp.LocStart = ON.getRange().getBegin();
5138 Comp.LocEnd = ON.getRange().getEnd();
5139 switch (ON.getKind()) {
5140 case Node::Array: {
5141 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCall60d7b3a2010-08-24 06:29:42 +00005142 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005143 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005144 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005145
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005146 ExprChanged = ExprChanged || Index.get() != FromIndex;
5147 Comp.isBrackets = true;
John McCall9ae2f072010-08-23 23:25:46 +00005148 Comp.U.E = Index.get();
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005149 break;
5150 }
Sean Huntc3021132010-05-05 15:23:54 +00005151
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005152 case Node::Field:
5153 case Node::Identifier:
5154 Comp.isBrackets = false;
5155 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregor29d2fd52010-04-28 22:43:14 +00005156 if (!Comp.U.IdentInfo)
5157 continue;
Sean Huntc3021132010-05-05 15:23:54 +00005158
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005159 break;
Sean Huntc3021132010-05-05 15:23:54 +00005160
Douglas Gregorcc8a5d52010-04-29 00:18:15 +00005161 case Node::Base:
5162 // Will be recomputed during the rebuild.
5163 continue;
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005164 }
Sean Huntc3021132010-05-05 15:23:54 +00005165
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005166 Components.push_back(Comp);
5167 }
Sean Huntc3021132010-05-05 15:23:54 +00005168
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005169 // If nothing changed, retain the existing expression.
5170 if (!getDerived().AlwaysRebuild() &&
5171 Type == E->getTypeSourceInfo() &&
5172 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005173 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00005174
Douglas Gregor8ecdb652010-04-28 22:16:22 +00005175 // Build a new offsetof expression.
5176 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5177 Components.data(), Components.size(),
5178 E->getRParenLoc());
5179}
5180
5181template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005182ExprResult
John McCall7cd7d1a2010-11-15 23:31:06 +00005183TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5184 assert(getDerived().AlreadyTransformed(E->getType()) &&
5185 "opaque value expression requires transformation");
5186 return SemaRef.Owned(E);
5187}
5188
5189template<typename Derived>
5190ExprResult
John McCall454feb92009-12-08 09:21:05 +00005191TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005192 if (E->isArgumentType()) {
John McCalla93c9342009-12-07 02:54:59 +00005193 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor5557b252009-10-28 00:29:27 +00005194
John McCalla93c9342009-12-07 02:54:59 +00005195 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall5ab75172009-11-04 07:28:41 +00005196 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005197 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005198
John McCall5ab75172009-11-04 07:28:41 +00005199 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCall3fa5cae2010-10-26 07:05:15 +00005200 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005201
John McCall5ab75172009-11-04 07:28:41 +00005202 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005203 E->isSizeOf(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005204 E->getSourceRange());
5205 }
Mike Stump1eb44332009-09-09 15:08:12 +00005206
John McCall60d7b3a2010-08-24 06:29:42 +00005207 ExprResult SubExpr;
Mike Stump1eb44332009-09-09 15:08:12 +00005208 {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005209 // C++0x [expr.sizeof]p1:
5210 // The operand is either an expression, which is an unevaluated operand
5211 // [...]
John McCallf312b1e2010-08-26 23:41:50 +00005212 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005213
Douglas Gregorb98b1992009-08-11 05:31:07 +00005214 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5215 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005216 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005217
Douglas Gregorb98b1992009-08-11 05:31:07 +00005218 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005219 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005220 }
Mike Stump1eb44332009-09-09 15:08:12 +00005221
John McCall9ae2f072010-08-23 23:25:46 +00005222 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005223 E->isSizeOf(),
5224 E->getSourceRange());
5225}
Mike Stump1eb44332009-09-09 15:08:12 +00005226
Douglas Gregorb98b1992009-08-11 05:31:07 +00005227template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005228ExprResult
John McCall454feb92009-12-08 09:21:05 +00005229TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005230 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005231 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005232 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005233
John McCall60d7b3a2010-08-24 06:29:42 +00005234 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005235 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005236 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005237
5238
Douglas Gregorb98b1992009-08-11 05:31:07 +00005239 if (!getDerived().AlwaysRebuild() &&
5240 LHS.get() == E->getLHS() &&
5241 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005242 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005243
John McCall9ae2f072010-08-23 23:25:46 +00005244 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005245 /*FIXME:*/E->getLHS()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005246 RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005247 E->getRBracketLoc());
5248}
Mike Stump1eb44332009-09-09 15:08:12 +00005249
5250template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005251ExprResult
John McCall454feb92009-12-08 09:21:05 +00005252TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005253 // Transform the callee.
John McCall60d7b3a2010-08-24 06:29:42 +00005254 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005255 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005256 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005257
5258 // Transform arguments.
5259 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005260 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005261 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5262 &ArgChanged))
5263 return ExprError();
5264
Douglas Gregorb98b1992009-08-11 05:31:07 +00005265 if (!getDerived().AlwaysRebuild() &&
5266 Callee.get() == E->getCallee() &&
5267 !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005268 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005269
Douglas Gregorb98b1992009-08-11 05:31:07 +00005270 // FIXME: Wrong source location information for the '('.
Mike Stump1eb44332009-09-09 15:08:12 +00005271 SourceLocation FakeLParenLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005272 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCall9ae2f072010-08-23 23:25:46 +00005273 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005274 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005275 E->getRParenLoc());
5276}
Mike Stump1eb44332009-09-09 15:08:12 +00005277
5278template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005279ExprResult
John McCall454feb92009-12-08 09:21:05 +00005280TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005281 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005282 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005283 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005284
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005285 NestedNameSpecifier *Qualifier = 0;
5286 if (E->hasQualifier()) {
Mike Stump1eb44332009-09-09 15:08:12 +00005287 Qualifier
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005288 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00005289 E->getQualifierRange());
Douglas Gregorc4bf26f2009-09-01 00:37:14 +00005290 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00005291 return ExprError();
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005292 }
Mike Stump1eb44332009-09-09 15:08:12 +00005293
Eli Friedmanf595cc42009-12-04 06:40:45 +00005294 ValueDecl *Member
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005295 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5296 E->getMemberDecl()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005297 if (!Member)
John McCallf312b1e2010-08-26 23:41:50 +00005298 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005299
John McCall6bb80172010-03-30 21:47:33 +00005300 NamedDecl *FoundDecl = E->getFoundDecl();
5301 if (FoundDecl == E->getMemberDecl()) {
5302 FoundDecl = Member;
5303 } else {
5304 FoundDecl = cast_or_null<NamedDecl>(
5305 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5306 if (!FoundDecl)
John McCallf312b1e2010-08-26 23:41:50 +00005307 return ExprError();
John McCall6bb80172010-03-30 21:47:33 +00005308 }
5309
Douglas Gregorb98b1992009-08-11 05:31:07 +00005310 if (!getDerived().AlwaysRebuild() &&
5311 Base.get() == E->getBase() &&
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005312 Qualifier == E->getQualifier() &&
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005313 Member == E->getMemberDecl() &&
John McCall6bb80172010-03-30 21:47:33 +00005314 FoundDecl == E->getFoundDecl() &&
John McCall096832c2010-08-19 23:49:38 +00005315 !E->hasExplicitTemplateArgs()) {
Sean Huntc3021132010-05-05 15:23:54 +00005316
Anders Carlsson1f240322009-12-22 05:24:09 +00005317 // Mark it referenced in the new context regardless.
5318 // FIXME: this is a bit instantiation-specific.
5319 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCall3fa5cae2010-10-26 07:05:15 +00005320 return SemaRef.Owned(E);
Anders Carlsson1f240322009-12-22 05:24:09 +00005321 }
Douglas Gregorb98b1992009-08-11 05:31:07 +00005322
John McCalld5532b62009-11-23 01:53:49 +00005323 TemplateArgumentListInfo TransArgs;
John McCall096832c2010-08-19 23:49:38 +00005324 if (E->hasExplicitTemplateArgs()) {
John McCalld5532b62009-11-23 01:53:49 +00005325 TransArgs.setLAngleLoc(E->getLAngleLoc());
5326 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00005327 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5328 E->getNumTemplateArgs(),
5329 TransArgs))
5330 return ExprError();
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005331 }
Sean Huntc3021132010-05-05 15:23:54 +00005332
Douglas Gregorb98b1992009-08-11 05:31:07 +00005333 // FIXME: Bogus source location for the operator
5334 SourceLocation FakeOperatorLoc
5335 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5336
John McCallc2233c52010-01-15 08:34:02 +00005337 // FIXME: to do this check properly, we will need to preserve the
5338 // first-qualifier-in-scope here, just in case we had a dependent
5339 // base (and therefore couldn't do the check) and a
5340 // nested-name-qualifier (and therefore could do the lookup).
5341 NamedDecl *FirstQualifierInScope = 0;
5342
John McCall9ae2f072010-08-23 23:25:46 +00005343 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005344 E->isArrow(),
Douglas Gregor83f6faf2009-08-31 23:41:50 +00005345 Qualifier,
5346 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00005347 E->getMemberNameInfo(),
Douglas Gregor8a4386b2009-11-04 23:20:05 +00005348 Member,
John McCall6bb80172010-03-30 21:47:33 +00005349 FoundDecl,
John McCall096832c2010-08-19 23:49:38 +00005350 (E->hasExplicitTemplateArgs()
John McCalld5532b62009-11-23 01:53:49 +00005351 ? &TransArgs : 0),
John McCallc2233c52010-01-15 08:34:02 +00005352 FirstQualifierInScope);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005353}
Mike Stump1eb44332009-09-09 15:08:12 +00005354
Douglas Gregorb98b1992009-08-11 05:31:07 +00005355template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005356ExprResult
John McCall454feb92009-12-08 09:21:05 +00005357TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005358 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005359 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005360 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005361
John McCall60d7b3a2010-08-24 06:29:42 +00005362 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005363 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005364 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005365
Douglas Gregorb98b1992009-08-11 05:31:07 +00005366 if (!getDerived().AlwaysRebuild() &&
5367 LHS.get() == E->getLHS() &&
5368 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005369 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005370
Douglas Gregorb98b1992009-08-11 05:31:07 +00005371 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCall9ae2f072010-08-23 23:25:46 +00005372 LHS.get(), RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005373}
5374
Mike Stump1eb44332009-09-09 15:08:12 +00005375template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005376ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005377TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall454feb92009-12-08 09:21:05 +00005378 CompoundAssignOperator *E) {
5379 return getDerived().TransformBinaryOperator(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005380}
Mike Stump1eb44332009-09-09 15:08:12 +00005381
Douglas Gregorb98b1992009-08-11 05:31:07 +00005382template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005383ExprResult
John McCall454feb92009-12-08 09:21:05 +00005384TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005385 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005386 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005387 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005388
John McCall60d7b3a2010-08-24 06:29:42 +00005389 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005390 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005391 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005392
John McCall60d7b3a2010-08-24 06:29:42 +00005393 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005394 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005395 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005396
Douglas Gregorb98b1992009-08-11 05:31:07 +00005397 if (!getDerived().AlwaysRebuild() &&
5398 Cond.get() == E->getCond() &&
5399 LHS.get() == E->getLHS() &&
5400 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005401 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005402
John McCall9ae2f072010-08-23 23:25:46 +00005403 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005404 E->getQuestionLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005405 LHS.get(),
Douglas Gregor47e1f7c2009-08-26 14:37:04 +00005406 E->getColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005407 RHS.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005408}
Mike Stump1eb44332009-09-09 15:08:12 +00005409
5410template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005411ExprResult
John McCall454feb92009-12-08 09:21:05 +00005412TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregora88cfbf2009-12-12 18:16:41 +00005413 // Implicit casts are eliminated during transformation, since they
5414 // will be recomputed by semantic analysis after transformation.
Douglas Gregor6eef5192009-12-14 19:27:10 +00005415 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005416}
Mike Stump1eb44332009-09-09 15:08:12 +00005417
Douglas Gregorb98b1992009-08-11 05:31:07 +00005418template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005419ExprResult
John McCall454feb92009-12-08 09:21:05 +00005420TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005421 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5422 if (!Type)
5423 return ExprError();
5424
John McCall60d7b3a2010-08-24 06:29:42 +00005425 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005426 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005427 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005428 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005429
Douglas Gregorb98b1992009-08-11 05:31:07 +00005430 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005431 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005432 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005433 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005434
John McCall9d125032010-01-15 18:39:57 +00005435 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005436 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005437 E->getRParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005438 SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005439}
Mike Stump1eb44332009-09-09 15:08:12 +00005440
Douglas Gregorb98b1992009-08-11 05:31:07 +00005441template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005442ExprResult
John McCall454feb92009-12-08 09:21:05 +00005443TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCall42f56b52010-01-18 19:35:47 +00005444 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5445 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5446 if (!NewT)
John McCallf312b1e2010-08-26 23:41:50 +00005447 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005448
John McCall60d7b3a2010-08-24 06:29:42 +00005449 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005450 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005451 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005452
Douglas Gregorb98b1992009-08-11 05:31:07 +00005453 if (!getDerived().AlwaysRebuild() &&
John McCall42f56b52010-01-18 19:35:47 +00005454 OldT == NewT &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005455 Init.get() == E->getInitializer())
John McCall3fa5cae2010-10-26 07:05:15 +00005456 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005457
John McCall1d7d8d62010-01-19 22:33:45 +00005458 // Note: the expression type doesn't necessarily match the
5459 // type-as-written, but that's okay, because it should always be
5460 // derivable from the initializer.
5461
John McCall42f56b52010-01-18 19:35:47 +00005462 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005463 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCall9ae2f072010-08-23 23:25:46 +00005464 Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005465}
Mike Stump1eb44332009-09-09 15:08:12 +00005466
Douglas Gregorb98b1992009-08-11 05:31:07 +00005467template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005468ExprResult
John McCall454feb92009-12-08 09:21:05 +00005469TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005470 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005471 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005472 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005473
Douglas Gregorb98b1992009-08-11 05:31:07 +00005474 if (!getDerived().AlwaysRebuild() &&
5475 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00005476 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005477
Douglas Gregorb98b1992009-08-11 05:31:07 +00005478 // FIXME: Bad source location
Mike Stump1eb44332009-09-09 15:08:12 +00005479 SourceLocation FakeOperatorLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005480 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCall9ae2f072010-08-23 23:25:46 +00005481 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005482 E->getAccessorLoc(),
5483 E->getAccessor());
5484}
Mike Stump1eb44332009-09-09 15:08:12 +00005485
Douglas Gregorb98b1992009-08-11 05:31:07 +00005486template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005487ExprResult
John McCall454feb92009-12-08 09:21:05 +00005488TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005489 bool InitChanged = false;
Mike Stump1eb44332009-09-09 15:08:12 +00005490
John McCallca0408f2010-08-23 06:44:23 +00005491 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005492 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5493 Inits, &InitChanged))
5494 return ExprError();
5495
Douglas Gregorb98b1992009-08-11 05:31:07 +00005496 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005497 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005498
Douglas Gregorb98b1992009-08-11 05:31:07 +00005499 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregore48319a2009-11-09 17:16:50 +00005500 E->getRBraceLoc(), E->getType());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005501}
Mike Stump1eb44332009-09-09 15:08:12 +00005502
Douglas Gregorb98b1992009-08-11 05:31:07 +00005503template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005504ExprResult
John McCall454feb92009-12-08 09:21:05 +00005505TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005506 Designation Desig;
Mike Stump1eb44332009-09-09 15:08:12 +00005507
Douglas Gregor43959a92009-08-20 07:17:43 +00005508 // transform the initializer value
John McCall60d7b3a2010-08-24 06:29:42 +00005509 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005510 if (Init.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005511 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005512
Douglas Gregor43959a92009-08-20 07:17:43 +00005513 // transform the designators.
John McCallca0408f2010-08-23 06:44:23 +00005514 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005515 bool ExprChanged = false;
5516 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5517 DEnd = E->designators_end();
5518 D != DEnd; ++D) {
5519 if (D->isFieldDesignator()) {
5520 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5521 D->getDotLoc(),
5522 D->getFieldLoc()));
5523 continue;
5524 }
Mike Stump1eb44332009-09-09 15:08:12 +00005525
Douglas Gregorb98b1992009-08-11 05:31:07 +00005526 if (D->isArrayDesignator()) {
John McCall60d7b3a2010-08-24 06:29:42 +00005527 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005528 if (Index.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005529 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005530
5531 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005532 D->getLBracketLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005533
Douglas Gregorb98b1992009-08-11 05:31:07 +00005534 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5535 ArrayExprs.push_back(Index.release());
5536 continue;
5537 }
Mike Stump1eb44332009-09-09 15:08:12 +00005538
Douglas Gregorb98b1992009-08-11 05:31:07 +00005539 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCall60d7b3a2010-08-24 06:29:42 +00005540 ExprResult Start
Douglas Gregorb98b1992009-08-11 05:31:07 +00005541 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5542 if (Start.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005543 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005544
John McCall60d7b3a2010-08-24 06:29:42 +00005545 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005546 if (End.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005547 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005548
5549 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005550 End.get(),
5551 D->getLBracketLoc(),
5552 D->getEllipsisLoc()));
Mike Stump1eb44332009-09-09 15:08:12 +00005553
Douglas Gregorb98b1992009-08-11 05:31:07 +00005554 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5555 End.get() != E->getArrayRangeEnd(*D);
Mike Stump1eb44332009-09-09 15:08:12 +00005556
Douglas Gregorb98b1992009-08-11 05:31:07 +00005557 ArrayExprs.push_back(Start.release());
5558 ArrayExprs.push_back(End.release());
5559 }
Mike Stump1eb44332009-09-09 15:08:12 +00005560
Douglas Gregorb98b1992009-08-11 05:31:07 +00005561 if (!getDerived().AlwaysRebuild() &&
5562 Init.get() == E->getInit() &&
5563 !ExprChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00005564 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005565
Douglas Gregorb98b1992009-08-11 05:31:07 +00005566 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5567 E->getEqualOrColonLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005568 E->usesGNUSyntax(), Init.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005569}
Mike Stump1eb44332009-09-09 15:08:12 +00005570
Douglas Gregorb98b1992009-08-11 05:31:07 +00005571template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005572ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005573TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall454feb92009-12-08 09:21:05 +00005574 ImplicitValueInitExpr *E) {
Douglas Gregor5557b252009-10-28 00:29:27 +00005575 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Sean Huntc3021132010-05-05 15:23:54 +00005576
Douglas Gregor5557b252009-10-28 00:29:27 +00005577 // FIXME: Will we ever have proper type location here? Will we actually
5578 // need to transform the type?
Douglas Gregorb98b1992009-08-11 05:31:07 +00005579 QualType T = getDerived().TransformType(E->getType());
5580 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00005581 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005582
Douglas Gregorb98b1992009-08-11 05:31:07 +00005583 if (!getDerived().AlwaysRebuild() &&
5584 T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005585 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005586
Douglas Gregorb98b1992009-08-11 05:31:07 +00005587 return getDerived().RebuildImplicitValueInitExpr(T);
5588}
Mike Stump1eb44332009-09-09 15:08:12 +00005589
Douglas Gregorb98b1992009-08-11 05:31:07 +00005590template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005591ExprResult
John McCall454feb92009-12-08 09:21:05 +00005592TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor9bcd4d42010-08-10 14:27:00 +00005593 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5594 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005595 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005596
John McCall60d7b3a2010-08-24 06:29:42 +00005597 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005598 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005599 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005600
Douglas Gregorb98b1992009-08-11 05:31:07 +00005601 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005602 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005603 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005604 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005605
John McCall9ae2f072010-08-23 23:25:46 +00005606 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara2cad9002010-08-10 10:06:15 +00005607 TInfo, E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005608}
5609
5610template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005611ExprResult
John McCall454feb92009-12-08 09:21:05 +00005612TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005613 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00005614 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005615 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5616 &ArgumentChanged))
5617 return ExprError();
5618
Douglas Gregorb98b1992009-08-11 05:31:07 +00005619 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5620 move_arg(Inits),
5621 E->getRParenLoc());
5622}
Mike Stump1eb44332009-09-09 15:08:12 +00005623
Douglas Gregorb98b1992009-08-11 05:31:07 +00005624/// \brief Transform an address-of-label expression.
5625///
5626/// By default, the transformation of an address-of-label expression always
5627/// rebuilds the expression, so that the label identifier can be resolved to
5628/// the corresponding label statement by semantic analysis.
5629template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005630ExprResult
John McCall454feb92009-12-08 09:21:05 +00005631TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005632 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5633 E->getLabel());
5634}
Mike Stump1eb44332009-09-09 15:08:12 +00005635
5636template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005637ExprResult
John McCall454feb92009-12-08 09:21:05 +00005638TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005639 StmtResult SubStmt
Douglas Gregorb98b1992009-08-11 05:31:07 +00005640 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5641 if (SubStmt.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005642 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005643
Douglas Gregorb98b1992009-08-11 05:31:07 +00005644 if (!getDerived().AlwaysRebuild() &&
5645 SubStmt.get() == E->getSubStmt())
John McCall3fa5cae2010-10-26 07:05:15 +00005646 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005647
5648 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005649 SubStmt.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005650 E->getRParenLoc());
5651}
Mike Stump1eb44332009-09-09 15:08:12 +00005652
Douglas Gregorb98b1992009-08-11 05:31:07 +00005653template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005654ExprResult
John McCall454feb92009-12-08 09:21:05 +00005655TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005656 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005657 if (Cond.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005658 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005659
John McCall60d7b3a2010-08-24 06:29:42 +00005660 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005661 if (LHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005662 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005663
John McCall60d7b3a2010-08-24 06:29:42 +00005664 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005665 if (RHS.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005666 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005667
Douglas Gregorb98b1992009-08-11 05:31:07 +00005668 if (!getDerived().AlwaysRebuild() &&
5669 Cond.get() == E->getCond() &&
5670 LHS.get() == E->getLHS() &&
5671 RHS.get() == E->getRHS())
John McCall3fa5cae2010-10-26 07:05:15 +00005672 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005673
Douglas Gregorb98b1992009-08-11 05:31:07 +00005674 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005675 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005676 E->getRParenLoc());
5677}
Mike Stump1eb44332009-09-09 15:08:12 +00005678
Douglas Gregorb98b1992009-08-11 05:31:07 +00005679template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005680ExprResult
John McCall454feb92009-12-08 09:21:05 +00005681TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005682 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005683}
5684
5685template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005686ExprResult
John McCall454feb92009-12-08 09:21:05 +00005687TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregor668d6d92009-12-13 20:44:55 +00005688 switch (E->getOperator()) {
5689 case OO_New:
5690 case OO_Delete:
5691 case OO_Array_New:
5692 case OO_Array_Delete:
5693 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallf312b1e2010-08-26 23:41:50 +00005694 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00005695
Douglas Gregor668d6d92009-12-13 20:44:55 +00005696 case OO_Call: {
5697 // This is a call to an object's operator().
5698 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5699
5700 // Transform the object itself.
John McCall60d7b3a2010-08-24 06:29:42 +00005701 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregor668d6d92009-12-13 20:44:55 +00005702 if (Object.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005703 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005704
5705 // FIXME: Poor location information
5706 SourceLocation FakeLParenLoc
5707 = SemaRef.PP.getLocForEndOfToken(
5708 static_cast<Expr *>(Object.get())->getLocEnd());
5709
5710 // Transform the call arguments.
John McCallca0408f2010-08-23 06:44:23 +00005711 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00005712 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5713 Args))
5714 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005715
John McCall9ae2f072010-08-23 23:25:46 +00005716 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregor668d6d92009-12-13 20:44:55 +00005717 move_arg(Args),
Douglas Gregor668d6d92009-12-13 20:44:55 +00005718 E->getLocEnd());
5719 }
5720
5721#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5722 case OO_##Name:
5723#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5724#include "clang/Basic/OperatorKinds.def"
5725 case OO_Subscript:
5726 // Handled below.
5727 break;
5728
5729 case OO_Conditional:
5730 llvm_unreachable("conditional operator is not actually overloadable");
John McCallf312b1e2010-08-26 23:41:50 +00005731 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005732
5733 case OO_None:
5734 case NUM_OVERLOADED_OPERATORS:
5735 llvm_unreachable("not an overloaded operator?");
John McCallf312b1e2010-08-26 23:41:50 +00005736 return ExprError();
Douglas Gregor668d6d92009-12-13 20:44:55 +00005737 }
5738
John McCall60d7b3a2010-08-24 06:29:42 +00005739 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005740 if (Callee.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005741 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005742
John McCall60d7b3a2010-08-24 06:29:42 +00005743 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005744 if (First.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005745 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005746
John McCall60d7b3a2010-08-24 06:29:42 +00005747 ExprResult Second;
Douglas Gregorb98b1992009-08-11 05:31:07 +00005748 if (E->getNumArgs() == 2) {
5749 Second = getDerived().TransformExpr(E->getArg(1));
5750 if (Second.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005751 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00005752 }
Mike Stump1eb44332009-09-09 15:08:12 +00005753
Douglas Gregorb98b1992009-08-11 05:31:07 +00005754 if (!getDerived().AlwaysRebuild() &&
5755 Callee.get() == E->getCallee() &&
5756 First.get() == E->getArg(0) &&
Mike Stump1eb44332009-09-09 15:08:12 +00005757 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCall3fa5cae2010-10-26 07:05:15 +00005758 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005759
Douglas Gregorb98b1992009-08-11 05:31:07 +00005760 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5761 E->getOperatorLoc(),
John McCall9ae2f072010-08-23 23:25:46 +00005762 Callee.get(),
5763 First.get(),
5764 Second.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005765}
Mike Stump1eb44332009-09-09 15:08:12 +00005766
Douglas Gregorb98b1992009-08-11 05:31:07 +00005767template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005768ExprResult
John McCall454feb92009-12-08 09:21:05 +00005769TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5770 return getDerived().TransformCallExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005771}
Mike Stump1eb44332009-09-09 15:08:12 +00005772
Douglas Gregorb98b1992009-08-11 05:31:07 +00005773template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005774ExprResult
John McCall454feb92009-12-08 09:21:05 +00005775TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005776 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5777 if (!Type)
5778 return ExprError();
5779
John McCall60d7b3a2010-08-24 06:29:42 +00005780 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005781 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005782 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005783 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005784
Douglas Gregorb98b1992009-08-11 05:31:07 +00005785 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005786 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005787 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005788 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005789
Douglas Gregorb98b1992009-08-11 05:31:07 +00005790 // FIXME: Poor source location information here.
Mike Stump1eb44332009-09-09 15:08:12 +00005791 SourceLocation FakeLAngleLoc
Douglas Gregorb98b1992009-08-11 05:31:07 +00005792 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5793 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5794 SourceLocation FakeRParenLoc
5795 = SemaRef.PP.getLocForEndOfToken(
5796 E->getSubExpr()->getSourceRange().getEnd());
5797 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump1eb44332009-09-09 15:08:12 +00005798 E->getStmtClass(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005799 FakeLAngleLoc,
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005800 Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005801 FakeRAngleLoc,
5802 FakeRAngleLoc,
John McCall9ae2f072010-08-23 23:25:46 +00005803 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005804 FakeRParenLoc);
5805}
Mike Stump1eb44332009-09-09 15:08:12 +00005806
Douglas Gregorb98b1992009-08-11 05:31:07 +00005807template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005808ExprResult
John McCall454feb92009-12-08 09:21:05 +00005809TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5810 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005811}
Mike Stump1eb44332009-09-09 15:08:12 +00005812
5813template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005814ExprResult
John McCall454feb92009-12-08 09:21:05 +00005815TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5816 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005817}
5818
Douglas Gregorb98b1992009-08-11 05:31:07 +00005819template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005820ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005821TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005822 CXXReinterpretCastExpr *E) {
5823 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005824}
Mike Stump1eb44332009-09-09 15:08:12 +00005825
Douglas Gregorb98b1992009-08-11 05:31:07 +00005826template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005827ExprResult
John McCall454feb92009-12-08 09:21:05 +00005828TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5829 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005830}
Mike Stump1eb44332009-09-09 15:08:12 +00005831
Douglas Gregorb98b1992009-08-11 05:31:07 +00005832template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005833ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005834TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall454feb92009-12-08 09:21:05 +00005835 CXXFunctionalCastExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005836 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5837 if (!Type)
5838 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005839
John McCall60d7b3a2010-08-24 06:29:42 +00005840 ExprResult SubExpr
Douglas Gregor6eef5192009-12-14 19:27:10 +00005841 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005842 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005843 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005844
Douglas Gregorb98b1992009-08-11 05:31:07 +00005845 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005846 Type == E->getTypeInfoAsWritten() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005847 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005848 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005849
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005850 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005851 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005852 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005853 E->getRParenLoc());
5854}
Mike Stump1eb44332009-09-09 15:08:12 +00005855
Douglas Gregorb98b1992009-08-11 05:31:07 +00005856template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005857ExprResult
John McCall454feb92009-12-08 09:21:05 +00005858TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00005859 if (E->isTypeOperand()) {
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005860 TypeSourceInfo *TInfo
5861 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5862 if (!TInfo)
John McCallf312b1e2010-08-26 23:41:50 +00005863 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005864
Douglas Gregorb98b1992009-08-11 05:31:07 +00005865 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005866 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005867 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005868
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005869 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5870 E->getLocStart(),
5871 TInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00005872 E->getLocEnd());
5873 }
Mike Stump1eb44332009-09-09 15:08:12 +00005874
Douglas Gregorb98b1992009-08-11 05:31:07 +00005875 // We don't know whether the expression is potentially evaluated until
5876 // after we perform semantic analysis, so the expression is potentially
5877 // potentially evaluated.
Mike Stump1eb44332009-09-09 15:08:12 +00005878 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallf312b1e2010-08-26 23:41:50 +00005879 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump1eb44332009-09-09 15:08:12 +00005880
John McCall60d7b3a2010-08-24 06:29:42 +00005881 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005882 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005883 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005884
Douglas Gregorb98b1992009-08-11 05:31:07 +00005885 if (!getDerived().AlwaysRebuild() &&
5886 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005887 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005888
Douglas Gregor57fdc8a2010-04-26 22:37:10 +00005889 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5890 E->getLocStart(),
John McCall9ae2f072010-08-23 23:25:46 +00005891 SubExpr.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00005892 E->getLocEnd());
5893}
5894
5895template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005896ExprResult
Francois Pichet01b7c302010-09-08 12:20:18 +00005897TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5898 if (E->isTypeOperand()) {
5899 TypeSourceInfo *TInfo
5900 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5901 if (!TInfo)
5902 return ExprError();
5903
5904 if (!getDerived().AlwaysRebuild() &&
5905 TInfo == E->getTypeOperandSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005906 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005907
5908 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5909 E->getLocStart(),
5910 TInfo,
5911 E->getLocEnd());
5912 }
5913
5914 // We don't know whether the expression is potentially evaluated until
5915 // after we perform semantic analysis, so the expression is potentially
5916 // potentially evaluated.
5917 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5918
5919 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5920 if (SubExpr.isInvalid())
5921 return ExprError();
5922
5923 if (!getDerived().AlwaysRebuild() &&
5924 SubExpr.get() == E->getExprOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00005925 return SemaRef.Owned(E);
Francois Pichet01b7c302010-09-08 12:20:18 +00005926
5927 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5928 E->getLocStart(),
5929 SubExpr.get(),
5930 E->getLocEnd());
5931}
5932
5933template<typename Derived>
5934ExprResult
John McCall454feb92009-12-08 09:21:05 +00005935TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005936 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005937}
Mike Stump1eb44332009-09-09 15:08:12 +00005938
Douglas Gregorb98b1992009-08-11 05:31:07 +00005939template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005940ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00005941TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall454feb92009-12-08 09:21:05 +00005942 CXXNullPtrLiteralExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00005943 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005944}
Mike Stump1eb44332009-09-09 15:08:12 +00005945
Douglas Gregorb98b1992009-08-11 05:31:07 +00005946template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005947ExprResult
John McCall454feb92009-12-08 09:21:05 +00005948TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005949 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5950 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5951 QualType T = MD->getThisType(getSema().Context);
Mike Stump1eb44332009-09-09 15:08:12 +00005952
Douglas Gregorba48d6a2010-09-09 16:55:46 +00005953 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCall3fa5cae2010-10-26 07:05:15 +00005954 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005955
Douglas Gregor828a1972010-01-07 23:12:05 +00005956 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005957}
Mike Stump1eb44332009-09-09 15:08:12 +00005958
Douglas Gregorb98b1992009-08-11 05:31:07 +00005959template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005960ExprResult
John McCall454feb92009-12-08 09:21:05 +00005961TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00005962 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005963 if (SubExpr.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00005964 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005965
Douglas Gregorb98b1992009-08-11 05:31:07 +00005966 if (!getDerived().AlwaysRebuild() &&
5967 SubExpr.get() == E->getSubExpr())
John McCall3fa5cae2010-10-26 07:05:15 +00005968 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005969
John McCall9ae2f072010-08-23 23:25:46 +00005970 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00005971}
Mike Stump1eb44332009-09-09 15:08:12 +00005972
Douglas Gregorb98b1992009-08-11 05:31:07 +00005973template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005974ExprResult
John McCall454feb92009-12-08 09:21:05 +00005975TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump1eb44332009-09-09 15:08:12 +00005976 ParmVarDecl *Param
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00005977 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
5978 E->getParam()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00005979 if (!Param)
John McCallf312b1e2010-08-26 23:41:50 +00005980 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00005981
Chandler Carruth53cb6f82010-02-08 06:42:49 +00005982 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00005983 Param == E->getParam())
John McCall3fa5cae2010-10-26 07:05:15 +00005984 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00005985
Douglas Gregor036aed12009-12-23 23:03:06 +00005986 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregorb98b1992009-08-11 05:31:07 +00005987}
Mike Stump1eb44332009-09-09 15:08:12 +00005988
Douglas Gregorb98b1992009-08-11 05:31:07 +00005989template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00005990ExprResult
Douglas Gregorab6677e2010-09-08 00:15:04 +00005991TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
5992 CXXScalarValueInitExpr *E) {
5993 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
5994 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00005995 return ExprError();
Douglas Gregorab6677e2010-09-08 00:15:04 +00005996
Douglas Gregorb98b1992009-08-11 05:31:07 +00005997 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00005998 T == E->getTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00005999 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006000
Douglas Gregorab6677e2010-09-08 00:15:04 +00006001 return getDerived().RebuildCXXScalarValueInitExpr(T,
6002 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregored8abf12010-07-08 06:14:04 +00006003 E->getRParenLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006004}
Mike Stump1eb44332009-09-09 15:08:12 +00006005
Douglas Gregorb98b1992009-08-11 05:31:07 +00006006template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006007ExprResult
John McCall454feb92009-12-08 09:21:05 +00006008TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006009 // Transform the type that we're allocating
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006010 TypeSourceInfo *AllocTypeInfo
6011 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6012 if (!AllocTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006013 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006014
Douglas Gregorb98b1992009-08-11 05:31:07 +00006015 // Transform the size of the array we're allocating (if any).
John McCall60d7b3a2010-08-24 06:29:42 +00006016 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006017 if (ArraySize.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006018 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006019
Douglas Gregorb98b1992009-08-11 05:31:07 +00006020 // Transform the placement arguments (if any).
6021 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006022 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006023 if (getDerived().TransformExprs(E->getPlacementArgs(),
6024 E->getNumPlacementArgs(), true,
6025 PlacementArgs, &ArgumentChanged))
6026 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006027
Douglas Gregor43959a92009-08-20 07:17:43 +00006028 // transform the constructor arguments (if any).
John McCallca0408f2010-08-23 06:44:23 +00006029 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006030 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6031 ConstructorArgs, &ArgumentChanged))
6032 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006033
Douglas Gregor1af74512010-02-26 00:38:10 +00006034 // Transform constructor, new operator, and delete operator.
6035 CXXConstructorDecl *Constructor = 0;
6036 if (E->getConstructor()) {
6037 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006038 getDerived().TransformDecl(E->getLocStart(),
6039 E->getConstructor()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006040 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006041 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006042 }
6043
6044 FunctionDecl *OperatorNew = 0;
6045 if (E->getOperatorNew()) {
6046 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006047 getDerived().TransformDecl(E->getLocStart(),
6048 E->getOperatorNew()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006049 if (!OperatorNew)
John McCallf312b1e2010-08-26 23:41:50 +00006050 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006051 }
6052
6053 FunctionDecl *OperatorDelete = 0;
6054 if (E->getOperatorDelete()) {
6055 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006056 getDerived().TransformDecl(E->getLocStart(),
6057 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006058 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006059 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006060 }
Sean Huntc3021132010-05-05 15:23:54 +00006061
Douglas Gregorb98b1992009-08-11 05:31:07 +00006062 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006063 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006064 ArraySize.get() == E->getArraySize() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006065 Constructor == E->getConstructor() &&
6066 OperatorNew == E->getOperatorNew() &&
6067 OperatorDelete == E->getOperatorDelete() &&
6068 !ArgumentChanged) {
6069 // Mark any declarations we need as referenced.
6070 // FIXME: instantiation-specific.
6071 if (Constructor)
6072 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6073 if (OperatorNew)
6074 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6075 if (OperatorDelete)
6076 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCall3fa5cae2010-10-26 07:05:15 +00006077 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006078 }
Mike Stump1eb44332009-09-09 15:08:12 +00006079
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006080 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006081 if (!ArraySize.get()) {
6082 // If no array size was specified, but the new expression was
6083 // instantiated with an array type (e.g., "new T" where T is
6084 // instantiated with "int[4]"), extract the outer bound from the
6085 // array type as our array size. We do this with constant and
6086 // dependently-sized array types.
6087 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6088 if (!ArrayT) {
6089 // Do nothing
6090 } else if (const ConstantArrayType *ConsArrayT
6091 = dyn_cast<ConstantArrayType>(ArrayT)) {
Sean Huntc3021132010-05-05 15:23:54 +00006092 ArraySize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00006093 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6094 ConsArrayT->getSize(),
6095 SemaRef.Context.getSizeType(),
6096 /*FIXME:*/E->getLocStart()));
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006097 AllocType = ConsArrayT->getElementType();
6098 } else if (const DependentSizedArrayType *DepArrayT
6099 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6100 if (DepArrayT->getSizeExpr()) {
John McCall3fa5cae2010-10-26 07:05:15 +00006101 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor5b5ad842009-12-22 17:13:37 +00006102 AllocType = DepArrayT->getElementType();
6103 }
6104 }
6105 }
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006106
Douglas Gregorb98b1992009-08-11 05:31:07 +00006107 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6108 E->isGlobalNew(),
6109 /*FIXME:*/E->getLocStart(),
6110 move_arg(PlacementArgs),
6111 /*FIXME:*/E->getLocStart(),
Douglas Gregor4bd40312010-07-13 15:54:32 +00006112 E->getTypeIdParens(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006113 AllocType,
Douglas Gregor1bb2a932010-09-07 21:49:58 +00006114 AllocTypeInfo,
John McCall9ae2f072010-08-23 23:25:46 +00006115 ArraySize.get(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006116 /*FIXME:*/E->getLocStart(),
6117 move_arg(ConstructorArgs),
Mike Stump1eb44332009-09-09 15:08:12 +00006118 E->getLocEnd());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006119}
Mike Stump1eb44332009-09-09 15:08:12 +00006120
Douglas Gregorb98b1992009-08-11 05:31:07 +00006121template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006122ExprResult
John McCall454feb92009-12-08 09:21:05 +00006123TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006124 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006125 if (Operand.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006126 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006127
Douglas Gregor1af74512010-02-26 00:38:10 +00006128 // Transform the delete operator, if known.
6129 FunctionDecl *OperatorDelete = 0;
6130 if (E->getOperatorDelete()) {
6131 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006132 getDerived().TransformDecl(E->getLocStart(),
6133 E->getOperatorDelete()));
Douglas Gregor1af74512010-02-26 00:38:10 +00006134 if (!OperatorDelete)
John McCallf312b1e2010-08-26 23:41:50 +00006135 return ExprError();
Douglas Gregor1af74512010-02-26 00:38:10 +00006136 }
Sean Huntc3021132010-05-05 15:23:54 +00006137
Douglas Gregorb98b1992009-08-11 05:31:07 +00006138 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1af74512010-02-26 00:38:10 +00006139 Operand.get() == E->getArgument() &&
6140 OperatorDelete == E->getOperatorDelete()) {
6141 // Mark any declarations we need as referenced.
6142 // FIXME: instantiation-specific.
6143 if (OperatorDelete)
6144 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor5833b0b2010-09-14 22:55:20 +00006145
6146 if (!E->getArgument()->isTypeDependent()) {
6147 QualType Destroyed = SemaRef.Context.getBaseElementType(
6148 E->getDestroyedType());
6149 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6150 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6151 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6152 SemaRef.LookupDestructor(Record));
6153 }
6154 }
6155
John McCall3fa5cae2010-10-26 07:05:15 +00006156 return SemaRef.Owned(E);
Douglas Gregor1af74512010-02-26 00:38:10 +00006157 }
Mike Stump1eb44332009-09-09 15:08:12 +00006158
Douglas Gregorb98b1992009-08-11 05:31:07 +00006159 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6160 E->isGlobalDelete(),
6161 E->isArrayForm(),
John McCall9ae2f072010-08-23 23:25:46 +00006162 Operand.get());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006163}
Mike Stump1eb44332009-09-09 15:08:12 +00006164
Douglas Gregorb98b1992009-08-11 05:31:07 +00006165template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006166ExprResult
Douglas Gregora71d8192009-09-04 17:36:40 +00006167TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall454feb92009-12-08 09:21:05 +00006168 CXXPseudoDestructorExpr *E) {
John McCall60d7b3a2010-08-24 06:29:42 +00006169 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora71d8192009-09-04 17:36:40 +00006170 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006171 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006172
John McCallb3d87482010-08-24 05:47:05 +00006173 ParsedType ObjectTypePtr;
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006174 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006175 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006176 E->getOperatorLoc(),
6177 E->isArrow()? tok::arrow : tok::period,
6178 ObjectTypePtr,
6179 MayBePseudoDestructor);
6180 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006181 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006182
John McCallb3d87482010-08-24 05:47:05 +00006183 QualType ObjectType = ObjectTypePtr.get();
John McCall43fed0d2010-11-12 08:19:04 +00006184 NestedNameSpecifier *Qualifier = E->getQualifier();
6185 if (Qualifier) {
6186 Qualifier
6187 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6188 E->getQualifierRange(),
6189 ObjectType);
6190 if (!Qualifier)
6191 return ExprError();
6192 }
Mike Stump1eb44332009-09-09 15:08:12 +00006193
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006194 PseudoDestructorTypeStorage Destroyed;
6195 if (E->getDestroyedTypeInfo()) {
6196 TypeSourceInfo *DestroyedTypeInfo
John McCall43fed0d2010-11-12 08:19:04 +00006197 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6198 ObjectType, 0, Qualifier);
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006199 if (!DestroyedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006200 return ExprError();
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006201 Destroyed = DestroyedTypeInfo;
6202 } else if (ObjectType->isDependentType()) {
6203 // We aren't likely to be able to resolve the identifier down to a type
6204 // now anyway, so just retain the identifier.
6205 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6206 E->getDestroyedTypeLoc());
6207 } else {
6208 // Look for a destructor known with the given name.
6209 CXXScopeSpec SS;
6210 if (Qualifier) {
6211 SS.setScopeRep(Qualifier);
6212 SS.setRange(E->getQualifierRange());
6213 }
Sean Huntc3021132010-05-05 15:23:54 +00006214
John McCallb3d87482010-08-24 05:47:05 +00006215 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006216 *E->getDestroyedTypeIdentifier(),
6217 E->getDestroyedTypeLoc(),
6218 /*Scope=*/0,
6219 SS, ObjectTypePtr,
6220 false);
6221 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006222 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006223
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006224 Destroyed
6225 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6226 E->getDestroyedTypeLoc());
6227 }
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006228
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006229 TypeSourceInfo *ScopeTypeInfo = 0;
6230 if (E->getScopeTypeInfo()) {
John McCall43fed0d2010-11-12 08:19:04 +00006231 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006232 if (!ScopeTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006233 return ExprError();
Douglas Gregora71d8192009-09-04 17:36:40 +00006234 }
Sean Huntc3021132010-05-05 15:23:54 +00006235
John McCall9ae2f072010-08-23 23:25:46 +00006236 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006237 E->getOperatorLoc(),
6238 E->isArrow(),
Douglas Gregora71d8192009-09-04 17:36:40 +00006239 Qualifier,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00006240 E->getQualifierRange(),
6241 ScopeTypeInfo,
6242 E->getColonColonLoc(),
Douglas Gregorfce46ee2010-02-24 23:50:37 +00006243 E->getTildeLoc(),
Douglas Gregora2e7dd22010-02-25 01:56:36 +00006244 Destroyed);
Douglas Gregora71d8192009-09-04 17:36:40 +00006245}
Mike Stump1eb44332009-09-09 15:08:12 +00006246
Douglas Gregora71d8192009-09-04 17:36:40 +00006247template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006248ExprResult
John McCallba135432009-11-21 08:51:07 +00006249TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall454feb92009-12-08 09:21:05 +00006250 UnresolvedLookupExpr *Old) {
John McCallf7a1a742009-11-24 19:00:30 +00006251 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6252
6253 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6254 Sema::LookupOrdinaryName);
6255
6256 // Transform all the decls.
6257 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6258 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006259 NamedDecl *InstD = static_cast<NamedDecl*>(
6260 getDerived().TransformDecl(Old->getNameLoc(),
6261 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006262 if (!InstD) {
6263 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6264 // This can happen because of dependent hiding.
6265 if (isa<UsingShadowDecl>(*I))
6266 continue;
6267 else
John McCallf312b1e2010-08-26 23:41:50 +00006268 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006269 }
John McCallf7a1a742009-11-24 19:00:30 +00006270
6271 // Expand using declarations.
6272 if (isa<UsingDecl>(InstD)) {
6273 UsingDecl *UD = cast<UsingDecl>(InstD);
6274 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6275 E = UD->shadow_end(); I != E; ++I)
6276 R.addDecl(*I);
6277 continue;
6278 }
6279
6280 R.addDecl(InstD);
6281 }
6282
6283 // Resolve a kind, but don't do any further analysis. If it's
6284 // ambiguous, the callee needs to deal with it.
6285 R.resolveKind();
6286
6287 // Rebuild the nested-name qualifier, if present.
6288 CXXScopeSpec SS;
6289 NestedNameSpecifier *Qualifier = 0;
6290 if (Old->getQualifier()) {
6291 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006292 Old->getQualifierRange());
John McCallf7a1a742009-11-24 19:00:30 +00006293 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006294 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006295
John McCallf7a1a742009-11-24 19:00:30 +00006296 SS.setScopeRep(Qualifier);
6297 SS.setRange(Old->getQualifierRange());
Sean Huntc3021132010-05-05 15:23:54 +00006298 }
6299
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006300 if (Old->getNamingClass()) {
Douglas Gregor66c45152010-04-27 16:10:10 +00006301 CXXRecordDecl *NamingClass
6302 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6303 Old->getNameLoc(),
6304 Old->getNamingClass()));
6305 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006306 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006307
Douglas Gregor66c45152010-04-27 16:10:10 +00006308 R.setNamingClass(NamingClass);
John McCallf7a1a742009-11-24 19:00:30 +00006309 }
6310
6311 // If we have no template arguments, it's a normal declaration name.
6312 if (!Old->hasExplicitTemplateArgs())
6313 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6314
6315 // If we have template arguments, rebuild them, then rebuild the
6316 // templateid expression.
6317 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006318 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6319 Old->getNumTemplateArgs(),
6320 TransArgs))
6321 return ExprError();
John McCallf7a1a742009-11-24 19:00:30 +00006322
6323 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6324 TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006325}
Mike Stump1eb44332009-09-09 15:08:12 +00006326
Douglas Gregorb98b1992009-08-11 05:31:07 +00006327template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006328ExprResult
John McCall454feb92009-12-08 09:21:05 +00006329TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006330 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6331 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006332 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006333
Douglas Gregorb98b1992009-08-11 05:31:07 +00006334 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3d37c0a2010-09-09 16:14:44 +00006335 T == E->getQueriedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006336 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006337
Mike Stump1eb44332009-09-09 15:08:12 +00006338 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006339 E->getLocStart(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006340 T,
6341 E->getLocEnd());
6342}
Mike Stump1eb44332009-09-09 15:08:12 +00006343
Douglas Gregorb98b1992009-08-11 05:31:07 +00006344template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006345ExprResult
Francois Pichet6ad6f282010-12-07 00:08:36 +00006346TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6347 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6348 if (!LhsT)
6349 return ExprError();
6350
6351 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6352 if (!RhsT)
6353 return ExprError();
6354
6355 if (!getDerived().AlwaysRebuild() &&
6356 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6357 return SemaRef.Owned(E);
6358
6359 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6360 E->getLocStart(),
6361 LhsT, RhsT,
6362 E->getLocEnd());
6363}
6364
6365template<typename Derived>
6366ExprResult
John McCall865d4472009-11-19 22:55:06 +00006367TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006368 DependentScopeDeclRefExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006369 NestedNameSpecifier *NNS
Douglas Gregorf17bb742009-10-22 17:20:55 +00006370 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006371 E->getQualifierRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006372 if (!NNS)
John McCallf312b1e2010-08-26 23:41:50 +00006373 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006374
John McCall43fed0d2010-11-12 08:19:04 +00006375 // TODO: If this is a conversion-function-id, verify that the
6376 // destination type name (if present) resolves the same way after
6377 // instantiation as it did in the local scope.
6378
Abramo Bagnara25777432010-08-11 22:01:17 +00006379 DeclarationNameInfo NameInfo
6380 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6381 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006382 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006383
John McCallf7a1a742009-11-24 19:00:30 +00006384 if (!E->hasExplicitTemplateArgs()) {
6385 if (!getDerived().AlwaysRebuild() &&
6386 NNS == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006387 // Note: it is sufficient to compare the Name component of NameInfo:
6388 // if name has not changed, DNLoc has not changed either.
6389 NameInfo.getName() == E->getDeclName())
John McCall3fa5cae2010-10-26 07:05:15 +00006390 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006391
John McCallf7a1a742009-11-24 19:00:30 +00006392 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6393 E->getQualifierRange(),
Abramo Bagnara25777432010-08-11 22:01:17 +00006394 NameInfo,
John McCallf7a1a742009-11-24 19:00:30 +00006395 /*TemplateArgs*/ 0);
Douglas Gregorf17bb742009-10-22 17:20:55 +00006396 }
John McCalld5532b62009-11-23 01:53:49 +00006397
6398 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006399 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6400 E->getNumTemplateArgs(),
6401 TransArgs))
6402 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +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 &TransArgs);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006408}
6409
6410template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006411ExprResult
John McCall454feb92009-12-08 09:21:05 +00006412TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregor321725d2010-02-03 03:01:57 +00006413 // CXXConstructExprs are always implicit, so when we have a
6414 // 1-argument construction we just transform that argument.
6415 if (E->getNumArgs() == 1 ||
6416 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6417 return getDerived().TransformExpr(E->getArg(0));
6418
Douglas Gregorb98b1992009-08-11 05:31:07 +00006419 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6420
6421 QualType T = getDerived().TransformType(E->getType());
6422 if (T.isNull())
John McCallf312b1e2010-08-26 23:41:50 +00006423 return ExprError();
Douglas Gregorb98b1992009-08-11 05:31:07 +00006424
6425 CXXConstructorDecl *Constructor
6426 = cast_or_null<CXXConstructorDecl>(
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006427 getDerived().TransformDecl(E->getLocStart(),
6428 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006429 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006430 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006431
Douglas Gregorb98b1992009-08-11 05:31:07 +00006432 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006433 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006434 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6435 &ArgumentChanged))
6436 return ExprError();
6437
Douglas Gregorb98b1992009-08-11 05:31:07 +00006438 if (!getDerived().AlwaysRebuild() &&
6439 T == E->getType() &&
6440 Constructor == E->getConstructor() &&
Douglas Gregorc845aad2010-02-26 00:01:57 +00006441 !ArgumentChanged) {
Douglas Gregor1af74512010-02-26 00:38:10 +00006442 // Mark the constructor as referenced.
6443 // FIXME: Instantiation-specific
Douglas Gregorc845aad2010-02-26 00:01:57 +00006444 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006445 return SemaRef.Owned(E);
Douglas Gregorc845aad2010-02-26 00:01:57 +00006446 }
Mike Stump1eb44332009-09-09 15:08:12 +00006447
Douglas Gregor4411d2e2009-12-14 16:27:04 +00006448 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6449 Constructor, E->isElidable(),
Douglas Gregor8c3e5542010-08-22 17:20:18 +00006450 move_arg(Args),
6451 E->requiresZeroInitialization(),
Chandler Carruth428edaf2010-10-25 08:47:36 +00006452 E->getConstructionKind(),
6453 E->getParenRange());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006454}
Mike Stump1eb44332009-09-09 15:08:12 +00006455
Douglas Gregorb98b1992009-08-11 05:31:07 +00006456/// \brief Transform a C++ temporary-binding expression.
6457///
Douglas Gregor51326552009-12-24 18:51:59 +00006458/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6459/// transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006460template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006461ExprResult
John McCall454feb92009-12-08 09:21:05 +00006462TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006463 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006464}
Mike Stump1eb44332009-09-09 15:08:12 +00006465
John McCall4765fa02010-12-06 08:20:24 +00006466/// \brief Transform a C++ expression that contains cleanups that should
6467/// be run after the expression is evaluated.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006468///
John McCall4765fa02010-12-06 08:20:24 +00006469/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor51326552009-12-24 18:51:59 +00006470/// just transform the subexpression and return that.
Douglas Gregorb98b1992009-08-11 05:31:07 +00006471template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006472ExprResult
John McCall4765fa02010-12-06 08:20:24 +00006473TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor51326552009-12-24 18:51:59 +00006474 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006475}
Mike Stump1eb44332009-09-09 15:08:12 +00006476
Douglas Gregorb98b1992009-08-11 05:31:07 +00006477template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006478ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006479TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregorab6677e2010-09-08 00:15:04 +00006480 CXXTemporaryObjectExpr *E) {
6481 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6482 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006483 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006484
Douglas Gregorb98b1992009-08-11 05:31:07 +00006485 CXXConstructorDecl *Constructor
6486 = cast_or_null<CXXConstructorDecl>(
Sean Huntc3021132010-05-05 15:23:54 +00006487 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006488 E->getConstructor()));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006489 if (!Constructor)
John McCallf312b1e2010-08-26 23:41:50 +00006490 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006491
Douglas Gregorb98b1992009-08-11 05:31:07 +00006492 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006493 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006494 Args.reserve(E->getNumArgs());
Douglas Gregoraa165f82011-01-03 19:04:46 +00006495 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6496 &ArgumentChanged))
6497 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006498
Douglas Gregorb98b1992009-08-11 05:31:07 +00006499 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006500 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006501 Constructor == E->getConstructor() &&
Douglas Gregor91be6f52010-03-02 17:18:33 +00006502 !ArgumentChanged) {
6503 // FIXME: Instantiation-specific
Douglas Gregorab6677e2010-09-08 00:15:04 +00006504 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCall3fa5cae2010-10-26 07:05:15 +00006505 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor91be6f52010-03-02 17:18:33 +00006506 }
Douglas Gregorab6677e2010-09-08 00:15:04 +00006507
6508 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6509 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006510 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006511 E->getLocEnd());
6512}
Mike Stump1eb44332009-09-09 15:08:12 +00006513
Douglas Gregorb98b1992009-08-11 05:31:07 +00006514template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006515ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00006516TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall454feb92009-12-08 09:21:05 +00006517 CXXUnresolvedConstructExpr *E) {
Douglas Gregorab6677e2010-09-08 00:15:04 +00006518 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6519 if (!T)
John McCallf312b1e2010-08-26 23:41:50 +00006520 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006521
Douglas Gregorb98b1992009-08-11 05:31:07 +00006522 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006523 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006524 Args.reserve(E->arg_size());
6525 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6526 &ArgumentChanged))
6527 return ExprError();
6528
Douglas Gregorb98b1992009-08-11 05:31:07 +00006529 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorab6677e2010-09-08 00:15:04 +00006530 T == E->getTypeSourceInfo() &&
Douglas Gregorb98b1992009-08-11 05:31:07 +00006531 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006532 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006533
Douglas Gregorb98b1992009-08-11 05:31:07 +00006534 // FIXME: we're faking the locations of the commas
Douglas Gregorab6677e2010-09-08 00:15:04 +00006535 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006536 E->getLParenLoc(),
6537 move_arg(Args),
Douglas Gregorb98b1992009-08-11 05:31:07 +00006538 E->getRParenLoc());
6539}
Mike Stump1eb44332009-09-09 15:08:12 +00006540
Douglas Gregorb98b1992009-08-11 05:31:07 +00006541template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006542ExprResult
John McCall865d4472009-11-19 22:55:06 +00006543TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnara25777432010-08-11 22:01:17 +00006544 CXXDependentScopeMemberExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006545 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006546 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006547 Expr *OldBase;
6548 QualType BaseType;
6549 QualType ObjectType;
6550 if (!E->isImplicitAccess()) {
6551 OldBase = E->getBase();
6552 Base = getDerived().TransformExpr(OldBase);
6553 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006554 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006555
John McCallaa81e162009-12-01 22:10:20 +00006556 // Start the member reference and compute the object's type.
John McCallb3d87482010-08-24 05:47:05 +00006557 ParsedType ObjectTy;
Douglas Gregord4dca082010-02-24 18:44:31 +00006558 bool MayBePseudoDestructor = false;
John McCall9ae2f072010-08-23 23:25:46 +00006559 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006560 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006561 E->isArrow()? tok::arrow : tok::period,
Douglas Gregord4dca082010-02-24 18:44:31 +00006562 ObjectTy,
6563 MayBePseudoDestructor);
John McCallaa81e162009-12-01 22:10:20 +00006564 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006565 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006566
John McCallb3d87482010-08-24 05:47:05 +00006567 ObjectType = ObjectTy.get();
John McCallaa81e162009-12-01 22:10:20 +00006568 BaseType = ((Expr*) Base.get())->getType();
6569 } else {
6570 OldBase = 0;
6571 BaseType = getDerived().TransformType(E->getBaseType());
6572 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6573 }
Mike Stump1eb44332009-09-09 15:08:12 +00006574
Douglas Gregor6cd21982009-10-20 05:58:46 +00006575 // Transform the first part of the nested-name-specifier that qualifies
6576 // the member name.
Douglas Gregorc68afe22009-09-03 21:38:09 +00006577 NamedDecl *FirstQualifierInScope
Douglas Gregor6cd21982009-10-20 05:58:46 +00006578 = getDerived().TransformFirstQualifierInScope(
6579 E->getFirstQualifierFoundInScope(),
6580 E->getQualifierRange().getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00006581
Douglas Gregora38c6872009-09-03 16:14:30 +00006582 NestedNameSpecifier *Qualifier = 0;
6583 if (E->getQualifier()) {
6584 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6585 E->getQualifierRange(),
John McCallaa81e162009-12-01 22:10:20 +00006586 ObjectType,
6587 FirstQualifierInScope);
Douglas Gregora38c6872009-09-03 16:14:30 +00006588 if (!Qualifier)
John McCallf312b1e2010-08-26 23:41:50 +00006589 return ExprError();
Douglas Gregora38c6872009-09-03 16:14:30 +00006590 }
Mike Stump1eb44332009-09-09 15:08:12 +00006591
John McCall43fed0d2010-11-12 08:19:04 +00006592 // TODO: If this is a conversion-function-id, verify that the
6593 // destination type name (if present) resolves the same way after
6594 // instantiation as it did in the local scope.
6595
Abramo Bagnara25777432010-08-11 22:01:17 +00006596 DeclarationNameInfo NameInfo
John McCall43fed0d2010-11-12 08:19:04 +00006597 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnara25777432010-08-11 22:01:17 +00006598 if (!NameInfo.getName())
John McCallf312b1e2010-08-26 23:41:50 +00006599 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006600
John McCallaa81e162009-12-01 22:10:20 +00006601 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006602 // This is a reference to a member without an explicitly-specified
6603 // template argument list. Optimize for this common case.
6604 if (!getDerived().AlwaysRebuild() &&
John McCallaa81e162009-12-01 22:10:20 +00006605 Base.get() == OldBase &&
6606 BaseType == E->getBaseType() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006607 Qualifier == E->getQualifier() &&
Abramo Bagnara25777432010-08-11 22:01:17 +00006608 NameInfo.getName() == E->getMember() &&
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006609 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCall3fa5cae2010-10-26 07:05:15 +00006610 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006611
John McCall9ae2f072010-08-23 23:25:46 +00006612 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006613 BaseType,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006614 E->isArrow(),
6615 E->getOperatorLoc(),
6616 Qualifier,
6617 E->getQualifierRange(),
John McCall129e2df2009-11-30 22:42:35 +00006618 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006619 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006620 /*TemplateArgs*/ 0);
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006621 }
6622
John McCalld5532b62009-11-23 01:53:49 +00006623 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006624 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6625 E->getNumTemplateArgs(),
6626 TransArgs))
6627 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006628
John McCall9ae2f072010-08-23 23:25:46 +00006629 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006630 BaseType,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006631 E->isArrow(),
6632 E->getOperatorLoc(),
Douglas Gregora38c6872009-09-03 16:14:30 +00006633 Qualifier,
6634 E->getQualifierRange(),
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00006635 FirstQualifierInScope,
Abramo Bagnara25777432010-08-11 22:01:17 +00006636 NameInfo,
John McCall129e2df2009-11-30 22:42:35 +00006637 &TransArgs);
6638}
6639
6640template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006641ExprResult
John McCall454feb92009-12-08 09:21:05 +00006642TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall129e2df2009-11-30 22:42:35 +00006643 // Transform the base of the expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006644 ExprResult Base((Expr*) 0);
John McCallaa81e162009-12-01 22:10:20 +00006645 QualType BaseType;
6646 if (!Old->isImplicitAccess()) {
6647 Base = getDerived().TransformExpr(Old->getBase());
6648 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006649 return ExprError();
John McCallaa81e162009-12-01 22:10:20 +00006650 BaseType = ((Expr*) Base.get())->getType();
6651 } else {
6652 BaseType = getDerived().TransformType(Old->getBaseType());
6653 }
John McCall129e2df2009-11-30 22:42:35 +00006654
6655 NestedNameSpecifier *Qualifier = 0;
6656 if (Old->getQualifier()) {
6657 Qualifier
6658 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregoredc90502010-02-25 04:46:04 +00006659 Old->getQualifierRange());
John McCall129e2df2009-11-30 22:42:35 +00006660 if (Qualifier == 0)
John McCallf312b1e2010-08-26 23:41:50 +00006661 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006662 }
6663
Abramo Bagnara25777432010-08-11 22:01:17 +00006664 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall129e2df2009-11-30 22:42:35 +00006665 Sema::LookupOrdinaryName);
6666
6667 // Transform all the decls.
6668 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6669 E = Old->decls_end(); I != E; ++I) {
Douglas Gregor7c1e98f2010-03-01 15:56:25 +00006670 NamedDecl *InstD = static_cast<NamedDecl*>(
6671 getDerived().TransformDecl(Old->getMemberLoc(),
6672 *I));
John McCall9f54ad42009-12-10 09:41:52 +00006673 if (!InstD) {
6674 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6675 // This can happen because of dependent hiding.
6676 if (isa<UsingShadowDecl>(*I))
6677 continue;
6678 else
John McCallf312b1e2010-08-26 23:41:50 +00006679 return ExprError();
John McCall9f54ad42009-12-10 09:41:52 +00006680 }
John McCall129e2df2009-11-30 22:42:35 +00006681
6682 // Expand using declarations.
6683 if (isa<UsingDecl>(InstD)) {
6684 UsingDecl *UD = cast<UsingDecl>(InstD);
6685 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6686 E = UD->shadow_end(); I != E; ++I)
6687 R.addDecl(*I);
6688 continue;
6689 }
6690
6691 R.addDecl(InstD);
6692 }
6693
6694 R.resolveKind();
6695
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006696 // Determine the naming class.
Chandler Carruth042d6f92010-05-19 01:37:01 +00006697 if (Old->getNamingClass()) {
Sean Huntc3021132010-05-05 15:23:54 +00006698 CXXRecordDecl *NamingClass
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006699 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregor66c45152010-04-27 16:10:10 +00006700 Old->getMemberLoc(),
6701 Old->getNamingClass()));
6702 if (!NamingClass)
John McCallf312b1e2010-08-26 23:41:50 +00006703 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006704
Douglas Gregor66c45152010-04-27 16:10:10 +00006705 R.setNamingClass(NamingClass);
Douglas Gregorc96be1e2010-04-27 18:19:34 +00006706 }
Sean Huntc3021132010-05-05 15:23:54 +00006707
John McCall129e2df2009-11-30 22:42:35 +00006708 TemplateArgumentListInfo TransArgs;
6709 if (Old->hasExplicitTemplateArgs()) {
6710 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6711 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregorfcc12532010-12-20 17:31:10 +00006712 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6713 Old->getNumTemplateArgs(),
6714 TransArgs))
6715 return ExprError();
John McCall129e2df2009-11-30 22:42:35 +00006716 }
John McCallc2233c52010-01-15 08:34:02 +00006717
6718 // FIXME: to do this check properly, we will need to preserve the
6719 // first-qualifier-in-scope here, just in case we had a dependent
6720 // base (and therefore couldn't do the check) and a
6721 // nested-name-qualifier (and therefore could do the lookup).
6722 NamedDecl *FirstQualifierInScope = 0;
Sean Huntc3021132010-05-05 15:23:54 +00006723
John McCall9ae2f072010-08-23 23:25:46 +00006724 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCallaa81e162009-12-01 22:10:20 +00006725 BaseType,
John McCall129e2df2009-11-30 22:42:35 +00006726 Old->getOperatorLoc(),
6727 Old->isArrow(),
6728 Qualifier,
6729 Old->getQualifierRange(),
John McCallc2233c52010-01-15 08:34:02 +00006730 FirstQualifierInScope,
John McCall129e2df2009-11-30 22:42:35 +00006731 R,
6732 (Old->hasExplicitTemplateArgs()
6733 ? &TransArgs : 0));
Douglas Gregorb98b1992009-08-11 05:31:07 +00006734}
6735
6736template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006737ExprResult
Sebastian Redl2e156222010-09-10 20:55:43 +00006738TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6739 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6740 if (SubExpr.isInvalid())
6741 return ExprError();
6742
6743 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCall3fa5cae2010-10-26 07:05:15 +00006744 return SemaRef.Owned(E);
Sebastian Redl2e156222010-09-10 20:55:43 +00006745
6746 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6747}
6748
6749template<typename Derived>
6750ExprResult
Douglas Gregorbe230c32011-01-03 17:17:50 +00006751TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
6752 llvm_unreachable("pack expansion expression in unhandled context");
6753 return ExprError();
6754}
Douglas Gregoree8aff02011-01-04 17:33:58 +00006755
6756template<typename Derived>
6757ExprResult
6758TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6759 // If E is not value-dependent, then nothing will change when we transform it.
6760 // Note: This is an instantiation-centric view.
6761 if (!E->isValueDependent())
6762 return SemaRef.Owned(E);
6763
6764 // Note: None of the implementations of TryExpandParameterPacks can ever
6765 // produce a diagnostic when given only a single unexpanded parameter pack,
6766 // so
6767 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6768 bool ShouldExpand = false;
Douglas Gregord3731192011-01-10 07:32:04 +00006769 bool RetainExpansion = false;
Douglas Gregoree8aff02011-01-04 17:33:58 +00006770 unsigned NumExpansions = 0;
6771 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6772 &Unexpanded, 1,
Douglas Gregord3731192011-01-10 07:32:04 +00006773 ShouldExpand, RetainExpansion,
6774 NumExpansions))
Douglas Gregoree8aff02011-01-04 17:33:58 +00006775 return ExprError();
Douglas Gregorbe230c32011-01-03 17:17:50 +00006776
Douglas Gregord3731192011-01-10 07:32:04 +00006777 if (!ShouldExpand || RetainExpansion)
Douglas Gregoree8aff02011-01-04 17:33:58 +00006778 return SemaRef.Owned(E);
6779
6780 // We now know the length of the parameter pack, so build a new expression
6781 // that stores that length.
6782 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6783 E->getPackLoc(), E->getRParenLoc(),
6784 NumExpansions);
6785}
6786
Douglas Gregorbe230c32011-01-03 17:17:50 +00006787template<typename Derived>
6788ExprResult
John McCall454feb92009-12-08 09:21:05 +00006789TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006790 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006791}
6792
Mike Stump1eb44332009-09-09 15:08:12 +00006793template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006794ExprResult
John McCall454feb92009-12-08 09:21:05 +00006795TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregor81d34662010-04-20 15:39:42 +00006796 TypeSourceInfo *EncodedTypeInfo
6797 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6798 if (!EncodedTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006799 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006800
Douglas Gregorb98b1992009-08-11 05:31:07 +00006801 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor81d34662010-04-20 15:39:42 +00006802 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCall3fa5cae2010-10-26 07:05:15 +00006803 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006804
6805 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregor81d34662010-04-20 15:39:42 +00006806 EncodedTypeInfo,
Douglas Gregorb98b1992009-08-11 05:31:07 +00006807 E->getRParenLoc());
6808}
Mike Stump1eb44332009-09-09 15:08:12 +00006809
Douglas Gregorb98b1992009-08-11 05:31:07 +00006810template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006811ExprResult
John McCall454feb92009-12-08 09:21:05 +00006812TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregor92e986e2010-04-22 16:44:27 +00006813 // Transform arguments.
6814 bool ArgChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006815 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006816 Args.reserve(E->getNumArgs());
6817 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6818 &ArgChanged))
6819 return ExprError();
6820
Douglas Gregor92e986e2010-04-22 16:44:27 +00006821 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6822 // Class message: transform the receiver type.
6823 TypeSourceInfo *ReceiverTypeInfo
6824 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6825 if (!ReceiverTypeInfo)
John McCallf312b1e2010-08-26 23:41:50 +00006826 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006827
Douglas Gregor92e986e2010-04-22 16:44:27 +00006828 // If nothing changed, just retain the existing message send.
6829 if (!getDerived().AlwaysRebuild() &&
6830 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006831 return SemaRef.Owned(E);
Douglas Gregor92e986e2010-04-22 16:44:27 +00006832
6833 // Build a new class message send.
6834 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6835 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006836 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006837 E->getMethodDecl(),
6838 E->getLeftLoc(),
6839 move_arg(Args),
6840 E->getRightLoc());
6841 }
6842
6843 // Instance message: transform the receiver
6844 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6845 "Only class and instance messages may be instantiated");
John McCall60d7b3a2010-08-24 06:29:42 +00006846 ExprResult Receiver
Douglas Gregor92e986e2010-04-22 16:44:27 +00006847 = getDerived().TransformExpr(E->getInstanceReceiver());
6848 if (Receiver.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006849 return ExprError();
Douglas Gregor92e986e2010-04-22 16:44:27 +00006850
6851 // If nothing changed, just retain the existing message send.
6852 if (!getDerived().AlwaysRebuild() &&
6853 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006854 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006855
Douglas Gregor92e986e2010-04-22 16:44:27 +00006856 // Build a new instance message send.
John McCall9ae2f072010-08-23 23:25:46 +00006857 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006858 E->getSelector(),
Argyrios Kyrtzidisf40f0d52010-12-10 20:08:27 +00006859 E->getSelectorLoc(),
Douglas Gregor92e986e2010-04-22 16:44:27 +00006860 E->getMethodDecl(),
6861 E->getLeftLoc(),
6862 move_arg(Args),
6863 E->getRightLoc());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006864}
6865
Mike Stump1eb44332009-09-09 15:08:12 +00006866template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006867ExprResult
John McCall454feb92009-12-08 09:21:05 +00006868TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006869 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006870}
6871
Mike Stump1eb44332009-09-09 15:08:12 +00006872template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006873ExprResult
John McCall454feb92009-12-08 09:21:05 +00006874TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCall3fa5cae2010-10-26 07:05:15 +00006875 return SemaRef.Owned(E);
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>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006881 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006882 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006883 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006884 return ExprError();
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006885
6886 // We don't need to transform the ivar; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006887
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006888 // If nothing changed, just retain the existing expression.
6889 if (!getDerived().AlwaysRebuild() &&
6890 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006891 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006892
John McCall9ae2f072010-08-23 23:25:46 +00006893 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006894 E->getLocation(),
6895 E->isArrow(), E->isFreeIvar());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006896}
6897
Mike Stump1eb44332009-09-09 15:08:12 +00006898template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006899ExprResult
John McCall454feb92009-12-08 09:21:05 +00006900TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCall12f78a62010-12-02 01:19:52 +00006901 // 'super' and types never change. Property never changes. Just
6902 // retain the existing expression.
6903 if (!E->isObjectReceiver())
John McCall3fa5cae2010-10-26 07:05:15 +00006904 return SemaRef.Owned(E);
Fariborz Jahanian8ac2d442010-10-14 16:04:05 +00006905
Douglas Gregore3303542010-04-26 20:47:02 +00006906 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006907 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregore3303542010-04-26 20:47:02 +00006908 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006909 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006910
Douglas Gregore3303542010-04-26 20:47:02 +00006911 // We don't need to transform the property; it will never change.
Sean Huntc3021132010-05-05 15:23:54 +00006912
Douglas Gregore3303542010-04-26 20:47:02 +00006913 // If nothing changed, just retain the existing expression.
6914 if (!getDerived().AlwaysRebuild() &&
6915 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006916 return SemaRef.Owned(E);
Douglas Gregorb98b1992009-08-11 05:31:07 +00006917
John McCall12f78a62010-12-02 01:19:52 +00006918 if (E->isExplicitProperty())
6919 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6920 E->getExplicitProperty(),
6921 E->getLocation());
6922
6923 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6924 E->getType(),
6925 E->getImplicitPropertyGetter(),
6926 E->getImplicitPropertySetter(),
6927 E->getLocation());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006928}
6929
Mike Stump1eb44332009-09-09 15:08:12 +00006930template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006931ExprResult
John McCall454feb92009-12-08 09:21:05 +00006932TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006933 // Transform the base expression.
John McCall60d7b3a2010-08-24 06:29:42 +00006934 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006935 if (Base.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00006936 return ExprError();
Sean Huntc3021132010-05-05 15:23:54 +00006937
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006938 // If nothing changed, just retain the existing expression.
6939 if (!getDerived().AlwaysRebuild() &&
6940 Base.get() == E->getBase())
John McCall3fa5cae2010-10-26 07:05:15 +00006941 return SemaRef.Owned(E);
Sean Huntc3021132010-05-05 15:23:54 +00006942
John McCall9ae2f072010-08-23 23:25:46 +00006943 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregorf9b9eab2010-04-26 20:11:03 +00006944 E->isArrow());
Douglas Gregorb98b1992009-08-11 05:31:07 +00006945}
6946
Mike Stump1eb44332009-09-09 15:08:12 +00006947template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006948ExprResult
John McCall454feb92009-12-08 09:21:05 +00006949TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00006950 bool ArgumentChanged = false;
John McCallca0408f2010-08-23 06:44:23 +00006951 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregoraa165f82011-01-03 19:04:46 +00006952 SubExprs.reserve(E->getNumSubExprs());
6953 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
6954 SubExprs, &ArgumentChanged))
6955 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00006956
Douglas Gregorb98b1992009-08-11 05:31:07 +00006957 if (!getDerived().AlwaysRebuild() &&
6958 !ArgumentChanged)
John McCall3fa5cae2010-10-26 07:05:15 +00006959 return SemaRef.Owned(E);
Mike Stump1eb44332009-09-09 15:08:12 +00006960
Douglas Gregorb98b1992009-08-11 05:31:07 +00006961 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
6962 move_arg(SubExprs),
6963 E->getRParenLoc());
6964}
6965
Mike Stump1eb44332009-09-09 15:08:12 +00006966template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00006967ExprResult
John McCall454feb92009-12-08 09:21:05 +00006968TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006969 SourceLocation CaretLoc(E->getExprLoc());
6970
6971 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
6972 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
6973 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
6974 llvm::SmallVector<ParmVarDecl*, 4> Params;
6975 llvm::SmallVector<QualType, 4> ParamTypes;
6976
6977 // Parameter substitution.
Douglas Gregor12c9c002011-01-07 16:43:16 +00006978 // FIXME: Variadic templates
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006979 const BlockDecl *BD = E->getBlockDecl();
6980 for (BlockDecl::param_const_iterator P = BD->param_begin(),
6981 EN = BD->param_end(); P != EN; ++P) {
6982 ParmVarDecl *OldParm = (*P);
6983 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
6984 QualType NewType = NewParm->getType();
6985 Params.push_back(NewParm);
6986 ParamTypes.push_back(NewParm->getType());
6987 }
6988
6989 const FunctionType *BExprFunctionType = E->getFunctionType();
6990 QualType BExprResultType = BExprFunctionType->getResultType();
6991 if (!BExprResultType.isNull()) {
6992 if (!BExprResultType->isDependentType())
6993 CurBlock->ReturnType = BExprResultType;
6994 else if (BExprResultType != SemaRef.Context.DependentTy)
6995 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
6996 }
John McCall711c52b2011-01-05 12:14:39 +00006997
Fariborz Jahaniana729da22010-07-09 18:44:02 +00006998 QualType FunctionType = getDerived().RebuildFunctionProtoType(
6999 CurBlock->ReturnType,
7000 ParamTypes.data(),
7001 ParamTypes.size(),
7002 BD->isVariadic(),
Eli Friedmanfa869542010-08-05 02:54:05 +00007003 0,
7004 BExprFunctionType->getExtInfo());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007005 CurBlock->FunctionType = FunctionType;
John McCall711c52b2011-01-05 12:14:39 +00007006
7007 // Set the parameters on the block decl.
7008 if (!Params.empty())
7009 CurBlock->TheDecl->setParams(Params.data(), Params.size());
7010
7011 // Transform the body
7012 StmtResult Body = getDerived().TransformStmt(E->getBody());
7013 if (Body.isInvalid())
7014 return ExprError();
7015
John McCall9ae2f072010-08-23 23:25:46 +00007016 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007017}
7018
Mike Stump1eb44332009-09-09 15:08:12 +00007019template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007020ExprResult
John McCall454feb92009-12-08 09:21:05 +00007021TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007022 NestedNameSpecifier *Qualifier = 0;
7023
7024 ValueDecl *ND
7025 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7026 E->getDecl()));
7027 if (!ND)
John McCallf312b1e2010-08-26 23:41:50 +00007028 return ExprError();
Abramo Bagnara25777432010-08-11 22:01:17 +00007029
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007030 if (!getDerived().AlwaysRebuild() &&
7031 ND == E->getDecl()) {
7032 // Mark it referenced in the new context regardless.
7033 // FIXME: this is a bit instantiation-specific.
7034 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7035
John McCall3fa5cae2010-10-26 07:05:15 +00007036 return SemaRef.Owned(E);
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007037 }
7038
Abramo Bagnara25777432010-08-11 22:01:17 +00007039 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahaniana729da22010-07-09 18:44:02 +00007040 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnara25777432010-08-11 22:01:17 +00007041 ND, NameInfo, 0);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007042}
Mike Stump1eb44332009-09-09 15:08:12 +00007043
Douglas Gregorb98b1992009-08-11 05:31:07 +00007044//===----------------------------------------------------------------------===//
Douglas Gregor577f75a2009-08-04 16:50:30 +00007045// Type reconstruction
7046//===----------------------------------------------------------------------===//
7047
Mike Stump1eb44332009-09-09 15:08:12 +00007048template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007049QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7050 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007051 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007052 getDerived().getBaseEntity());
7053}
7054
Mike Stump1eb44332009-09-09 15:08:12 +00007055template<typename Derived>
John McCall85737a72009-10-30 00:06:24 +00007056QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7057 SourceLocation Star) {
John McCall28654742010-06-05 06:41:15 +00007058 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007059 getDerived().getBaseEntity());
7060}
7061
Mike Stump1eb44332009-09-09 15:08:12 +00007062template<typename Derived>
7063QualType
John McCall85737a72009-10-30 00:06:24 +00007064TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7065 bool WrittenAsLValue,
7066 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007067 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall85737a72009-10-30 00:06:24 +00007068 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007069}
7070
7071template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007072QualType
John McCall85737a72009-10-30 00:06:24 +00007073TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7074 QualType ClassType,
7075 SourceLocation Sigil) {
John McCall28654742010-06-05 06:41:15 +00007076 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall85737a72009-10-30 00:06:24 +00007077 Sigil, getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007078}
7079
7080template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007081QualType
Douglas Gregor577f75a2009-08-04 16:50:30 +00007082TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7083 ArrayType::ArraySizeModifier SizeMod,
7084 const llvm::APInt *Size,
7085 Expr *SizeExpr,
7086 unsigned IndexTypeQuals,
7087 SourceRange BracketsRange) {
7088 if (SizeExpr || !Size)
7089 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7090 IndexTypeQuals, BracketsRange,
7091 getDerived().getBaseEntity());
Mike Stump1eb44332009-09-09 15:08:12 +00007092
7093 QualType Types[] = {
7094 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7095 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7096 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregor577f75a2009-08-04 16:50:30 +00007097 };
7098 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7099 QualType SizeType;
7100 for (unsigned I = 0; I != NumTypes; ++I)
7101 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7102 SizeType = Types[I];
7103 break;
7104 }
Mike Stump1eb44332009-09-09 15:08:12 +00007105
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007106 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7107 /*FIXME*/BracketsRange.getBegin());
Mike Stump1eb44332009-09-09 15:08:12 +00007108 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007109 IndexTypeQuals, BracketsRange,
Mike Stump1eb44332009-09-09 15:08:12 +00007110 getDerived().getBaseEntity());
Douglas Gregor577f75a2009-08-04 16:50:30 +00007111}
Mike Stump1eb44332009-09-09 15:08:12 +00007112
Douglas Gregor577f75a2009-08-04 16:50:30 +00007113template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007114QualType
7115TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007116 ArrayType::ArraySizeModifier SizeMod,
7117 const llvm::APInt &Size,
John McCall85737a72009-10-30 00:06:24 +00007118 unsigned IndexTypeQuals,
7119 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007120 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall85737a72009-10-30 00:06:24 +00007121 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007122}
7123
7124template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007125QualType
Mike Stump1eb44332009-09-09 15:08:12 +00007126TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007127 ArrayType::ArraySizeModifier SizeMod,
John McCall85737a72009-10-30 00:06:24 +00007128 unsigned IndexTypeQuals,
7129 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007130 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall85737a72009-10-30 00:06:24 +00007131 IndexTypeQuals, BracketsRange);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007132}
Mike Stump1eb44332009-09-09 15:08:12 +00007133
Douglas Gregor577f75a2009-08-04 16:50:30 +00007134template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007135QualType
7136TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007137 ArrayType::ArraySizeModifier SizeMod,
John McCall9ae2f072010-08-23 23:25:46 +00007138 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007139 unsigned IndexTypeQuals,
7140 SourceRange BracketsRange) {
Mike Stump1eb44332009-09-09 15:08:12 +00007141 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCall9ae2f072010-08-23 23:25:46 +00007142 SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007143 IndexTypeQuals, BracketsRange);
7144}
7145
7146template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007147QualType
7148TreeTransform<Derived>::RebuildDependentSizedArrayType(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>
7159QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsone86d78c2010-11-10 21:56:12 +00007160 unsigned NumElements,
7161 VectorType::VectorKind VecKind) {
Douglas Gregor577f75a2009-08-04 16:50:30 +00007162 // FIXME: semantic checking!
Bob Wilsone86d78c2010-11-10 21:56:12 +00007163 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007164}
Mike Stump1eb44332009-09-09 15:08:12 +00007165
Douglas Gregor577f75a2009-08-04 16:50:30 +00007166template<typename Derived>
7167QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7168 unsigned NumElements,
7169 SourceLocation AttributeLoc) {
7170 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7171 NumElements, true);
7172 IntegerLiteral *VectorSize
Argyrios Kyrtzidis9996a7f2010-08-28 09:06:06 +00007173 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7174 AttributeLoc);
John McCall9ae2f072010-08-23 23:25:46 +00007175 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
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>
Mike Stump1eb44332009-09-09 15:08:12 +00007179QualType
7180TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCall9ae2f072010-08-23 23:25:46 +00007181 Expr *SizeExpr,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007182 SourceLocation AttributeLoc) {
John McCall9ae2f072010-08-23 23:25:46 +00007183 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007184}
Mike Stump1eb44332009-09-09 15:08:12 +00007185
Douglas Gregor577f75a2009-08-04 16:50:30 +00007186template<typename Derived>
7187QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump1eb44332009-09-09 15:08:12 +00007188 QualType *ParamTypes,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007189 unsigned NumParamTypes,
Mike Stump1eb44332009-09-09 15:08:12 +00007190 bool Variadic,
Eli Friedmanfa869542010-08-05 02:54:05 +00007191 unsigned Quals,
7192 const FunctionType::ExtInfo &Info) {
Mike Stump1eb44332009-09-09 15:08:12 +00007193 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregor577f75a2009-08-04 16:50:30 +00007194 Quals,
7195 getDerived().getBaseLocation(),
Eli Friedmanfa869542010-08-05 02:54:05 +00007196 getDerived().getBaseEntity(),
7197 Info);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007198}
Mike Stump1eb44332009-09-09 15:08:12 +00007199
Douglas Gregor577f75a2009-08-04 16:50:30 +00007200template<typename Derived>
John McCalla2becad2009-10-21 00:40:46 +00007201QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7202 return SemaRef.Context.getFunctionNoProtoType(T);
7203}
7204
7205template<typename Derived>
John McCalled976492009-12-04 22:46:56 +00007206QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7207 assert(D && "no decl found");
7208 if (D->isInvalidDecl()) return QualType();
7209
Douglas Gregor92e986e2010-04-22 16:44:27 +00007210 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCalled976492009-12-04 22:46:56 +00007211 TypeDecl *Ty;
7212 if (isa<UsingDecl>(D)) {
7213 UsingDecl *Using = cast<UsingDecl>(D);
7214 assert(Using->isTypeName() &&
7215 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7216
7217 // A valid resolved using typename decl points to exactly one type decl.
7218 assert(++Using->shadow_begin() == Using->shadow_end());
7219 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Sean Huntc3021132010-05-05 15:23:54 +00007220
John McCalled976492009-12-04 22:46:56 +00007221 } else {
7222 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7223 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7224 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7225 }
7226
7227 return SemaRef.Context.getTypeDeclType(Ty);
7228}
7229
7230template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007231QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7232 SourceLocation Loc) {
7233 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007234}
7235
7236template<typename Derived>
7237QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7238 return SemaRef.Context.getTypeOfType(Underlying);
7239}
7240
7241template<typename Derived>
John McCall2a984ca2010-10-12 00:20:44 +00007242QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7243 SourceLocation Loc) {
7244 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007245}
7246
7247template<typename Derived>
7248QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall833ca992009-10-29 08:12:44 +00007249 TemplateName Template,
7250 SourceLocation TemplateNameLoc,
John McCalld5532b62009-11-23 01:53:49 +00007251 const TemplateArgumentListInfo &TemplateArgs) {
7252 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregor577f75a2009-08-04 16:50:30 +00007253}
Mike Stump1eb44332009-09-09 15:08:12 +00007254
Douglas Gregordcee1a12009-08-06 05:28:30 +00007255template<typename Derived>
7256NestedNameSpecifier *
7257TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7258 SourceRange Range,
Douglas Gregora38c6872009-09-03 16:14:30 +00007259 IdentifierInfo &II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007260 QualType ObjectType,
John McCalld5532b62009-11-23 01:53:49 +00007261 NamedDecl *FirstQualifierInScope) {
Douglas Gregordcee1a12009-08-06 05:28:30 +00007262 CXXScopeSpec SS;
7263 // FIXME: The source location information is all wrong.
7264 SS.setRange(Range);
7265 SS.setScopeRep(Prefix);
7266 return static_cast<NestedNameSpecifier *>(
Mike Stump1eb44332009-09-09 15:08:12 +00007267 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregor495c35d2009-08-25 22:51:20 +00007268 Range.getEnd(), II,
Douglas Gregorc68afe22009-09-03 21:38:09 +00007269 ObjectType,
7270 FirstQualifierInScope,
Chris Lattner46646492009-12-07 01:36:53 +00007271 false, false));
Douglas Gregordcee1a12009-08-06 05:28:30 +00007272}
7273
7274template<typename Derived>
7275NestedNameSpecifier *
7276TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7277 SourceRange Range,
7278 NamespaceDecl *NS) {
7279 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7280}
7281
7282template<typename Derived>
7283NestedNameSpecifier *
7284TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7285 SourceRange Range,
7286 bool TemplateKW,
Douglas Gregoredc90502010-02-25 04:46:04 +00007287 QualType T) {
7288 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregordcee1a12009-08-06 05:28:30 +00007289 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregora4923eb2009-11-16 21:35:15 +00007290 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregordcee1a12009-08-06 05:28:30 +00007291 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7292 T.getTypePtr());
7293 }
Mike Stump1eb44332009-09-09 15:08:12 +00007294
Douglas Gregordcee1a12009-08-06 05:28:30 +00007295 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7296 return 0;
7297}
Mike Stump1eb44332009-09-09 15:08:12 +00007298
Douglas Gregord1067e52009-08-06 06:41:21 +00007299template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007300TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007301TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7302 bool TemplateKW,
7303 TemplateDecl *Template) {
Mike Stump1eb44332009-09-09 15:08:12 +00007304 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregord1067e52009-08-06 06:41:21 +00007305 Template);
7306}
7307
7308template<typename Derived>
Mike Stump1eb44332009-09-09 15:08:12 +00007309TemplateName
Douglas Gregord1067e52009-08-06 06:41:21 +00007310TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007311 SourceRange QualifierRange,
Douglas Gregor3b6afbb2009-09-09 00:23:06 +00007312 const IdentifierInfo &II,
John McCall43fed0d2010-11-12 08:19:04 +00007313 QualType ObjectType,
7314 NamedDecl *FirstQualifierInScope) {
Douglas Gregord1067e52009-08-06 06:41:21 +00007315 CXXScopeSpec SS;
Douglas Gregor1efb6c72010-09-08 23:56:00 +00007316 SS.setRange(QualifierRange);
Mike Stump1eb44332009-09-09 15:08:12 +00007317 SS.setScopeRep(Qualifier);
Douglas Gregor014e88d2009-11-03 23:16:33 +00007318 UnqualifiedId Name;
7319 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregord6ab2322010-06-16 23:00:59 +00007320 Sema::TemplateTy Template;
7321 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7322 /*FIXME:*/getDerived().getBaseLocation(),
7323 SS,
7324 Name,
John McCallb3d87482010-08-24 05:47:05 +00007325 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007326 /*EnteringContext=*/false,
7327 Template);
John McCall43fed0d2010-11-12 08:19:04 +00007328 return Template.get();
Douglas Gregord1067e52009-08-06 06:41:21 +00007329}
Mike Stump1eb44332009-09-09 15:08:12 +00007330
Douglas Gregorb98b1992009-08-11 05:31:07 +00007331template<typename Derived>
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007332TemplateName
7333TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7334 OverloadedOperatorKind Operator,
7335 QualType ObjectType) {
7336 CXXScopeSpec SS;
7337 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7338 SS.setScopeRep(Qualifier);
7339 UnqualifiedId Name;
7340 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7341 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7342 Operator, SymbolLocations);
Douglas Gregord6ab2322010-06-16 23:00:59 +00007343 Sema::TemplateTy Template;
7344 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007345 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007346 SS,
7347 Name,
John McCallb3d87482010-08-24 05:47:05 +00007348 ParsedType::make(ObjectType),
Douglas Gregord6ab2322010-06-16 23:00:59 +00007349 /*EnteringContext=*/false,
7350 Template);
7351 return Template.template getAsVal<TemplateName>();
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007352}
Sean Huntc3021132010-05-05 15:23:54 +00007353
Douglas Gregorca1bdd72009-11-04 00:56:37 +00007354template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007355ExprResult
Douglas Gregorb98b1992009-08-11 05:31:07 +00007356TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7357 SourceLocation OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007358 Expr *OrigCallee,
7359 Expr *First,
7360 Expr *Second) {
7361 Expr *Callee = OrigCallee->IgnoreParenCasts();
7362 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump1eb44332009-09-09 15:08:12 +00007363
Douglas Gregorb98b1992009-08-11 05:31:07 +00007364 // Determine whether this should be a builtin operation.
Sebastian Redlf322ed62009-10-29 20:17:01 +00007365 if (Op == OO_Subscript) {
John McCall9ae2f072010-08-23 23:25:46 +00007366 if (!First->getType()->isOverloadableType() &&
7367 !Second->getType()->isOverloadableType())
7368 return getSema().CreateBuiltinArraySubscriptExpr(First,
7369 Callee->getLocStart(),
7370 Second, OpLoc);
Eli Friedman1a3c75f2009-11-16 19:13:03 +00007371 } else if (Op == OO_Arrow) {
7372 // -> is never a builtin operation.
John McCall9ae2f072010-08-23 23:25:46 +00007373 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7374 } else if (Second == 0 || isPostIncDec) {
7375 if (!First->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007376 // The argument is not of overloadable type, so try to create a
7377 // built-in unary operation.
John McCall2de56d12010-08-25 11:45:40 +00007378 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007379 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump1eb44332009-09-09 15:08:12 +00007380
John McCall9ae2f072010-08-23 23:25:46 +00007381 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007382 }
7383 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007384 if (!First->getType()->isOverloadableType() &&
7385 !Second->getType()->isOverloadableType()) {
Douglas Gregorb98b1992009-08-11 05:31:07 +00007386 // Neither of the arguments is an overloadable type, so try to
7387 // create a built-in binary operation.
John McCall2de56d12010-08-25 11:45:40 +00007388 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007389 ExprResult Result
John McCall9ae2f072010-08-23 23:25:46 +00007390 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007391 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007392 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007393
Douglas Gregorb98b1992009-08-11 05:31:07 +00007394 return move(Result);
7395 }
7396 }
Mike Stump1eb44332009-09-09 15:08:12 +00007397
7398 // Compute the transformed set of functions (and function templates) to be
Douglas Gregorb98b1992009-08-11 05:31:07 +00007399 // used during overload resolution.
John McCall6e266892010-01-26 03:27:55 +00007400 UnresolvedSet<16> Functions;
Mike Stump1eb44332009-09-09 15:08:12 +00007401
John McCall9ae2f072010-08-23 23:25:46 +00007402 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCallba135432009-11-21 08:51:07 +00007403 assert(ULE->requiresADL());
7404
7405 // FIXME: Do we have to check
7406 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall6e266892010-01-26 03:27:55 +00007407 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCallba135432009-11-21 08:51:07 +00007408 } else {
John McCall9ae2f072010-08-23 23:25:46 +00007409 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCallba135432009-11-21 08:51:07 +00007410 }
Mike Stump1eb44332009-09-09 15:08:12 +00007411
Douglas Gregorb98b1992009-08-11 05:31:07 +00007412 // Add any functions found via argument-dependent lookup.
John McCall9ae2f072010-08-23 23:25:46 +00007413 Expr *Args[2] = { First, Second };
7414 unsigned NumArgs = 1 + (Second != 0);
Mike Stump1eb44332009-09-09 15:08:12 +00007415
Douglas Gregorb98b1992009-08-11 05:31:07 +00007416 // Create the overloaded operator invocation for unary operators.
7417 if (NumArgs == 1 || isPostIncDec) {
John McCall2de56d12010-08-25 11:45:40 +00007418 UnaryOperatorKind Opc
Douglas Gregorb98b1992009-08-11 05:31:07 +00007419 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCall9ae2f072010-08-23 23:25:46 +00007420 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007421 }
Mike Stump1eb44332009-09-09 15:08:12 +00007422
Sebastian Redlf322ed62009-10-29 20:17:01 +00007423 if (Op == OO_Subscript)
John McCall9ae2f072010-08-23 23:25:46 +00007424 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCallba135432009-11-21 08:51:07 +00007425 OpLoc,
John McCall9ae2f072010-08-23 23:25:46 +00007426 First,
7427 Second);
Sebastian Redlf322ed62009-10-29 20:17:01 +00007428
Douglas Gregorb98b1992009-08-11 05:31:07 +00007429 // Create the overloaded operator invocation for binary operators.
John McCall2de56d12010-08-25 11:45:40 +00007430 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCall60d7b3a2010-08-24 06:29:42 +00007431 ExprResult Result
Douglas Gregorb98b1992009-08-11 05:31:07 +00007432 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7433 if (Result.isInvalid())
John McCallf312b1e2010-08-26 23:41:50 +00007434 return ExprError();
Mike Stump1eb44332009-09-09 15:08:12 +00007435
Mike Stump1eb44332009-09-09 15:08:12 +00007436 return move(Result);
Douglas Gregorb98b1992009-08-11 05:31:07 +00007437}
Mike Stump1eb44332009-09-09 15:08:12 +00007438
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007439template<typename Derived>
John McCall60d7b3a2010-08-24 06:29:42 +00007440ExprResult
John McCall9ae2f072010-08-23 23:25:46 +00007441TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007442 SourceLocation OperatorLoc,
7443 bool isArrow,
7444 NestedNameSpecifier *Qualifier,
7445 SourceRange QualifierRange,
7446 TypeSourceInfo *ScopeType,
7447 SourceLocation CCLoc,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007448 SourceLocation TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007449 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007450 CXXScopeSpec SS;
7451 if (Qualifier) {
7452 SS.setRange(QualifierRange);
7453 SS.setScopeRep(Qualifier);
7454 }
7455
John McCall9ae2f072010-08-23 23:25:46 +00007456 QualType BaseType = Base->getType();
7457 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007458 (!isArrow && !BaseType->getAs<RecordType>()) ||
Sean Huntc3021132010-05-05 15:23:54 +00007459 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greifbf2ca2f2010-02-25 13:04:33 +00007460 !BaseType->getAs<PointerType>()->getPointeeType()
7461 ->template getAs<RecordType>())){
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007462 // This pseudo-destructor expression is still a pseudo-destructor.
John McCall9ae2f072010-08-23 23:25:46 +00007463 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007464 isArrow? tok::arrow : tok::period,
Douglas Gregorfce46ee2010-02-24 23:50:37 +00007465 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007466 Destroyed,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007467 /*FIXME?*/true);
7468 }
Abramo Bagnara25777432010-08-11 22:01:17 +00007469
Douglas Gregora2e7dd22010-02-25 01:56:36 +00007470 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnara25777432010-08-11 22:01:17 +00007471 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7472 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7473 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7474 NameInfo.setNamedTypeInfo(DestroyedType);
7475
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007476 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnara25777432010-08-11 22:01:17 +00007477
John McCall9ae2f072010-08-23 23:25:46 +00007478 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007479 OperatorLoc, isArrow,
7480 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnara25777432010-08-11 22:01:17 +00007481 NameInfo,
Douglas Gregor26d4ac92010-02-24 23:40:28 +00007482 /*TemplateArgs*/ 0);
7483}
7484
Douglas Gregor577f75a2009-08-04 16:50:30 +00007485} // end namespace clang
7486
7487#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H