blob: 43d89e2875ef5e7499bf4b7f3bb308ed80392b97 [file] [log] [blame]
John McCall550e0c22009-10-21 00:40:46 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===/
Douglas Gregord6ff3322009-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 McCall83024632010-08-25 22:03:47 +000016#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000017#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000018#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000019#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000020#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000021#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000022#include "clang/AST/DeclObjC.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000023#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000024#include "clang/AST/ExprCXX.h"
25#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000026#include "clang/AST/Stmt.h"
27#include "clang/AST/StmtCXX.h"
28#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000029#include "clang/Sema/Ownership.h"
30#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000031#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000032#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000033#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000034#include <algorithm>
35
36namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000037using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000038
Douglas Gregord6ff3322009-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 Stump11289f42009-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 Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +000052/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +000067/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000068/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-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 Gregorebe10102009-08-20 07:17:43 +000075/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000076/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000077/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +000085/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-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 Gregord6ff3322009-08-04 16:50:30 +000090template<typename Derived>
91class TreeTransform {
Douglas Gregora8bac7f2011-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 Gregord6ff3322009-08-04 16:50:30 +0000109protected:
110 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000111
Mike Stump11289f42009-09-09 15:08:12 +0000112public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000114 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000115
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000120 const Derived &getDerived() const {
121 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 }
123
John McCalldadc5752010-08-24 06:29:42 +0000124 static inline ExprResult Owned(Expr *E) { return E; }
125 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000126
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000130
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000137
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000141 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000142 /// provide an alternative implementation that provides better location
143 /// information.
144 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000145
Douglas Gregord6ff3322009-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 Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +0000159
Douglas Gregora16548e2009-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 Stump11289f42009-09-09 15:08:12 +0000166
Douglas Gregora16548e2009-08-11 05:31:07 +0000167 public:
168 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000169 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000170 OldLocation = Self.getDerived().getBaseLocation();
171 OldEntity = Self.getDerived().getBaseEntity();
172 Self.getDerived().setBase(Location, Entity);
173 }
Mike Stump11289f42009-09-09 15:08:12 +0000174
Douglas Gregora16548e2009-08-11 05:31:07 +0000175 ~TemporaryBase() {
176 Self.getDerived().setBase(OldLocation, OldEntity);
177 }
178 };
Mike Stump11289f42009-09-09 15:08:12 +0000179
180 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000181 /// transformed.
182 ///
183 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000184 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-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 Gregord196a582009-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 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000200
Douglas Gregor840bd6c2010-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 Gregor76aca7b2010-12-21 00:52:54 +0000205 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-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 Gregora8bac7f2011-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 Gregor840bd6c2010-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 Gregora8bac7f2011-01-10 07:32:04 +0000242 bool &RetainExpansion,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000243 unsigned &NumExpansions) {
244 ShouldExpand = false;
245 return false;
246 }
247
Douglas Gregora8bac7f2011-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 Gregorf3010112011-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 Gregord6ff3322009-08-04 16:50:30 +0000268 /// \brief Transforms the given type into another type.
269 ///
John McCall550e0c22009-10-21 00:40:46 +0000270 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000271 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-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 McCallbcd03502009-12-07 02:54:59 +0000274 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000275 ///
276 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000277 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000278
John McCall550e0c22009-10-21 00:40:46 +0000279 /// \brief Transforms the given type-with-location into a new
280 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000281 ///
John McCall550e0c22009-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 McCall31f82722010-11-12 08:19:04 +0000287 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-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 McCall31f82722010-11-12 08:19:04 +0000293 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000294
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000295 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000296 ///
Mike Stump11289f42009-09-09 15:08:12 +0000297 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-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 McCalldadc5752010-08-24 06:29:42 +0000304 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000305
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000306 /// \brief Transform the given expression.
307 ///
Douglas Gregora16548e2009-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 McCalldadc5752010-08-24 06:29:42 +0000314 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000315
Douglas Gregora3efea12011-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 Gregord6ff3322009-08-04 16:50:30 +0000343 /// \brief Transform the given declaration, which is referenced from a type
344 /// or expression.
345 ///
Douglas Gregor1135c352009-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 Gregora04f2ca2010-03-01 15:56:25 +0000348 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000349
350 /// \brief Transform the definition of the given declaration.
351 ///
Mike Stump11289f42009-09-09 15:08:12 +0000352 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000353 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000354 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
355 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000356 }
Mike Stump11289f42009-09-09 15:08:12 +0000357
Douglas Gregora5cb6da2009-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 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000361 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-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.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000367 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
368 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000369 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000370
Douglas Gregord6ff3322009-08-04 16:50:30 +0000371 /// \brief Transform the given nested-name-specifier.
372 ///
Mike Stump11289f42009-09-09 15:08:12 +0000373 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000374 /// nested-name-specifier. Subclasses may override this function to provide
375 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000376 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000377 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000378 QualType ObjectType = QualType(),
379 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000380
Douglas Gregorf816bd72009-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 Bagnarad6d2f182010-08-11 22:01:17 +0000387 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000388 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000389
Douglas Gregord6ff3322009-08-04 16:50:30 +0000390 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000391 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000392 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000393 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000394 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000395 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000396 QualType ObjectType = QualType(),
397 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000398
Douglas Gregord6ff3322009-08-04 16:50:30 +0000399 /// \brief Transform the given template argument.
400 ///
Mike Stump11289f42009-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 Gregore922c772009-08-04 22:27:00 +0000403 /// new template argument from the transformed result. Subclasses may
404 /// override this function to provide alternate behavior.
John McCall0ad16662009-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 Gregor62e06f22010-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 Gregorfe921a72010-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 Gregor62e06f22010-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 Gregorfe921a72010-12-20 23:36:19 +0000430 TemplateArgumentListInfo &Outputs) {
431 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
432 }
Douglas Gregor42cafa82010-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 Gregorfe921a72010-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 Gregor42cafa82010-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 Gregorfe921a72010-12-20 23:36:19 +0000448 template<typename InputIterator>
449 bool TransformTemplateArguments(InputIterator First,
450 InputIterator Last,
451 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000452
John McCall0ad16662009-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 McCallbcd03502009-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 McCall0ad16662009-10-29 08:12:44 +0000460 getDerived().getBaseLocation());
461 }
Mike Stump11289f42009-09-09 15:08:12 +0000462
John McCall550e0c22009-10-21 00:40:46 +0000463#define ABSTRACT_TYPELOC(CLASS, PARENT)
464#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000465 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000466#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000467
John McCall31f82722010-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 McCall58f10c32010-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 Gregordd472162011-01-07 00:20:55 +0000485 bool TransformFunctionTypeParams(SourceLocation Loc,
486 ParmVarDecl **Params, unsigned NumParams,
487 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000488 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000489 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-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 McCall31f82722010-11-12 08:19:04 +0000495 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000496
John McCalldadc5752010-08-24 06:29:42 +0000497 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
498 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000499
Douglas Gregorebe10102009-08-20 07:17:43 +0000500#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000501 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000502#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000503 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000504#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000505#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000506
Douglas Gregord6ff3322009-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 McCall70dd5f62009-10-30 00:06:24 +0000511 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000512
513 /// \brief Build a new block pointer type given its pointee type.
514 ///
Mike Stump11289f42009-09-09 15:08:12 +0000515 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000516 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000517 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000518
John McCall70dd5f62009-10-30 00:06:24 +0000519 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000520 ///
John McCall70dd5f62009-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 Gregord6ff3322009-08-04 16:50:30 +0000524 ///
John McCall70dd5f62009-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 Stump11289f42009-09-09 15:08:12 +0000530
Douglas Gregord6ff3322009-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 McCall70dd5f62009-10-30 00:06:24 +0000536 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
537 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000538
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000545 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000552
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000558 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000559 ArrayType::ArraySizeModifier SizeMod,
560 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000561 unsigned IndexTypeQuals,
562 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000563
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000569 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000571 unsigned IndexTypeQuals,
572 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000573
Mike Stump11289f42009-09-09 15:08:12 +0000574 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000579 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000580 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000581 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000582 unsigned IndexTypeQuals,
583 SourceRange BracketsRange);
584
Mike Stump11289f42009-09-09 15:08:12 +0000585 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000590 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000591 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000592 Expr *SizeExpr,
Douglas Gregord6ff3322009-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 Thompson22334602010-02-05 00:12:22 +0000601 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000602 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000603
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000611
612 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000617 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000618 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000619 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000620
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000626 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000627 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000628 bool Variadic, unsigned Quals,
629 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000630
John McCall550e0c22009-10-21 00:40:46 +0000631 /// \brief Build a new unprototyped function type.
632 QualType RebuildFunctionNoProtoType(QualType ResultType);
633
John McCallb96ec562009-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 Gregord6ff3322009-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 McCallfcc33b02009-09-05 00:15:47 +0000652
Mike Stump11289f42009-09-09 15:08:12 +0000653 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-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 McCall36e7fe32010-10-12 00:20:44 +0000657 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000658
Mike Stump11289f42009-09-09 15:08:12 +0000659 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-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 Stump11289f42009-09-09 15:08:12 +0000664 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-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 McCall36e7fe32010-10-12 00:20:44 +0000668 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000669
Douglas Gregord6ff3322009-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 McCall0ad16662009-10-29 08:12:44 +0000676 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000677 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000678
Abramo Bagnara924a8f32010-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 Gregord6ff3322009-08-04 16:50:30 +0000687 /// \brief Build a new qualified name type.
688 ///
Abramo Bagnara6150c882010-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 McCall954b5de2010-11-04 19:04:38 +0000692 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
693 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000694 NestedNameSpecifier *NNS, QualType Named) {
695 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000696 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000697
698 /// \brief Build a new typename type that refers to a template-id.
699 ///
Abramo Bagnarad7548482010-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 McCallc392f372010-06-11 00:33:02 +0000703 QualType RebuildDependentTemplateSpecializationType(
704 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000705 NestedNameSpecifier *Qualifier,
706 SourceRange QualifierRange,
John McCallc392f372010-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 Gregora5614c52010-09-08 23:56:00 +0000713 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000714 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000715
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000716 if (InstName.isNull())
717 return QualType();
718
John McCallc392f372010-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 Gregora5614c52010-09-08 23:56:00 +0000722 Keyword, Qualifier, Name, Args);
John McCallc392f372010-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 Bagnara6150c882010-05-11 21:36:43 +0000729
Abramo Bagnaraf9985b42010-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 Stump11289f42009-09-09 15:08:12 +0000732 }
Douglas Gregord6ff3322009-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 Bagnarad7548482010-05-19 21:37:53 +0000737 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000738 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000739 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000740 NestedNameSpecifier *NNS,
741 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000742 SourceLocation KeywordLoc,
743 SourceRange NNSRange,
744 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000745 CXXScopeSpec SS;
746 SS.setScopeRep(NNS);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000747 SS.setRange(NNSRange);
748
Douglas Gregore677daf2010-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 Bagnara6150c882010-05-11 21:36:43 +0000755 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000756 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
757 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000758
759 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
760
Abramo Bagnarad7548482010-05-19 21:37:53 +0000761 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000762 // into a non-dependent elaborated-type-specifier. Find the tag we're
763 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000764 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000765 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
766 if (!DC)
767 return QualType();
768
John McCallbf8c5192010-05-27 06:40:31 +0000769 if (SemaRef.RequireCompleteDeclContext(SS, DC))
770 return QualType();
771
Douglas Gregore677daf2010-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;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000778
Douglas Gregore677daf2010-03-31 22:19:08 +0000779 case LookupResult::Found:
780 Tag = Result.getAsSingle<TagDecl>();
781 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000782
Douglas Gregore677daf2010-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();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000787
Douglas Gregore677daf2010-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 Gregorf5af3582010-03-31 23:17:41 +0000794 // FIXME: Would be nice to highlight just the source range.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000795 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Douglas Gregorf5af3582010-03-31 23:17:41 +0000796 << Kind << Id << DC;
Douglas Gregore677daf2010-03-31 22:19:08 +0000797 return QualType();
798 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000799
Abramo Bagnarad7548482010-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 Gregore677daf2010-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 Bagnara6150c882010-05-11 21:36:43 +0000808 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000809 }
Mike Stump11289f42009-09-09 15:08:12 +0000810
Douglas Gregor822d0302011-01-12 17:07:58 +0000811 /// \brief Build a new pack expansion type.
812 ///
813 /// By default, builds a new PackExpansionType type from the given pattern.
814 /// Subclasses may override this routine to provide different behavior.
815 QualType RebuildPackExpansionType(QualType Pattern,
816 SourceRange PatternRange,
817 SourceLocation EllipsisLoc) {
818 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc);
819 }
820
Douglas Gregor1135c352009-08-06 05:28:30 +0000821 /// \brief Build a new nested-name-specifier given the prefix and an
822 /// identifier that names the next step in the nested-name-specifier.
823 ///
824 /// By default, performs semantic analysis when building the new
825 /// nested-name-specifier. Subclasses may override this routine to provide
826 /// different behavior.
827 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
828 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000829 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000830 QualType ObjectType,
831 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000832
833 /// \brief Build a new nested-name-specifier given the prefix and the
834 /// namespace 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 NamespaceDecl *NS);
842
843 /// \brief Build a new nested-name-specifier given the prefix and the
844 /// type named in the next step in the nested-name-specifier.
845 ///
846 /// By default, performs semantic analysis when building the new
847 /// nested-name-specifier. Subclasses may override this routine to provide
848 /// different behavior.
849 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
850 SourceRange Range,
851 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000852 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000853
854 /// \brief Build a new template name given a nested name specifier, a flag
855 /// indicating whether the "template" keyword was provided, and the template
856 /// that the template name refers to.
857 ///
858 /// By default, builds the new template name directly. Subclasses may override
859 /// this routine to provide different behavior.
860 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
861 bool TemplateKW,
862 TemplateDecl *Template);
863
Douglas Gregor71dc5092009-08-06 06:41:21 +0000864 /// \brief Build a new template name given a nested name specifier and the
865 /// name that is referred to as a template.
866 ///
867 /// By default, performs semantic analysis to determine whether the name can
868 /// be resolved to a specific template, then builds the appropriate kind of
869 /// template name. Subclasses may override this routine to provide different
870 /// behavior.
871 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000872 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000873 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000874 QualType ObjectType,
875 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000876
Douglas Gregor71395fa2009-11-04 00:56:37 +0000877 /// \brief Build a new template name given a nested name specifier and the
878 /// overloaded operator name that is referred to as a template.
879 ///
880 /// By default, performs semantic analysis to determine whether the name can
881 /// be resolved to a specific template, then builds the appropriate kind of
882 /// template name. Subclasses may override this routine to provide different
883 /// behavior.
884 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
885 OverloadedOperatorKind Operator,
886 QualType ObjectType);
Alexis Hunta8136cc2010-05-05 15:23:54 +0000887
Douglas Gregorebe10102009-08-20 07:17:43 +0000888 /// \brief Build a new compound statement.
889 ///
890 /// By default, performs semantic analysis to build the new statement.
891 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000892 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000893 MultiStmtArg Statements,
894 SourceLocation RBraceLoc,
895 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000896 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000897 IsStmtExpr);
898 }
899
900 /// \brief Build a new case statement.
901 ///
902 /// By default, performs semantic analysis to build the new statement.
903 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000904 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000905 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000906 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000907 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000908 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000909 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000910 ColonLoc);
911 }
Mike Stump11289f42009-09-09 15:08:12 +0000912
Douglas Gregorebe10102009-08-20 07:17:43 +0000913 /// \brief Attach the body to a new case statement.
914 ///
915 /// By default, performs semantic analysis to build the new statement.
916 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000917 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000918 getSema().ActOnCaseStmtBody(S, Body);
919 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000920 }
Mike Stump11289f42009-09-09 15:08:12 +0000921
Douglas Gregorebe10102009-08-20 07:17:43 +0000922 /// \brief Build a new default statement.
923 ///
924 /// By default, performs semantic analysis to build the new statement.
925 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000926 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000927 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000928 Stmt *SubStmt) {
929 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000930 /*CurScope=*/0);
931 }
Mike Stump11289f42009-09-09 15:08:12 +0000932
Douglas Gregorebe10102009-08-20 07:17:43 +0000933 /// \brief Build a new label statement.
934 ///
935 /// By default, performs semantic analysis to build the new statement.
936 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000937 StmtResult RebuildLabelStmt(SourceLocation IdentLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000938 IdentifierInfo *Id,
939 SourceLocation ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +0000940 Stmt *SubStmt, bool HasUnusedAttr) {
941 return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt,
942 HasUnusedAttr);
Douglas Gregorebe10102009-08-20 07:17:43 +0000943 }
Mike Stump11289f42009-09-09 15:08:12 +0000944
Douglas Gregorebe10102009-08-20 07:17:43 +0000945 /// \brief Build a new "if" statement.
946 ///
947 /// By default, performs semantic analysis to build the new statement.
948 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000949 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000950 VarDecl *CondVar, Stmt *Then,
John McCallb268a282010-08-23 23:25:46 +0000951 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +0000952 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +0000953 }
Mike Stump11289f42009-09-09 15:08:12 +0000954
Douglas Gregorebe10102009-08-20 07:17:43 +0000955 /// \brief Start building a new 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 McCalldadc5752010-08-24 06:29:42 +0000959 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000960 Expr *Cond, VarDecl *CondVar) {
961 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +0000962 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +0000963 }
Mike Stump11289f42009-09-09 15:08:12 +0000964
Douglas Gregorebe10102009-08-20 07:17:43 +0000965 /// \brief Attach the body to the switch statement.
966 ///
967 /// By default, performs semantic analysis to build the new statement.
968 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000969 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
John McCallb268a282010-08-23 23:25:46 +0000970 Stmt *Switch, Stmt *Body) {
971 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000972 }
973
974 /// \brief Build a new while statement.
975 ///
976 /// By default, performs semantic analysis to build the new statement.
977 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000978 StmtResult RebuildWhileStmt(SourceLocation WhileLoc,
Douglas Gregorff73a9e2010-05-08 22:20:28 +0000979 Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +0000980 VarDecl *CondVar,
John McCallb268a282010-08-23 23:25:46 +0000981 Stmt *Body) {
982 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +0000983 }
Mike Stump11289f42009-09-09 15:08:12 +0000984
Douglas Gregorebe10102009-08-20 07:17:43 +0000985 /// \brief Build a new do-while statement.
986 ///
987 /// By default, performs semantic analysis to build the new statement.
988 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000989 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Douglas Gregorebe10102009-08-20 07:17:43 +0000990 SourceLocation WhileLoc,
991 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +0000992 Expr *Cond,
Douglas Gregorebe10102009-08-20 07:17:43 +0000993 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +0000994 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
995 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +0000996 }
997
998 /// \brief Build a new for statement.
999 ///
1000 /// By default, performs semantic analysis to build the new statement.
1001 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001002 StmtResult RebuildForStmt(SourceLocation ForLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001003 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001004 Stmt *Init, Sema::FullExprArg Cond,
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00001005 VarDecl *CondVar, Sema::FullExprArg Inc,
John McCallb268a282010-08-23 23:25:46 +00001006 SourceLocation RParenLoc, Stmt *Body) {
1007 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
John McCall48871652010-08-21 09:40:31 +00001008 CondVar,
John McCallb268a282010-08-23 23:25:46 +00001009 Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001010 }
Mike Stump11289f42009-09-09 15:08:12 +00001011
Douglas Gregorebe10102009-08-20 07:17:43 +00001012 /// \brief Build a new 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 McCalldadc5752010-08-24 06:29:42 +00001016 StmtResult RebuildGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001017 SourceLocation LabelLoc,
1018 LabelStmt *Label) {
1019 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID());
1020 }
1021
1022 /// \brief Build a new indirect goto statement.
1023 ///
1024 /// By default, performs semantic analysis to build the new statement.
1025 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001026 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001027 SourceLocation StarLoc,
John McCallb268a282010-08-23 23:25:46 +00001028 Expr *Target) {
1029 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001030 }
Mike Stump11289f42009-09-09 15:08:12 +00001031
Douglas Gregorebe10102009-08-20 07:17:43 +00001032 /// \brief Build a new return statement.
1033 ///
1034 /// By default, performs semantic analysis to build the new statement.
1035 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001036 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc,
John McCallb268a282010-08-23 23:25:46 +00001037 Expr *Result) {
Mike Stump11289f42009-09-09 15:08:12 +00001038
John McCallb268a282010-08-23 23:25:46 +00001039 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001040 }
Mike Stump11289f42009-09-09 15:08:12 +00001041
Douglas Gregorebe10102009-08-20 07:17:43 +00001042 /// \brief Build a new declaration statement.
1043 ///
1044 /// By default, performs semantic analysis to build the new statement.
1045 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001046 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001047 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001048 SourceLocation EndLoc) {
1049 return getSema().Owned(
1050 new (getSema().Context) DeclStmt(
1051 DeclGroupRef::Create(getSema().Context,
1052 Decls, NumDecls),
1053 StartLoc, EndLoc));
1054 }
Mike Stump11289f42009-09-09 15:08:12 +00001055
Anders Carlssonaaeef072010-01-24 05:50:09 +00001056 /// \brief Build a new inline asm statement.
1057 ///
1058 /// By default, performs semantic analysis to build the new statement.
1059 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001060 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001061 bool IsSimple,
1062 bool IsVolatile,
1063 unsigned NumOutputs,
1064 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001065 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001066 MultiExprArg Constraints,
1067 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001068 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001069 MultiExprArg Clobbers,
1070 SourceLocation RParenLoc,
1071 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001072 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001073 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001074 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001075 RParenLoc, MSAsm);
1076 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001077
1078 /// \brief Build a new Objective-C @try statement.
1079 ///
1080 /// By default, performs semantic analysis to build the new statement.
1081 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001082 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001083 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001084 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001085 Stmt *Finally) {
1086 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1087 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001088 }
1089
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001090 /// \brief Rebuild an Objective-C exception declaration.
1091 ///
1092 /// By default, performs semantic analysis to build the new declaration.
1093 /// Subclasses may override this routine to provide different behavior.
1094 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1095 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001096 return getSema().BuildObjCExceptionDecl(TInfo, T,
1097 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001098 ExceptionDecl->getLocation());
1099 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001100
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001101 /// \brief Build a new Objective-C @catch statement.
1102 ///
1103 /// By default, performs semantic analysis to build the new statement.
1104 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001105 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001106 SourceLocation RParenLoc,
1107 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001108 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001109 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001110 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001111 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001112
Douglas Gregor306de2f2010-04-22 23:59:56 +00001113 /// \brief Build a new Objective-C @finally statement.
1114 ///
1115 /// By default, performs semantic analysis to build the new statement.
1116 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001117 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001118 Stmt *Body) {
1119 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001120 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001121
Douglas Gregor6148de72010-04-22 22:01:21 +00001122 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001123 ///
1124 /// By default, performs semantic analysis to build the new statement.
1125 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001126 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001127 Expr *Operand) {
1128 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001129 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001130
Douglas Gregor6148de72010-04-22 22:01:21 +00001131 /// \brief Build a new Objective-C @synchronized statement.
1132 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001133 /// By default, performs semantic analysis to build the new statement.
1134 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001135 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001136 Expr *Object,
1137 Stmt *Body) {
1138 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1139 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001140 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001141
1142 /// \brief Build a new Objective-C fast enumeration statement.
1143 ///
1144 /// By default, performs semantic analysis to build the new statement.
1145 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001146 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001147 SourceLocation LParenLoc,
1148 Stmt *Element,
1149 Expr *Collection,
1150 SourceLocation RParenLoc,
1151 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001152 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001153 Element,
1154 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001155 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001156 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001157 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001158
Douglas Gregorebe10102009-08-20 07:17:43 +00001159 /// \brief Build a new C++ exception declaration.
1160 ///
1161 /// By default, performs semantic analysis to build the new decaration.
1162 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001163 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001164 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001165 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001166 SourceLocation Loc) {
1167 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001168 }
1169
1170 /// \brief Build a new C++ catch statement.
1171 ///
1172 /// By default, performs semantic analysis to build the new statement.
1173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001174 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001175 VarDecl *ExceptionDecl,
1176 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001177 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1178 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001179 }
Mike Stump11289f42009-09-09 15:08:12 +00001180
Douglas Gregorebe10102009-08-20 07:17:43 +00001181 /// \brief Build a new C++ try statement.
1182 ///
1183 /// By default, performs semantic analysis to build the new statement.
1184 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001185 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001186 Stmt *TryBlock,
1187 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001188 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001189 }
Mike Stump11289f42009-09-09 15:08:12 +00001190
Douglas Gregora16548e2009-08-11 05:31:07 +00001191 /// \brief Build a new expression that references a declaration.
1192 ///
1193 /// By default, performs semantic analysis to build the new expression.
1194 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001195 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001196 LookupResult &R,
1197 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001198 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1199 }
1200
1201
1202 /// \brief Build a new expression that references a declaration.
1203 ///
1204 /// By default, performs semantic analysis to build the new expression.
1205 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001206 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001207 SourceRange QualifierRange,
1208 ValueDecl *VD,
1209 const DeclarationNameInfo &NameInfo,
1210 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001211 CXXScopeSpec SS;
1212 SS.setScopeRep(Qualifier);
1213 SS.setRange(QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001214
1215 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001216
1217 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001218 }
Mike Stump11289f42009-09-09 15:08:12 +00001219
Douglas Gregora16548e2009-08-11 05:31:07 +00001220 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001221 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001222 /// By default, performs semantic analysis to build the new expression.
1223 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001224 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001225 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001226 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001227 }
1228
Douglas Gregorad8a3362009-09-04 17:36:40 +00001229 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001230 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001231 /// By default, performs semantic analysis to build the new expression.
1232 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001233 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregorad8a3362009-09-04 17:36:40 +00001234 SourceLocation OperatorLoc,
1235 bool isArrow,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001236 NestedNameSpecifier *Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00001237 SourceRange QualifierRange,
1238 TypeSourceInfo *ScopeType,
1239 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00001240 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001241 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001242
Douglas Gregora16548e2009-08-11 05:31:07 +00001243 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001244 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001245 /// By default, performs semantic analysis to build the new expression.
1246 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001247 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001248 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001249 Expr *SubExpr) {
1250 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001251 }
Mike Stump11289f42009-09-09 15:08:12 +00001252
Douglas Gregor882211c2010-04-28 22:16:22 +00001253 /// \brief Build a new builtin offsetof expression.
1254 ///
1255 /// By default, performs semantic analysis to build the new expression.
1256 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001257 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001258 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001259 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001260 unsigned NumComponents,
1261 SourceLocation RParenLoc) {
1262 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1263 NumComponents, RParenLoc);
1264 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001265
Douglas Gregora16548e2009-08-11 05:31:07 +00001266 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001267 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001268 /// By default, performs semantic analysis to build the new expression.
1269 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001270 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001271 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001272 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001273 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001274 }
1275
Mike Stump11289f42009-09-09 15:08:12 +00001276 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001277 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001278 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001279 /// By default, performs semantic analysis to build the new expression.
1280 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001281 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001282 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001283 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001284 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001285 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001286 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001287
Douglas Gregora16548e2009-08-11 05:31:07 +00001288 return move(Result);
1289 }
Mike Stump11289f42009-09-09 15:08:12 +00001290
Douglas Gregora16548e2009-08-11 05:31:07 +00001291 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001292 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001293 /// By default, performs semantic analysis to build the new expression.
1294 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001295 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001296 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001297 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001298 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001299 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1300 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001301 RBracketLoc);
1302 }
1303
1304 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001305 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001306 /// By default, performs semantic analysis to build the new expression.
1307 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001308 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001309 MultiExprArg Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00001310 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001311 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Douglas Gregorce5aa332010-09-09 16:33:13 +00001312 move(Args), RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001313 }
1314
1315 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001316 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001317 /// By default, performs semantic analysis to build the new expression.
1318 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001319 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001320 bool isArrow,
1321 NestedNameSpecifier *Qualifier,
1322 SourceRange QualifierRange,
1323 const DeclarationNameInfo &MemberNameInfo,
1324 ValueDecl *Member,
1325 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001326 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001327 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001328 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001329 // We have a reference to an unnamed field. This is always the
1330 // base of an anonymous struct/union member access, i.e. the
1331 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001332 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001333 assert(Member->getType()->isRecordType() &&
1334 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001335
John McCallb268a282010-08-23 23:25:46 +00001336 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001337 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001338 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001339
John McCall7decc9e2010-11-18 06:31:45 +00001340 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001341 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001342 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001343 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001344 cast<FieldDecl>(Member)->getType(),
1345 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001346 return getSema().Owned(ME);
1347 }
Mike Stump11289f42009-09-09 15:08:12 +00001348
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001349 CXXScopeSpec SS;
1350 if (Qualifier) {
1351 SS.setRange(QualifierRange);
1352 SS.setScopeRep(Qualifier);
1353 }
1354
John McCallb268a282010-08-23 23:25:46 +00001355 getSema().DefaultFunctionArrayConversion(Base);
1356 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001357
John McCall16df1e52010-03-30 21:47:33 +00001358 // FIXME: this involves duplicating earlier analysis in a lot of
1359 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001360 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001361 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001362 R.resolveKind();
1363
John McCallb268a282010-08-23 23:25:46 +00001364 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001365 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001366 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001367 }
Mike Stump11289f42009-09-09 15:08:12 +00001368
Douglas Gregora16548e2009-08-11 05:31:07 +00001369 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001370 ///
Douglas Gregora16548e2009-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 McCalldadc5752010-08-24 06:29:42 +00001373 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001374 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001375 Expr *LHS, Expr *RHS) {
1376 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001377 }
1378
1379 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001380 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001381 /// By default, performs semantic analysis to build the new expression.
1382 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001383 ExprResult RebuildConditionalOperator(Expr *Cond,
Douglas Gregora16548e2009-08-11 05:31:07 +00001384 SourceLocation QuestionLoc,
John McCallb268a282010-08-23 23:25:46 +00001385 Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001386 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001387 Expr *RHS) {
1388 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1389 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001390 }
1391
Douglas Gregora16548e2009-08-11 05:31:07 +00001392 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001393 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001394 /// By default, performs semantic analysis to build the new expression.
1395 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001396 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001397 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001398 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001399 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001400 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001401 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 }
Mike Stump11289f42009-09-09 15:08:12 +00001403
Douglas Gregora16548e2009-08-11 05:31:07 +00001404 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001405 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001406 /// By default, performs semantic analysis to build the new expression.
1407 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001408 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001409 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001410 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001411 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001412 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001413 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001414 }
Mike Stump11289f42009-09-09 15:08:12 +00001415
Douglas Gregora16548e2009-08-11 05:31:07 +00001416 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001417 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001418 /// By default, performs semantic analysis to build the new expression.
1419 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001420 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 SourceLocation OpLoc,
1422 SourceLocation AccessorLoc,
1423 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001424
John McCall10eae182009-11-30 22:42:35 +00001425 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001426 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001427 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001428 OpLoc, /*IsArrow*/ false,
1429 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001430 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001431 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001432 }
Mike Stump11289f42009-09-09 15:08:12 +00001433
Douglas Gregora16548e2009-08-11 05:31:07 +00001434 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001435 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001436 /// By default, performs semantic analysis to build the new expression.
1437 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001438 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001439 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001440 SourceLocation RBraceLoc,
1441 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001442 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001443 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1444 if (Result.isInvalid() || ResultTy->isDependentType())
1445 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001446
Douglas Gregord3d93062009-11-09 17:16:50 +00001447 // Patch in the result type we were given, which may have been computed
1448 // when the initial InitListExpr was built.
1449 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1450 ILE->setType(ResultTy);
1451 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001452 }
Mike Stump11289f42009-09-09 15:08:12 +00001453
Douglas Gregora16548e2009-08-11 05:31:07 +00001454 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001455 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 /// By default, performs semantic analysis to build the new expression.
1457 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001458 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001459 MultiExprArg ArrayExprs,
1460 SourceLocation EqualOrColonLoc,
1461 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001462 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001463 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001464 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001465 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001467 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001468
Douglas Gregora16548e2009-08-11 05:31:07 +00001469 ArrayExprs.release();
1470 return move(Result);
1471 }
Mike Stump11289f42009-09-09 15:08:12 +00001472
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001474 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001475 /// By default, builds the implicit value initialization without performing
1476 /// any semantic analysis. Subclasses may override this routine to provide
1477 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001478 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001479 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1480 }
Mike Stump11289f42009-09-09 15:08:12 +00001481
Douglas Gregora16548e2009-08-11 05:31:07 +00001482 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001483 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001484 /// By default, performs semantic analysis to build the new expression.
1485 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001486 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001487 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001488 SourceLocation RParenLoc) {
1489 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001490 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001491 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001492 }
1493
1494 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001495 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001496 /// By default, performs semantic analysis to build the new expression.
1497 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001498 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001499 MultiExprArg SubExprs,
1500 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001501 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001502 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001503 }
Mike Stump11289f42009-09-09 15:08:12 +00001504
Douglas Gregora16548e2009-08-11 05:31:07 +00001505 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001506 ///
1507 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 /// rather than attempting to map the label statement itself.
1509 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001510 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 SourceLocation LabelLoc,
1512 LabelStmt *Label) {
1513 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID());
1514 }
Mike Stump11289f42009-09-09 15:08:12 +00001515
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001517 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 /// By default, performs semantic analysis to build the new expression.
1519 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001520 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001521 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001522 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001523 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001524 }
Mike Stump11289f42009-09-09 15:08:12 +00001525
Douglas Gregora16548e2009-08-11 05:31:07 +00001526 /// \brief Build a new __builtin_choose_expr expression.
1527 ///
1528 /// By default, performs semantic analysis to build the new expression.
1529 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001530 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001531 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001532 SourceLocation RParenLoc) {
1533 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001534 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001535 RParenLoc);
1536 }
Mike Stump11289f42009-09-09 15:08:12 +00001537
Douglas Gregora16548e2009-08-11 05:31:07 +00001538 /// \brief Build a new overloaded operator call expression.
1539 ///
1540 /// By default, performs semantic analysis to build the new expression.
1541 /// The semantic analysis provides the behavior of template instantiation,
1542 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001543 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001544 /// argument-dependent lookup, etc. Subclasses may override this routine to
1545 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001546 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001547 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001548 Expr *Callee,
1549 Expr *First,
1550 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001551
1552 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001553 /// reinterpret_cast.
1554 ///
1555 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001556 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001557 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001558 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 Stmt::StmtClass Class,
1560 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001561 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001562 SourceLocation RAngleLoc,
1563 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001564 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 SourceLocation RParenLoc) {
1566 switch (Class) {
1567 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001568 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001569 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001570 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001571
1572 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001573 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001574 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001575 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001576
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001578 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001579 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001580 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001582
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001584 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001585 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001586 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001587
Douglas Gregora16548e2009-08-11 05:31:07 +00001588 default:
1589 assert(false && "Invalid C++ named cast");
1590 break;
1591 }
Mike Stump11289f42009-09-09 15:08:12 +00001592
John McCallfaf5fb42010-08-26 23:41:50 +00001593 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001594 }
Mike Stump11289f42009-09-09 15:08:12 +00001595
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 /// \brief Build a new C++ static_cast expression.
1597 ///
1598 /// By default, performs semantic analysis to build the new expression.
1599 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001600 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001601 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001602 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001603 SourceLocation RAngleLoc,
1604 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001605 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001607 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001608 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001609 SourceRange(LAngleLoc, RAngleLoc),
1610 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 }
1612
1613 /// \brief Build a new C++ dynamic_cast expression.
1614 ///
1615 /// By default, performs semantic analysis to build the new expression.
1616 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001617 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001618 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001619 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001620 SourceLocation RAngleLoc,
1621 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001622 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001624 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001625 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001626 SourceRange(LAngleLoc, RAngleLoc),
1627 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 }
1629
1630 /// \brief Build a new C++ reinterpret_cast expression.
1631 ///
1632 /// By default, performs semantic analysis to build the new expression.
1633 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001634 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001636 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001637 SourceLocation RAngleLoc,
1638 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001639 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001641 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001642 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001643 SourceRange(LAngleLoc, RAngleLoc),
1644 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 }
1646
1647 /// \brief Build a new C++ const_cast expression.
1648 ///
1649 /// By default, performs semantic analysis to build the new expression.
1650 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001651 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001653 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 SourceLocation RAngleLoc,
1655 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001656 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001658 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001659 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001660 SourceRange(LAngleLoc, RAngleLoc),
1661 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001662 }
Mike Stump11289f42009-09-09 15:08:12 +00001663
Douglas Gregora16548e2009-08-11 05:31:07 +00001664 /// \brief Build a new C++ functional-style cast expression.
1665 ///
1666 /// By default, performs semantic analysis to build the new expression.
1667 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001668 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1669 SourceLocation LParenLoc,
1670 Expr *Sub,
1671 SourceLocation RParenLoc) {
1672 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001673 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001674 RParenLoc);
1675 }
Mike Stump11289f42009-09-09 15:08:12 +00001676
Douglas Gregora16548e2009-08-11 05:31:07 +00001677 /// \brief Build a new C++ typeid(type) expression.
1678 ///
1679 /// By default, performs semantic analysis to build the new expression.
1680 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001681 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001682 SourceLocation TypeidLoc,
1683 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001684 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001685 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001686 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001687 }
Mike Stump11289f42009-09-09 15:08:12 +00001688
Francois Pichet9f4f2072010-09-08 12:20:18 +00001689
Douglas Gregora16548e2009-08-11 05:31:07 +00001690 /// \brief Build a new C++ typeid(expr) expression.
1691 ///
1692 /// By default, performs semantic analysis to build the new expression.
1693 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001694 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001695 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001696 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001697 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001698 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001699 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001700 }
1701
Francois Pichet9f4f2072010-09-08 12:20:18 +00001702 /// \brief Build a new C++ __uuidof(type) expression.
1703 ///
1704 /// By default, performs semantic analysis to build the new expression.
1705 /// Subclasses may override this routine to provide different behavior.
1706 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1707 SourceLocation TypeidLoc,
1708 TypeSourceInfo *Operand,
1709 SourceLocation RParenLoc) {
1710 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1711 RParenLoc);
1712 }
1713
1714 /// \brief Build a new C++ __uuidof(expr) expression.
1715 ///
1716 /// By default, performs semantic analysis to build the new expression.
1717 /// Subclasses may override this routine to provide different behavior.
1718 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1719 SourceLocation TypeidLoc,
1720 Expr *Operand,
1721 SourceLocation RParenLoc) {
1722 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1723 RParenLoc);
1724 }
1725
Douglas Gregora16548e2009-08-11 05:31:07 +00001726 /// \brief Build a new C++ "this" expression.
1727 ///
1728 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001729 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001731 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001732 QualType ThisType,
1733 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001734 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001735 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1736 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 }
1738
1739 /// \brief Build a new C++ throw expression.
1740 ///
1741 /// By default, performs semantic analysis to build the new expression.
1742 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001743 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001744 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001745 }
1746
1747 /// \brief Build a new C++ default-argument expression.
1748 ///
1749 /// By default, builds a new default-argument expression, which does not
1750 /// require any semantic analysis. Subclasses may override this routine to
1751 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001752 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001753 ParmVarDecl *Param) {
1754 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1755 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001756 }
1757
1758 /// \brief Build a new C++ zero-initialization expression.
1759 ///
1760 /// By default, performs semantic analysis to build the new expression.
1761 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001762 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1763 SourceLocation LParenLoc,
1764 SourceLocation RParenLoc) {
1765 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001766 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001767 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001768 }
Mike Stump11289f42009-09-09 15:08:12 +00001769
Douglas Gregora16548e2009-08-11 05:31:07 +00001770 /// \brief Build a new C++ "new" expression.
1771 ///
1772 /// By default, performs semantic analysis to build the new expression.
1773 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001774 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001775 bool UseGlobal,
1776 SourceLocation PlacementLParen,
1777 MultiExprArg PlacementArgs,
1778 SourceLocation PlacementRParen,
1779 SourceRange TypeIdParens,
1780 QualType AllocatedType,
1781 TypeSourceInfo *AllocatedTypeInfo,
1782 Expr *ArraySize,
1783 SourceLocation ConstructorLParen,
1784 MultiExprArg ConstructorArgs,
1785 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001786 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001787 PlacementLParen,
1788 move(PlacementArgs),
1789 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001790 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001791 AllocatedType,
1792 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001793 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001794 ConstructorLParen,
1795 move(ConstructorArgs),
1796 ConstructorRParen);
1797 }
Mike Stump11289f42009-09-09 15:08:12 +00001798
Douglas Gregora16548e2009-08-11 05:31:07 +00001799 /// \brief Build a new C++ "delete" expression.
1800 ///
1801 /// By default, performs semantic analysis to build the new expression.
1802 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001803 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001804 bool IsGlobalDelete,
1805 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001806 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001807 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001808 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001809 }
Mike Stump11289f42009-09-09 15:08:12 +00001810
Douglas Gregora16548e2009-08-11 05:31:07 +00001811 /// \brief Build a new unary type trait expression.
1812 ///
1813 /// By default, performs semantic analysis to build the new expression.
1814 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001815 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001816 SourceLocation StartLoc,
1817 TypeSourceInfo *T,
1818 SourceLocation RParenLoc) {
1819 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001820 }
1821
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001822 /// \brief Build a new binary type trait expression.
1823 ///
1824 /// By default, performs semantic analysis to build the new expression.
1825 /// Subclasses may override this routine to provide different behavior.
1826 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1827 SourceLocation StartLoc,
1828 TypeSourceInfo *LhsT,
1829 TypeSourceInfo *RhsT,
1830 SourceLocation RParenLoc) {
1831 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1832 }
1833
Mike Stump11289f42009-09-09 15:08:12 +00001834 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001835 /// expression.
1836 ///
1837 /// By default, performs semantic analysis to build the new expression.
1838 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001839 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001841 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001842 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001843 CXXScopeSpec SS;
1844 SS.setRange(QualifierRange);
1845 SS.setScopeRep(NNS);
John McCalle66edc12009-11-24 19:00:30 +00001846
1847 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001848 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001849 *TemplateArgs);
1850
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001851 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001852 }
1853
1854 /// \brief Build a new template-id expression.
1855 ///
1856 /// By default, performs semantic analysis to build the new expression.
1857 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001858 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001859 LookupResult &R,
1860 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001861 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001862 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 }
1864
1865 /// \brief Build a new object-construction expression.
1866 ///
1867 /// By default, performs semantic analysis to build the new expression.
1868 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001869 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001870 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001871 CXXConstructorDecl *Constructor,
1872 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001873 MultiExprArg Args,
1874 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001875 CXXConstructExpr::ConstructionKind ConstructKind,
1876 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001877 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001878 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001879 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001880 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001881
Douglas Gregordb121ba2009-12-14 16:27:04 +00001882 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001883 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001884 RequiresZeroInit, ConstructKind,
1885 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001886 }
1887
1888 /// \brief Build a new object-construction expression.
1889 ///
1890 /// By default, performs semantic analysis to build the new expression.
1891 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001892 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1893 SourceLocation LParenLoc,
1894 MultiExprArg Args,
1895 SourceLocation RParenLoc) {
1896 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001897 LParenLoc,
1898 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001899 RParenLoc);
1900 }
1901
1902 /// \brief Build a new object-construction expression.
1903 ///
1904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001906 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1907 SourceLocation LParenLoc,
1908 MultiExprArg Args,
1909 SourceLocation RParenLoc) {
1910 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001911 LParenLoc,
1912 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 RParenLoc);
1914 }
Mike Stump11289f42009-09-09 15:08:12 +00001915
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 /// \brief Build a new member reference expression.
1917 ///
1918 /// By default, performs semantic analysis to build the new expression.
1919 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001920 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001921 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001922 bool IsArrow,
1923 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001924 NestedNameSpecifier *Qualifier,
1925 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001926 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001927 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001928 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 CXXScopeSpec SS;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001930 SS.setRange(QualifierRange);
1931 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001932
John McCallb268a282010-08-23 23:25:46 +00001933 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001934 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001935 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001936 MemberNameInfo,
1937 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001938 }
1939
John McCall10eae182009-11-30 22:42:35 +00001940 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001941 ///
1942 /// By default, performs semantic analysis to build the new expression.
1943 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001944 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001945 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001946 SourceLocation OperatorLoc,
1947 bool IsArrow,
1948 NestedNameSpecifier *Qualifier,
1949 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001950 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00001951 LookupResult &R,
1952 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00001953 CXXScopeSpec SS;
1954 SS.setRange(QualifierRange);
1955 SS.setScopeRep(Qualifier);
Mike Stump11289f42009-09-09 15:08:12 +00001956
John McCallb268a282010-08-23 23:25:46 +00001957 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001958 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00001959 SS, FirstQualifierInScope,
1960 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00001961 }
Mike Stump11289f42009-09-09 15:08:12 +00001962
Sebastian Redl4202c0f2010-09-10 20:55:43 +00001963 /// \brief Build a new noexcept expression.
1964 ///
1965 /// By default, performs semantic analysis to build the new expression.
1966 /// Subclasses may override this routine to provide different behavior.
1967 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
1968 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
1969 }
1970
Douglas Gregor820ba7b2011-01-04 17:33:58 +00001971 /// \brief Build a new expression to compute the length of a parameter pack.
1972 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
1973 SourceLocation PackLoc,
1974 SourceLocation RParenLoc,
1975 unsigned Length) {
1976 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
1977 OperatorLoc, Pack, PackLoc,
1978 RParenLoc, Length);
1979 }
1980
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 /// \brief Build a new Objective-C @encode expression.
1982 ///
1983 /// By default, performs semantic analysis to build the new expression.
1984 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001985 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00001986 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001987 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00001988 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001989 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00001990 }
Douglas Gregora16548e2009-08-11 05:31:07 +00001991
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001992 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00001993 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001994 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00001995 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001996 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00001997 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00001998 MultiExprArg Args,
1999 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002000 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2001 ReceiverTypeInfo->getType(),
2002 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002003 Sel, Method, LBracLoc, SelectorLoc,
2004 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002005 }
2006
2007 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002008 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002009 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002010 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002011 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002012 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002013 MultiExprArg Args,
2014 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002015 return SemaRef.BuildInstanceMessage(Receiver,
2016 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002017 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002018 Sel, Method, LBracLoc, SelectorLoc,
2019 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002020 }
2021
Douglas Gregord51d90d2010-04-26 20:11:03 +00002022 /// \brief Build a new Objective-C ivar reference expression.
2023 ///
2024 /// By default, performs semantic analysis to build the new expression.
2025 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002026 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002027 SourceLocation IvarLoc,
2028 bool IsArrow, bool IsFreeIvar) {
2029 // FIXME: We lose track of the IsFreeIvar bit.
2030 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002031 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002032 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2033 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002034 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002035 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002036 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002037 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002038 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002039 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002040
Douglas Gregord51d90d2010-04-26 20:11:03 +00002041 if (Result.get())
2042 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002043
John McCallb268a282010-08-23 23:25:46 +00002044 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002045 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002046 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002047 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002048 /*TemplateArgs=*/0);
2049 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002050
2051 /// \brief Build a new Objective-C property reference expression.
2052 ///
2053 /// By default, performs semantic analysis to build the new expression.
2054 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002055 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002056 ObjCPropertyDecl *Property,
2057 SourceLocation PropertyLoc) {
2058 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002059 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002060 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2061 Sema::LookupMemberName);
2062 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002063 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002064 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002065 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002066 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002067 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002068
Douglas Gregor9faee212010-04-26 20:47:02 +00002069 if (Result.get())
2070 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002071
John McCallb268a282010-08-23 23:25:46 +00002072 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002073 /*FIXME:*/PropertyLoc, IsArrow,
2074 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002075 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002076 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002077 /*TemplateArgs=*/0);
2078 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002079
John McCallb7bd14f2010-12-02 01:19:52 +00002080 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002081 ///
2082 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002083 /// Subclasses may override this routine to provide different behavior.
2084 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2085 ObjCMethodDecl *Getter,
2086 ObjCMethodDecl *Setter,
2087 SourceLocation PropertyLoc) {
2088 // Since these expressions can only be value-dependent, we do not
2089 // need to perform semantic analysis again.
2090 return Owned(
2091 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2092 VK_LValue, OK_ObjCProperty,
2093 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002094 }
2095
Douglas Gregord51d90d2010-04-26 20:11:03 +00002096 /// \brief Build a new Objective-C "isa" expression.
2097 ///
2098 /// By default, performs semantic analysis to build the new expression.
2099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002100 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002101 bool IsArrow) {
2102 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002103 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002104 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2105 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002106 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002107 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002108 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002109 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002110 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002111
Douglas Gregord51d90d2010-04-26 20:11:03 +00002112 if (Result.get())
2113 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002114
John McCallb268a282010-08-23 23:25:46 +00002115 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002116 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002117 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002118 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002119 /*TemplateArgs=*/0);
2120 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002121
Douglas Gregora16548e2009-08-11 05:31:07 +00002122 /// \brief Build a new shuffle vector expression.
2123 ///
2124 /// By default, performs semantic analysis to build the new expression.
2125 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002126 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002127 MultiExprArg SubExprs,
2128 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002130 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002131 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2132 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2133 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2134 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002135
Douglas Gregora16548e2009-08-11 05:31:07 +00002136 // Build a reference to the __builtin_shufflevector builtin
2137 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002138 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002139 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002140 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002141 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002142
2143 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002144 unsigned NumSubExprs = SubExprs.size();
2145 Expr **Subs = (Expr **)SubExprs.release();
2146 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2147 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002148 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002149 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002150 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002151 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002152
Douglas Gregora16548e2009-08-11 05:31:07 +00002153 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002154 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002156 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002157
Douglas Gregora16548e2009-08-11 05:31:07 +00002158 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002159 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002160 }
John McCall31f82722010-11-12 08:19:04 +00002161
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002162 /// \brief Build a new template argument pack expansion.
2163 ///
2164 /// By default, performs semantic analysis to build a new pack expansion
2165 /// for a template argument. Subclasses may override this routine to provide
2166 /// different behavior.
2167 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
2168 SourceLocation EllipsisLoc) {
2169 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002170 case TemplateArgument::Expression: {
2171 ExprResult Result
2172 = getSema().ActOnPackExpansion(Pattern.getSourceExpression(),
2173 EllipsisLoc);
2174 if (Result.isInvalid())
2175 return TemplateArgumentLoc();
2176
2177 return TemplateArgumentLoc(Result.get(), Result.get());
2178 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002179
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002180 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002181 return TemplateArgumentLoc(TemplateArgument(
2182 Pattern.getArgument().getAsTemplate(),
2183 true),
2184 Pattern.getTemplateQualifierRange(),
2185 Pattern.getTemplateNameLoc(),
2186 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002187
2188 case TemplateArgument::Null:
2189 case TemplateArgument::Integral:
2190 case TemplateArgument::Declaration:
2191 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002192 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002193 llvm_unreachable("Pack expansion pattern has no parameter packs");
2194
2195 case TemplateArgument::Type:
2196 if (TypeSourceInfo *Expansion
2197 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
2198 EllipsisLoc))
2199 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2200 Expansion);
2201 break;
2202 }
2203
2204 return TemplateArgumentLoc();
2205 }
2206
Douglas Gregor968f23a2011-01-03 19:31:53 +00002207 /// \brief Build a new expression pack expansion.
2208 ///
2209 /// By default, performs semantic analysis to build a new pack expansion
2210 /// for an expression. Subclasses may override this routine to provide
2211 /// different behavior.
2212 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc) {
2213 return getSema().ActOnPackExpansion(Pattern, EllipsisLoc);
2214 }
2215
John McCall31f82722010-11-12 08:19:04 +00002216private:
2217 QualType TransformTypeInObjectScope(QualType T,
2218 QualType ObjectType,
2219 NamedDecl *FirstQualifierInScope,
2220 NestedNameSpecifier *Prefix);
2221
2222 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2223 QualType ObjectType,
2224 NamedDecl *FirstQualifierInScope,
2225 NestedNameSpecifier *Prefix);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002226};
Douglas Gregora16548e2009-08-11 05:31:07 +00002227
Douglas Gregorebe10102009-08-20 07:17:43 +00002228template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002229StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002230 if (!S)
2231 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002232
Douglas Gregorebe10102009-08-20 07:17:43 +00002233 switch (S->getStmtClass()) {
2234 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002235
Douglas Gregorebe10102009-08-20 07:17:43 +00002236 // Transform individual statement nodes
2237#define STMT(Node, Parent) \
2238 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
2239#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002240#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002241
Douglas Gregorebe10102009-08-20 07:17:43 +00002242 // Transform expressions by calling TransformExpr.
2243#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002244#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002245#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002246#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002247 {
John McCalldadc5752010-08-24 06:29:42 +00002248 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002249 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002250 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002251
John McCallb268a282010-08-23 23:25:46 +00002252 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002253 }
Mike Stump11289f42009-09-09 15:08:12 +00002254 }
2255
John McCallc3007a22010-10-26 07:05:15 +00002256 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002257}
Mike Stump11289f42009-09-09 15:08:12 +00002258
2259
Douglas Gregore922c772009-08-04 22:27:00 +00002260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002261ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002262 if (!E)
2263 return SemaRef.Owned(E);
2264
2265 switch (E->getStmtClass()) {
2266 case Stmt::NoStmtClass: break;
2267#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002268#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002269#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002270 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002271#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002272 }
2273
John McCallc3007a22010-10-26 07:05:15 +00002274 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002275}
2276
2277template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002278bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2279 unsigned NumInputs,
2280 bool IsCall,
2281 llvm::SmallVectorImpl<Expr *> &Outputs,
2282 bool *ArgChanged) {
2283 for (unsigned I = 0; I != NumInputs; ++I) {
2284 // If requested, drop call arguments that need to be dropped.
2285 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2286 if (ArgChanged)
2287 *ArgChanged = true;
2288
2289 break;
2290 }
2291
Douglas Gregor968f23a2011-01-03 19:31:53 +00002292 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2293 Expr *Pattern = Expansion->getPattern();
2294
2295 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2296 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2297 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2298
2299 // Determine whether the set of unexpanded parameter packs can and should
2300 // be expanded.
2301 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002302 bool RetainExpansion = false;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002303 unsigned NumExpansions = 0;
2304 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2305 Pattern->getSourceRange(),
2306 Unexpanded.data(),
2307 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002308 Expand, RetainExpansion,
2309 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002310 return true;
2311
2312 if (!Expand) {
2313 // The transform has determined that we should perform a simple
2314 // transformation on the pack expansion, producing another pack
2315 // expansion.
2316 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2317 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2318 if (OutPattern.isInvalid())
2319 return true;
2320
2321 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
2322 Expansion->getEllipsisLoc());
2323 if (Out.isInvalid())
2324 return true;
2325
2326 if (ArgChanged)
2327 *ArgChanged = true;
2328 Outputs.push_back(Out.get());
2329 continue;
2330 }
2331
2332 // The transform has determined that we should perform an elementwise
2333 // expansion of the pattern. Do so.
2334 for (unsigned I = 0; I != NumExpansions; ++I) {
2335 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2336 ExprResult Out = getDerived().TransformExpr(Pattern);
2337 if (Out.isInvalid())
2338 return true;
2339
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002340 if (Out.get()->containsUnexpandedParameterPack()) {
2341 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc());
2342 if (Out.isInvalid())
2343 return true;
2344 }
2345
Douglas Gregor968f23a2011-01-03 19:31:53 +00002346 if (ArgChanged)
2347 *ArgChanged = true;
2348 Outputs.push_back(Out.get());
2349 }
2350
2351 continue;
2352 }
2353
Douglas Gregora3efea12011-01-03 19:04:46 +00002354 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2355 if (Result.isInvalid())
2356 return true;
2357
2358 if (Result.get() != Inputs[I] && ArgChanged)
2359 *ArgChanged = true;
2360
2361 Outputs.push_back(Result.get());
2362 }
2363
2364 return false;
2365}
2366
2367template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002368NestedNameSpecifier *
2369TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002370 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002371 QualType ObjectType,
2372 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002373 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002374
Douglas Gregorebe10102009-08-20 07:17:43 +00002375 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002376 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002377 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002378 ObjectType,
2379 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002380 if (!Prefix)
2381 return 0;
2382 }
Mike Stump11289f42009-09-09 15:08:12 +00002383
Douglas Gregor1135c352009-08-06 05:28:30 +00002384 switch (NNS->getKind()) {
2385 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002386 if (Prefix) {
2387 // The object type and qualifier-in-scope really apply to the
2388 // leftmost entity.
2389 ObjectType = QualType();
2390 FirstQualifierInScope = 0;
2391 }
2392
Mike Stump11289f42009-09-09 15:08:12 +00002393 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002394 "Identifier nested-name-specifier with no prefix or object type");
2395 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2396 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002397 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002398
2399 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002400 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002401 ObjectType,
2402 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002403
Douglas Gregor1135c352009-08-06 05:28:30 +00002404 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002405 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002406 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002407 getDerived().TransformDecl(Range.getBegin(),
2408 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002409 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002410 Prefix == NNS->getPrefix() &&
2411 NS == NNS->getAsNamespace())
2412 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002413
Douglas Gregor1135c352009-08-06 05:28:30 +00002414 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2415 }
Mike Stump11289f42009-09-09 15:08:12 +00002416
Douglas Gregor1135c352009-08-06 05:28:30 +00002417 case NestedNameSpecifier::Global:
2418 // There is no meaningful transformation that one could perform on the
2419 // global scope.
2420 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002421
Douglas Gregor1135c352009-08-06 05:28:30 +00002422 case NestedNameSpecifier::TypeSpecWithTemplate:
2423 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002424 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002425 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2426 ObjectType,
2427 FirstQualifierInScope,
2428 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002429 if (T.isNull())
2430 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002431
Douglas Gregor1135c352009-08-06 05:28:30 +00002432 if (!getDerived().AlwaysRebuild() &&
2433 Prefix == NNS->getPrefix() &&
2434 T == QualType(NNS->getAsType(), 0))
2435 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002436
2437 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2438 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002439 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002440 }
2441 }
Mike Stump11289f42009-09-09 15:08:12 +00002442
Douglas Gregor1135c352009-08-06 05:28:30 +00002443 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002444 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002445}
2446
2447template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002448DeclarationNameInfo
2449TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002450::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002451 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002452 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002453 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002454
2455 switch (Name.getNameKind()) {
2456 case DeclarationName::Identifier:
2457 case DeclarationName::ObjCZeroArgSelector:
2458 case DeclarationName::ObjCOneArgSelector:
2459 case DeclarationName::ObjCMultiArgSelector:
2460 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002461 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002462 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002463 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002464
Douglas Gregorf816bd72009-09-03 22:13:48 +00002465 case DeclarationName::CXXConstructorName:
2466 case DeclarationName::CXXDestructorName:
2467 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002468 TypeSourceInfo *NewTInfo;
2469 CanQualType NewCanTy;
2470 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002471 NewTInfo = getDerived().TransformType(OldTInfo);
2472 if (!NewTInfo)
2473 return DeclarationNameInfo();
2474 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002475 }
2476 else {
2477 NewTInfo = 0;
2478 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002479 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002480 if (NewT.isNull())
2481 return DeclarationNameInfo();
2482 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2483 }
Mike Stump11289f42009-09-09 15:08:12 +00002484
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002485 DeclarationName NewName
2486 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2487 NewCanTy);
2488 DeclarationNameInfo NewNameInfo(NameInfo);
2489 NewNameInfo.setName(NewName);
2490 NewNameInfo.setNamedTypeInfo(NewTInfo);
2491 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002492 }
Mike Stump11289f42009-09-09 15:08:12 +00002493 }
2494
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002495 assert(0 && "Unknown name kind.");
2496 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002497}
2498
2499template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002500TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002501TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002502 QualType ObjectType,
2503 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002504 SourceLocation Loc = getDerived().getBaseLocation();
2505
Douglas Gregor71dc5092009-08-06 06:41:21 +00002506 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002507 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002508 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002509 /*FIXME*/ SourceRange(Loc),
2510 ObjectType,
2511 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002512 if (!NNS)
2513 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002514
Douglas Gregor71dc5092009-08-06 06:41:21 +00002515 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002516 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002517 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002518 if (!TransTemplate)
2519 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002520
Douglas Gregor71dc5092009-08-06 06:41:21 +00002521 if (!getDerived().AlwaysRebuild() &&
2522 NNS == QTN->getQualifier() &&
2523 TransTemplate == Template)
2524 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002525
Douglas Gregor71dc5092009-08-06 06:41:21 +00002526 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2527 TransTemplate);
2528 }
Mike Stump11289f42009-09-09 15:08:12 +00002529
John McCalle66edc12009-11-24 19:00:30 +00002530 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002531 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002532 }
Mike Stump11289f42009-09-09 15:08:12 +00002533
Douglas Gregor71dc5092009-08-06 06:41:21 +00002534 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002535 NestedNameSpecifier *NNS = DTN->getQualifier();
2536 if (NNS) {
2537 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2538 /*FIXME:*/SourceRange(Loc),
2539 ObjectType,
2540 FirstQualifierInScope);
2541 if (!NNS) return TemplateName();
2542
2543 // These apply to the scope specifier, not the template.
2544 ObjectType = QualType();
2545 FirstQualifierInScope = 0;
2546 }
Mike Stump11289f42009-09-09 15:08:12 +00002547
Douglas Gregor71dc5092009-08-06 06:41:21 +00002548 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002549 NNS == DTN->getQualifier() &&
2550 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002551 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002552
Douglas Gregora5614c52010-09-08 23:56:00 +00002553 if (DTN->isIdentifier()) {
2554 // FIXME: Bad range
2555 SourceRange QualifierRange(getDerived().getBaseLocation());
2556 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2557 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002558 ObjectType,
2559 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002560 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002561
2562 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002563 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002564 }
Mike Stump11289f42009-09-09 15:08:12 +00002565
Douglas Gregor71dc5092009-08-06 06:41:21 +00002566 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002567 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002568 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002569 if (!TransTemplate)
2570 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002571
Douglas Gregor71dc5092009-08-06 06:41:21 +00002572 if (!getDerived().AlwaysRebuild() &&
2573 TransTemplate == Template)
2574 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002575
Douglas Gregor71dc5092009-08-06 06:41:21 +00002576 return TemplateName(TransTemplate);
2577 }
Mike Stump11289f42009-09-09 15:08:12 +00002578
John McCalle66edc12009-11-24 19:00:30 +00002579 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002580 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002581 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002582}
2583
2584template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002585void TreeTransform<Derived>::InventTemplateArgumentLoc(
2586 const TemplateArgument &Arg,
2587 TemplateArgumentLoc &Output) {
2588 SourceLocation Loc = getDerived().getBaseLocation();
2589 switch (Arg.getKind()) {
2590 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002591 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002592 break;
2593
2594 case TemplateArgument::Type:
2595 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002596 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002597
John McCall0ad16662009-10-29 08:12:44 +00002598 break;
2599
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002600 case TemplateArgument::Template:
2601 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2602 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002603
2604 case TemplateArgument::TemplateExpansion:
2605 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2606 break;
2607
John McCall0ad16662009-10-29 08:12:44 +00002608 case TemplateArgument::Expression:
2609 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2610 break;
2611
2612 case TemplateArgument::Declaration:
2613 case TemplateArgument::Integral:
2614 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002615 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002616 break;
2617 }
2618}
2619
2620template<typename Derived>
2621bool TreeTransform<Derived>::TransformTemplateArgument(
2622 const TemplateArgumentLoc &Input,
2623 TemplateArgumentLoc &Output) {
2624 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002625 switch (Arg.getKind()) {
2626 case TemplateArgument::Null:
2627 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002628 Output = Input;
2629 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002630
Douglas Gregore922c772009-08-04 22:27:00 +00002631 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002632 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002633 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002634 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002635
2636 DI = getDerived().TransformType(DI);
2637 if (!DI) return true;
2638
2639 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2640 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002641 }
Mike Stump11289f42009-09-09 15:08:12 +00002642
Douglas Gregore922c772009-08-04 22:27:00 +00002643 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002644 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002645 DeclarationName Name;
2646 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2647 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002648 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002649 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002650 if (!D) return true;
2651
John McCall0d07eb32009-10-29 18:45:58 +00002652 Expr *SourceExpr = Input.getSourceDeclExpression();
2653 if (SourceExpr) {
2654 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002655 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002656 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002657 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002658 }
2659
2660 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002661 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002662 }
Mike Stump11289f42009-09-09 15:08:12 +00002663
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002664 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002665 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002666 TemplateName Template
2667 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2668 if (Template.isNull())
2669 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002670
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002671 Output = TemplateArgumentLoc(TemplateArgument(Template),
2672 Input.getTemplateQualifierRange(),
2673 Input.getTemplateNameLoc());
2674 return false;
2675 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002676
2677 case TemplateArgument::TemplateExpansion:
2678 llvm_unreachable("Caller should expand pack expansions");
2679
Douglas Gregore922c772009-08-04 22:27:00 +00002680 case TemplateArgument::Expression: {
2681 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002682 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002683 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002684
John McCall0ad16662009-10-29 08:12:44 +00002685 Expr *InputExpr = Input.getSourceExpression();
2686 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2687
John McCalldadc5752010-08-24 06:29:42 +00002688 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002689 = getDerived().TransformExpr(InputExpr);
2690 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002691 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002692 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002693 }
Mike Stump11289f42009-09-09 15:08:12 +00002694
Douglas Gregore922c772009-08-04 22:27:00 +00002695 case TemplateArgument::Pack: {
2696 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2697 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002698 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002699 AEnd = Arg.pack_end();
2700 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002701
John McCall0ad16662009-10-29 08:12:44 +00002702 // FIXME: preserve source information here when we start
2703 // caring about parameter packs.
2704
John McCall0d07eb32009-10-29 18:45:58 +00002705 TemplateArgumentLoc InputArg;
2706 TemplateArgumentLoc OutputArg;
2707 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2708 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002709 return true;
2710
John McCall0d07eb32009-10-29 18:45:58 +00002711 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002712 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002713
2714 TemplateArgument *TransformedArgsPtr
2715 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2716 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2717 TransformedArgsPtr);
2718 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2719 TransformedArgs.size()),
2720 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002721 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002722 }
2723 }
Mike Stump11289f42009-09-09 15:08:12 +00002724
Douglas Gregore922c772009-08-04 22:27:00 +00002725 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002726 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002727}
2728
Douglas Gregorfe921a72010-12-20 23:36:19 +00002729/// \brief Iterator adaptor that invents template argument location information
2730/// for each of the template arguments in its underlying iterator.
2731template<typename Derived, typename InputIterator>
2732class TemplateArgumentLocInventIterator {
2733 TreeTransform<Derived> &Self;
2734 InputIterator Iter;
2735
2736public:
2737 typedef TemplateArgumentLoc value_type;
2738 typedef TemplateArgumentLoc reference;
2739 typedef typename std::iterator_traits<InputIterator>::difference_type
2740 difference_type;
2741 typedef std::input_iterator_tag iterator_category;
2742
2743 class pointer {
2744 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002745
Douglas Gregorfe921a72010-12-20 23:36:19 +00002746 public:
2747 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2748
2749 const TemplateArgumentLoc *operator->() const { return &Arg; }
2750 };
2751
2752 TemplateArgumentLocInventIterator() { }
2753
2754 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2755 InputIterator Iter)
2756 : Self(Self), Iter(Iter) { }
2757
2758 TemplateArgumentLocInventIterator &operator++() {
2759 ++Iter;
2760 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002761 }
2762
Douglas Gregorfe921a72010-12-20 23:36:19 +00002763 TemplateArgumentLocInventIterator operator++(int) {
2764 TemplateArgumentLocInventIterator Old(*this);
2765 ++(*this);
2766 return Old;
2767 }
2768
2769 reference operator*() const {
2770 TemplateArgumentLoc Result;
2771 Self.InventTemplateArgumentLoc(*Iter, Result);
2772 return Result;
2773 }
2774
2775 pointer operator->() const { return pointer(**this); }
2776
2777 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2778 const TemplateArgumentLocInventIterator &Y) {
2779 return X.Iter == Y.Iter;
2780 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002781
Douglas Gregorfe921a72010-12-20 23:36:19 +00002782 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2783 const TemplateArgumentLocInventIterator &Y) {
2784 return X.Iter != Y.Iter;
2785 }
2786};
2787
Douglas Gregor42cafa82010-12-20 17:42:22 +00002788template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002789template<typename InputIterator>
2790bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2791 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002792 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002793 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002794 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002795 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002796
2797 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2798 // Unpack argument packs, which we translate them into separate
2799 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002800 // FIXME: We could do much better if we could guarantee that the
2801 // TemplateArgumentLocInfo for the pack expansion would be usable for
2802 // all of the template arguments in the argument pack.
2803 typedef TemplateArgumentLocInventIterator<Derived,
2804 TemplateArgument::pack_iterator>
2805 PackLocIterator;
2806 if (TransformTemplateArguments(PackLocIterator(*this,
2807 In.getArgument().pack_begin()),
2808 PackLocIterator(*this,
2809 In.getArgument().pack_end()),
2810 Outputs))
2811 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002812
2813 continue;
2814 }
2815
2816 if (In.getArgument().isPackExpansion()) {
2817 // We have a pack expansion, for which we will be substituting into
2818 // the pattern.
2819 SourceLocation Ellipsis;
2820 TemplateArgumentLoc Pattern
2821 = In.getPackExpansionPattern(Ellipsis, getSema().Context);
2822
2823 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2824 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2825 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2826
2827 // Determine whether the set of unexpanded parameter packs can and should
2828 // be expanded.
2829 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002830 bool RetainExpansion = false;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002831 unsigned NumExpansions = 0;
2832 if (getDerived().TryExpandParameterPacks(Ellipsis,
2833 Pattern.getSourceRange(),
2834 Unexpanded.data(),
2835 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002836 Expand,
2837 RetainExpansion,
2838 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002839 return true;
2840
2841 if (!Expand) {
2842 // The transform has determined that we should perform a simple
2843 // transformation on the pack expansion, producing another pack
2844 // expansion.
2845 TemplateArgumentLoc OutPattern;
2846 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2847 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
2848 return true;
2849
2850 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis);
2851 if (Out.getArgument().isNull())
2852 return true;
2853
2854 Outputs.addArgument(Out);
2855 continue;
2856 }
2857
2858 // The transform has determined that we should perform an elementwise
2859 // expansion of the pattern. Do so.
2860 for (unsigned I = 0; I != NumExpansions; ++I) {
2861 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2862
2863 if (getDerived().TransformTemplateArgument(Pattern, Out))
2864 return true;
2865
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002866 if (Out.getArgument().containsUnexpandedParameterPack()) {
2867 Out = getDerived().RebuildPackExpansion(Out, Ellipsis);
2868 if (Out.getArgument().isNull())
2869 return true;
2870 }
2871
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002872 Outputs.addArgument(Out);
2873 }
2874
Douglas Gregor48d24112011-01-10 20:53:55 +00002875 // If we're supposed to retain a pack expansion, do so by temporarily
2876 // forgetting the partially-substituted parameter pack.
2877 if (RetainExpansion) {
2878 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
2879
2880 if (getDerived().TransformTemplateArgument(Pattern, Out))
2881 return true;
2882
2883 Out = getDerived().RebuildPackExpansion(Out, Ellipsis);
2884 if (Out.getArgument().isNull())
2885 return true;
2886
2887 Outputs.addArgument(Out);
2888 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002889
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002890 continue;
2891 }
2892
2893 // The simple case:
2894 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00002895 return true;
2896
2897 Outputs.addArgument(Out);
2898 }
2899
2900 return false;
2901
2902}
2903
Douglas Gregord6ff3322009-08-04 16:50:30 +00002904//===----------------------------------------------------------------------===//
2905// Type transformation
2906//===----------------------------------------------------------------------===//
2907
2908template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002909QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00002910 if (getDerived().AlreadyTransformed(T))
2911 return T;
Mike Stump11289f42009-09-09 15:08:12 +00002912
John McCall550e0c22009-10-21 00:40:46 +00002913 // Temporary workaround. All of these transformations should
2914 // eventually turn into transformations on TypeLocs.
John McCallbcd03502009-12-07 02:54:59 +00002915 TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T);
John McCallde889892009-10-21 00:44:26 +00002916 DI->getTypeLoc().initialize(getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00002917
John McCall31f82722010-11-12 08:19:04 +00002918 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00002919
John McCall550e0c22009-10-21 00:40:46 +00002920 if (!NewDI)
2921 return QualType();
2922
2923 return NewDI->getType();
2924}
2925
2926template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00002927TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00002928 if (getDerived().AlreadyTransformed(DI->getType()))
2929 return DI;
2930
2931 TypeLocBuilder TLB;
2932
2933 TypeLoc TL = DI->getTypeLoc();
2934 TLB.reserve(TL.getFullDataSize());
2935
John McCall31f82722010-11-12 08:19:04 +00002936 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00002937 if (Result.isNull())
2938 return 0;
2939
John McCallbcd03502009-12-07 02:54:59 +00002940 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00002941}
2942
2943template<typename Derived>
2944QualType
John McCall31f82722010-11-12 08:19:04 +00002945TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00002946 switch (T.getTypeLocClass()) {
2947#define ABSTRACT_TYPELOC(CLASS, PARENT)
2948#define TYPELOC(CLASS, PARENT) \
2949 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00002950 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00002951#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00002952 }
Mike Stump11289f42009-09-09 15:08:12 +00002953
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002954 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00002955 return QualType();
2956}
2957
2958/// FIXME: By default, this routine adds type qualifiers only to types
2959/// that can have qualifiers, and silently suppresses those qualifiers
2960/// that are not permitted (e.g., qualifiers on reference or function
2961/// types). This is the right thing for template instantiation, but
2962/// probably not for other clients.
2963template<typename Derived>
2964QualType
2965TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00002966 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00002967 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00002968
John McCall31f82722010-11-12 08:19:04 +00002969 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00002970 if (Result.isNull())
2971 return QualType();
2972
2973 // Silently suppress qualifiers if the result type can't be qualified.
2974 // FIXME: this is the right thing for template instantiation, but
2975 // probably not for other clients.
2976 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00002977 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00002978
John McCallcb0f89a2010-06-05 06:41:15 +00002979 if (!Quals.empty()) {
2980 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
2981 TLB.push<QualifiedTypeLoc>(Result);
2982 // No location information to preserve.
2983 }
John McCall550e0c22009-10-21 00:40:46 +00002984
2985 return Result;
2986}
2987
John McCall31f82722010-11-12 08:19:04 +00002988/// \brief Transforms a type that was written in a scope specifier,
2989/// given an object type, the results of unqualified lookup, and
2990/// an already-instantiated prefix.
2991///
2992/// The object type is provided iff the scope specifier qualifies the
2993/// member of a dependent member-access expression. The prefix is
2994/// provided iff the the scope specifier in which this appears has a
2995/// prefix.
2996///
2997/// This is private to TreeTransform.
2998template<typename Derived>
2999QualType
3000TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3001 QualType ObjectType,
3002 NamedDecl *UnqualLookup,
3003 NestedNameSpecifier *Prefix) {
3004 if (getDerived().AlreadyTransformed(T))
3005 return T;
3006
3007 TypeSourceInfo *TSI =
3008 SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation());
3009
3010 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3011 UnqualLookup, Prefix);
3012 if (!TSI) return QualType();
3013 return TSI->getType();
3014}
3015
3016template<typename Derived>
3017TypeSourceInfo *
3018TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3019 QualType ObjectType,
3020 NamedDecl *UnqualLookup,
3021 NestedNameSpecifier *Prefix) {
3022 // TODO: in some cases, we might be some verification to do here.
3023 if (ObjectType.isNull())
3024 return getDerived().TransformType(TSI);
3025
3026 QualType T = TSI->getType();
3027 if (getDerived().AlreadyTransformed(T))
3028 return TSI;
3029
3030 TypeLocBuilder TLB;
3031 QualType Result;
3032
3033 if (isa<TemplateSpecializationType>(T)) {
3034 TemplateSpecializationTypeLoc TL
3035 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3036
3037 TemplateName Template =
3038 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3039 ObjectType, UnqualLookup);
3040 if (Template.isNull()) return 0;
3041
3042 Result = getDerived()
3043 .TransformTemplateSpecializationType(TLB, TL, Template);
3044 } else if (isa<DependentTemplateSpecializationType>(T)) {
3045 DependentTemplateSpecializationTypeLoc TL
3046 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3047
3048 Result = getDerived()
3049 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3050 } else {
3051 // Nothing special needs to be done for these.
3052 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3053 }
3054
3055 if (Result.isNull()) return 0;
3056 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3057}
3058
John McCall550e0c22009-10-21 00:40:46 +00003059template <class TyLoc> static inline
3060QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3061 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3062 NewT.setNameLoc(T.getNameLoc());
3063 return T.getType();
3064}
3065
John McCall550e0c22009-10-21 00:40:46 +00003066template<typename Derived>
3067QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003068 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003069 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3070 NewT.setBuiltinLoc(T.getBuiltinLoc());
3071 if (T.needsExtraLocalData())
3072 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3073 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003074}
Mike Stump11289f42009-09-09 15:08:12 +00003075
Douglas Gregord6ff3322009-08-04 16:50:30 +00003076template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003077QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003078 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003079 // FIXME: recurse?
3080 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003081}
Mike Stump11289f42009-09-09 15:08:12 +00003082
Douglas Gregord6ff3322009-08-04 16:50:30 +00003083template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003084QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003085 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003086 QualType PointeeType
3087 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003088 if (PointeeType.isNull())
3089 return QualType();
3090
3091 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003092 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003093 // A dependent pointer type 'T *' has is being transformed such
3094 // that an Objective-C class type is being replaced for 'T'. The
3095 // resulting pointer type is an ObjCObjectPointerType, not a
3096 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003097 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003098
John McCall8b07ec22010-05-15 11:32:37 +00003099 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3100 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003101 return Result;
3102 }
John McCall31f82722010-11-12 08:19:04 +00003103
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003104 if (getDerived().AlwaysRebuild() ||
3105 PointeeType != TL.getPointeeLoc().getType()) {
3106 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3107 if (Result.isNull())
3108 return QualType();
3109 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003110
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003111 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3112 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003113 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003114}
Mike Stump11289f42009-09-09 15:08:12 +00003115
3116template<typename Derived>
3117QualType
John McCall550e0c22009-10-21 00:40:46 +00003118TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003119 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003120 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003121 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3122 if (PointeeType.isNull())
3123 return QualType();
3124
3125 QualType Result = TL.getType();
3126 if (getDerived().AlwaysRebuild() ||
3127 PointeeType != TL.getPointeeLoc().getType()) {
3128 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003129 TL.getSigilLoc());
3130 if (Result.isNull())
3131 return QualType();
3132 }
3133
Douglas Gregor049211a2010-04-22 16:50:51 +00003134 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003135 NewT.setSigilLoc(TL.getSigilLoc());
3136 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003137}
3138
John McCall70dd5f62009-10-30 00:06:24 +00003139/// Transforms a reference type. Note that somewhat paradoxically we
3140/// don't care whether the type itself is an l-value type or an r-value
3141/// type; we only care if the type was *written* as an l-value type
3142/// or an r-value type.
3143template<typename Derived>
3144QualType
3145TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003146 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003147 const ReferenceType *T = TL.getTypePtr();
3148
3149 // Note that this works with the pointee-as-written.
3150 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3151 if (PointeeType.isNull())
3152 return QualType();
3153
3154 QualType Result = TL.getType();
3155 if (getDerived().AlwaysRebuild() ||
3156 PointeeType != T->getPointeeTypeAsWritten()) {
3157 Result = getDerived().RebuildReferenceType(PointeeType,
3158 T->isSpelledAsLValue(),
3159 TL.getSigilLoc());
3160 if (Result.isNull())
3161 return QualType();
3162 }
3163
3164 // r-value references can be rebuilt as l-value references.
3165 ReferenceTypeLoc NewTL;
3166 if (isa<LValueReferenceType>(Result))
3167 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3168 else
3169 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3170 NewTL.setSigilLoc(TL.getSigilLoc());
3171
3172 return Result;
3173}
3174
Mike Stump11289f42009-09-09 15:08:12 +00003175template<typename Derived>
3176QualType
John McCall550e0c22009-10-21 00:40:46 +00003177TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003178 LValueReferenceTypeLoc TL) {
3179 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003180}
3181
Mike Stump11289f42009-09-09 15:08:12 +00003182template<typename Derived>
3183QualType
John McCall550e0c22009-10-21 00:40:46 +00003184TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003185 RValueReferenceTypeLoc TL) {
3186 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003187}
Mike Stump11289f42009-09-09 15:08:12 +00003188
Douglas Gregord6ff3322009-08-04 16:50:30 +00003189template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003190QualType
John McCall550e0c22009-10-21 00:40:46 +00003191TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003192 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003193 MemberPointerType *T = TL.getTypePtr();
3194
3195 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003196 if (PointeeType.isNull())
3197 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003198
John McCall550e0c22009-10-21 00:40:46 +00003199 // TODO: preserve source information for this.
3200 QualType ClassType
3201 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003202 if (ClassType.isNull())
3203 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003204
John McCall550e0c22009-10-21 00:40:46 +00003205 QualType Result = TL.getType();
3206 if (getDerived().AlwaysRebuild() ||
3207 PointeeType != T->getPointeeType() ||
3208 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003209 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3210 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003211 if (Result.isNull())
3212 return QualType();
3213 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003214
John McCall550e0c22009-10-21 00:40:46 +00003215 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3216 NewTL.setSigilLoc(TL.getSigilLoc());
3217
3218 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003219}
3220
Mike Stump11289f42009-09-09 15:08:12 +00003221template<typename Derived>
3222QualType
John McCall550e0c22009-10-21 00:40:46 +00003223TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003224 ConstantArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003225 ConstantArrayType *T = TL.getTypePtr();
3226 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003227 if (ElementType.isNull())
3228 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003229
John McCall550e0c22009-10-21 00:40:46 +00003230 QualType Result = TL.getType();
3231 if (getDerived().AlwaysRebuild() ||
3232 ElementType != T->getElementType()) {
3233 Result = getDerived().RebuildConstantArrayType(ElementType,
3234 T->getSizeModifier(),
3235 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003236 T->getIndexTypeCVRQualifiers(),
3237 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003238 if (Result.isNull())
3239 return QualType();
3240 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003241
John McCall550e0c22009-10-21 00:40:46 +00003242 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3243 NewTL.setLBracketLoc(TL.getLBracketLoc());
3244 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003245
John McCall550e0c22009-10-21 00:40:46 +00003246 Expr *Size = TL.getSizeExpr();
3247 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003248 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003249 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3250 }
3251 NewTL.setSizeExpr(Size);
3252
3253 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003254}
Mike Stump11289f42009-09-09 15:08:12 +00003255
Douglas Gregord6ff3322009-08-04 16:50:30 +00003256template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003257QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003258 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003259 IncompleteArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003260 IncompleteArrayType *T = TL.getTypePtr();
3261 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003262 if (ElementType.isNull())
3263 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003264
John McCall550e0c22009-10-21 00:40:46 +00003265 QualType Result = TL.getType();
3266 if (getDerived().AlwaysRebuild() ||
3267 ElementType != T->getElementType()) {
3268 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003269 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003270 T->getIndexTypeCVRQualifiers(),
3271 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003272 if (Result.isNull())
3273 return QualType();
3274 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003275
John McCall550e0c22009-10-21 00:40:46 +00003276 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3277 NewTL.setLBracketLoc(TL.getLBracketLoc());
3278 NewTL.setRBracketLoc(TL.getRBracketLoc());
3279 NewTL.setSizeExpr(0);
3280
3281 return Result;
3282}
3283
3284template<typename Derived>
3285QualType
3286TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003287 VariableArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003288 VariableArrayType *T = TL.getTypePtr();
3289 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3290 if (ElementType.isNull())
3291 return QualType();
3292
3293 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003294 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003295
John McCalldadc5752010-08-24 06:29:42 +00003296 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003297 = getDerived().TransformExpr(T->getSizeExpr());
3298 if (SizeResult.isInvalid())
3299 return QualType();
3300
John McCallb268a282010-08-23 23:25:46 +00003301 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003302
3303 QualType Result = TL.getType();
3304 if (getDerived().AlwaysRebuild() ||
3305 ElementType != T->getElementType() ||
3306 Size != T->getSizeExpr()) {
3307 Result = getDerived().RebuildVariableArrayType(ElementType,
3308 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003309 Size,
John McCall550e0c22009-10-21 00:40:46 +00003310 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003311 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003312 if (Result.isNull())
3313 return QualType();
3314 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003315
John McCall550e0c22009-10-21 00:40:46 +00003316 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3317 NewTL.setLBracketLoc(TL.getLBracketLoc());
3318 NewTL.setRBracketLoc(TL.getRBracketLoc());
3319 NewTL.setSizeExpr(Size);
3320
3321 return Result;
3322}
3323
3324template<typename Derived>
3325QualType
3326TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003327 DependentSizedArrayTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003328 DependentSizedArrayType *T = TL.getTypePtr();
3329 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3330 if (ElementType.isNull())
3331 return QualType();
3332
3333 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003334 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003335
John McCalldadc5752010-08-24 06:29:42 +00003336 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003337 = getDerived().TransformExpr(T->getSizeExpr());
3338 if (SizeResult.isInvalid())
3339 return QualType();
3340
3341 Expr *Size = static_cast<Expr*>(SizeResult.get());
3342
3343 QualType Result = TL.getType();
3344 if (getDerived().AlwaysRebuild() ||
3345 ElementType != T->getElementType() ||
3346 Size != T->getSizeExpr()) {
3347 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3348 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003349 Size,
John McCall550e0c22009-10-21 00:40:46 +00003350 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003351 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003352 if (Result.isNull())
3353 return QualType();
3354 }
3355 else SizeResult.take();
3356
3357 // We might have any sort of array type now, but fortunately they
3358 // all have the same location layout.
3359 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3360 NewTL.setLBracketLoc(TL.getLBracketLoc());
3361 NewTL.setRBracketLoc(TL.getRBracketLoc());
3362 NewTL.setSizeExpr(Size);
3363
3364 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003365}
Mike Stump11289f42009-09-09 15:08:12 +00003366
3367template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003368QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003369 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003370 DependentSizedExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003371 DependentSizedExtVectorType *T = TL.getTypePtr();
3372
3373 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003374 QualType ElementType = getDerived().TransformType(T->getElementType());
3375 if (ElementType.isNull())
3376 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003377
Douglas Gregore922c772009-08-04 22:27:00 +00003378 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003379 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003380
John McCalldadc5752010-08-24 06:29:42 +00003381 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003382 if (Size.isInvalid())
3383 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003384
John McCall550e0c22009-10-21 00:40:46 +00003385 QualType Result = TL.getType();
3386 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003387 ElementType != T->getElementType() ||
3388 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003389 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003390 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003391 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003392 if (Result.isNull())
3393 return QualType();
3394 }
John McCall550e0c22009-10-21 00:40:46 +00003395
3396 // Result might be dependent or not.
3397 if (isa<DependentSizedExtVectorType>(Result)) {
3398 DependentSizedExtVectorTypeLoc NewTL
3399 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3400 NewTL.setNameLoc(TL.getNameLoc());
3401 } else {
3402 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3403 NewTL.setNameLoc(TL.getNameLoc());
3404 }
3405
3406 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003407}
Mike Stump11289f42009-09-09 15:08:12 +00003408
3409template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003410QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003411 VectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003412 VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003413 QualType ElementType = getDerived().TransformType(T->getElementType());
3414 if (ElementType.isNull())
3415 return QualType();
3416
John McCall550e0c22009-10-21 00:40:46 +00003417 QualType Result = TL.getType();
3418 if (getDerived().AlwaysRebuild() ||
3419 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003420 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003421 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003422 if (Result.isNull())
3423 return QualType();
3424 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003425
John McCall550e0c22009-10-21 00:40:46 +00003426 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3427 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003428
John McCall550e0c22009-10-21 00:40:46 +00003429 return Result;
3430}
3431
3432template<typename Derived>
3433QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003434 ExtVectorTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003435 VectorType *T = TL.getTypePtr();
3436 QualType ElementType = getDerived().TransformType(T->getElementType());
3437 if (ElementType.isNull())
3438 return QualType();
3439
3440 QualType Result = TL.getType();
3441 if (getDerived().AlwaysRebuild() ||
3442 ElementType != T->getElementType()) {
3443 Result = getDerived().RebuildExtVectorType(ElementType,
3444 T->getNumElements(),
3445 /*FIXME*/ SourceLocation());
3446 if (Result.isNull())
3447 return QualType();
3448 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003449
John McCall550e0c22009-10-21 00:40:46 +00003450 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3451 NewTL.setNameLoc(TL.getNameLoc());
3452
3453 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003454}
Mike Stump11289f42009-09-09 15:08:12 +00003455
3456template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003457ParmVarDecl *
3458TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) {
3459 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
3460 TypeSourceInfo *NewDI = getDerived().TransformType(OldDI);
3461 if (!NewDI)
3462 return 0;
3463
3464 if (NewDI == OldDI)
3465 return OldParm;
3466 else
3467 return ParmVarDecl::Create(SemaRef.Context,
3468 OldParm->getDeclContext(),
3469 OldParm->getLocation(),
3470 OldParm->getIdentifier(),
3471 NewDI->getType(),
3472 NewDI,
3473 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003474 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003475 /* DefArg */ NULL);
3476}
3477
3478template<typename Derived>
3479bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003480 TransformFunctionTypeParams(SourceLocation Loc,
3481 ParmVarDecl **Params, unsigned NumParams,
3482 const QualType *ParamTypes,
3483 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3484 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3485 for (unsigned i = 0; i != NumParams; ++i) {
3486 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003487 if (OldParm->isParameterPack()) {
3488 // We have a function parameter pack that may need to be expanded.
3489 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003490
Douglas Gregor5499af42011-01-05 23:12:31 +00003491 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003492 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3493 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3494 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3495 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor5499af42011-01-05 23:12:31 +00003496
3497 // Determine whether we should expand the parameter packs.
3498 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003499 bool RetainExpansion = false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003500 unsigned NumExpansions = 0;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003501 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3502 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003503 Unexpanded.data(),
3504 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003505 ShouldExpand,
3506 RetainExpansion,
3507 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003508 return true;
3509 }
3510
3511 if (ShouldExpand) {
3512 // Expand the function parameter pack into multiple, separate
3513 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003514 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003515 for (unsigned I = 0; I != NumExpansions; ++I) {
3516 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3517 ParmVarDecl *NewParm
3518 = getDerived().TransformFunctionTypeParam(OldParm);
3519 if (!NewParm)
3520 return true;
3521
Douglas Gregordd472162011-01-07 00:20:55 +00003522 OutParamTypes.push_back(NewParm->getType());
3523 if (PVars)
3524 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003525 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003526
3527 // If we're supposed to retain a pack expansion, do so by temporarily
3528 // forgetting the partially-substituted parameter pack.
3529 if (RetainExpansion) {
3530 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3531 ParmVarDecl *NewParm
3532 = getDerived().TransformFunctionTypeParam(OldParm);
3533 if (!NewParm)
3534 return true;
3535
3536 OutParamTypes.push_back(NewParm->getType());
3537 if (PVars)
3538 PVars->push_back(NewParm);
3539 }
3540
Douglas Gregor5499af42011-01-05 23:12:31 +00003541 // We're done with the pack expansion.
3542 continue;
3543 }
3544
3545 // We'll substitute the parameter now without expanding the pack
3546 // expansion.
3547 }
3548
3549 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3550 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
John McCall58f10c32010-03-11 09:03:00 +00003551 if (!NewParm)
3552 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003553
Douglas Gregordd472162011-01-07 00:20:55 +00003554 OutParamTypes.push_back(NewParm->getType());
3555 if (PVars)
3556 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003557 continue;
3558 }
John McCall58f10c32010-03-11 09:03:00 +00003559
3560 // Deal with the possibility that we don't have a parameter
3561 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003562 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003563 bool IsPackExpansion = false;
3564 if (const PackExpansionType *Expansion
3565 = dyn_cast<PackExpansionType>(OldType)) {
3566 // We have a function parameter pack that may need to be expanded.
3567 QualType Pattern = Expansion->getPattern();
3568 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3569 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3570
3571 // Determine whether we should expand the parameter packs.
3572 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003573 bool RetainExpansion = false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003574 unsigned NumExpansions = 0;
Douglas Gregordd472162011-01-07 00:20:55 +00003575 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003576 Unexpanded.data(),
3577 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003578 ShouldExpand,
3579 RetainExpansion,
3580 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003581 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003582 }
3583
3584 if (ShouldExpand) {
3585 // Expand the function parameter pack into multiple, separate
3586 // parameters.
3587 for (unsigned I = 0; I != NumExpansions; ++I) {
3588 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3589 QualType NewType = getDerived().TransformType(Pattern);
3590 if (NewType.isNull())
3591 return true;
John McCall58f10c32010-03-11 09:03:00 +00003592
Douglas Gregordd472162011-01-07 00:20:55 +00003593 OutParamTypes.push_back(NewType);
3594 if (PVars)
3595 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003596 }
3597
3598 // We're done with the pack expansion.
3599 continue;
3600 }
3601
Douglas Gregor48d24112011-01-10 20:53:55 +00003602 // If we're supposed to retain a pack expansion, do so by temporarily
3603 // forgetting the partially-substituted parameter pack.
3604 if (RetainExpansion) {
3605 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3606 QualType NewType = getDerived().TransformType(Pattern);
3607 if (NewType.isNull())
3608 return true;
3609
3610 OutParamTypes.push_back(NewType);
3611 if (PVars)
3612 PVars->push_back(0);
3613 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003614
Douglas Gregor5499af42011-01-05 23:12:31 +00003615 // We'll substitute the parameter now without expanding the pack
3616 // expansion.
3617 OldType = Expansion->getPattern();
3618 IsPackExpansion = true;
3619 }
3620
3621 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3622 QualType NewType = getDerived().TransformType(OldType);
3623 if (NewType.isNull())
3624 return true;
3625
3626 if (IsPackExpansion)
3627 NewType = getSema().Context.getPackExpansionType(NewType);
3628
Douglas Gregordd472162011-01-07 00:20:55 +00003629 OutParamTypes.push_back(NewType);
3630 if (PVars)
3631 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003632 }
3633
3634 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003635 }
John McCall58f10c32010-03-11 09:03:00 +00003636
3637template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003638QualType
John McCall550e0c22009-10-21 00:40:46 +00003639TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003640 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003641 // Transform the parameters and return type.
3642 //
3643 // We instantiate in source order, with the return type first followed by
3644 // the parameters, because users tend to expect this (even if they shouldn't
3645 // rely on it!).
3646 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003647 // When the function has a trailing return type, we instantiate the
3648 // parameters before the return type, since the return type can then refer
3649 // to the parameters themselves (via decltype, sizeof, etc.).
3650 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003651 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003652 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
Douglas Gregor14cf7522010-04-30 18:55:50 +00003653 FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003654
Douglas Gregor7fb25412010-10-01 18:44:50 +00003655 QualType ResultType;
3656
3657 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003658 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3659 TL.getParmArray(),
3660 TL.getNumArgs(),
3661 TL.getTypePtr()->arg_type_begin(),
3662 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003663 return QualType();
3664
3665 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3666 if (ResultType.isNull())
3667 return QualType();
3668 }
3669 else {
3670 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3671 if (ResultType.isNull())
3672 return QualType();
3673
Douglas Gregordd472162011-01-07 00:20:55 +00003674 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3675 TL.getParmArray(),
3676 TL.getNumArgs(),
3677 TL.getTypePtr()->arg_type_begin(),
3678 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003679 return QualType();
3680 }
3681
John McCall550e0c22009-10-21 00:40:46 +00003682 QualType Result = TL.getType();
3683 if (getDerived().AlwaysRebuild() ||
3684 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003685 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003686 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3687 Result = getDerived().RebuildFunctionProtoType(ResultType,
3688 ParamTypes.data(),
3689 ParamTypes.size(),
3690 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003691 T->getTypeQuals(),
3692 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003693 if (Result.isNull())
3694 return QualType();
3695 }
Mike Stump11289f42009-09-09 15:08:12 +00003696
John McCall550e0c22009-10-21 00:40:46 +00003697 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3698 NewTL.setLParenLoc(TL.getLParenLoc());
3699 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003700 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003701 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3702 NewTL.setArg(i, ParamDecls[i]);
3703
3704 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003705}
Mike Stump11289f42009-09-09 15:08:12 +00003706
Douglas Gregord6ff3322009-08-04 16:50:30 +00003707template<typename Derived>
3708QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003709 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003710 FunctionNoProtoTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003711 FunctionNoProtoType *T = TL.getTypePtr();
3712 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3713 if (ResultType.isNull())
3714 return QualType();
3715
3716 QualType Result = TL.getType();
3717 if (getDerived().AlwaysRebuild() ||
3718 ResultType != T->getResultType())
3719 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
3720
3721 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
3722 NewTL.setLParenLoc(TL.getLParenLoc());
3723 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003724 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00003725
3726 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003727}
Mike Stump11289f42009-09-09 15:08:12 +00003728
John McCallb96ec562009-12-04 22:46:56 +00003729template<typename Derived> QualType
3730TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003731 UnresolvedUsingTypeLoc TL) {
John McCallb96ec562009-12-04 22:46:56 +00003732 UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003733 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00003734 if (!D)
3735 return QualType();
3736
3737 QualType Result = TL.getType();
3738 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
3739 Result = getDerived().RebuildUnresolvedUsingType(D);
3740 if (Result.isNull())
3741 return QualType();
3742 }
3743
3744 // We might get an arbitrary type spec type back. We should at
3745 // least always get a type spec type, though.
3746 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
3747 NewTL.setNameLoc(TL.getNameLoc());
3748
3749 return Result;
3750}
3751
Douglas Gregord6ff3322009-08-04 16:50:30 +00003752template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003753QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003754 TypedefTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003755 TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003756 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003757 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3758 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003759 if (!Typedef)
3760 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003761
John McCall550e0c22009-10-21 00:40:46 +00003762 QualType Result = TL.getType();
3763 if (getDerived().AlwaysRebuild() ||
3764 Typedef != T->getDecl()) {
3765 Result = getDerived().RebuildTypedefType(Typedef);
3766 if (Result.isNull())
3767 return QualType();
3768 }
Mike Stump11289f42009-09-09 15:08:12 +00003769
John McCall550e0c22009-10-21 00:40:46 +00003770 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
3771 NewTL.setNameLoc(TL.getNameLoc());
3772
3773 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003774}
Mike Stump11289f42009-09-09 15:08:12 +00003775
Douglas Gregord6ff3322009-08-04 16:50:30 +00003776template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003777QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003778 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00003779 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003780 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003781
John McCalldadc5752010-08-24 06:29:42 +00003782 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003783 if (E.isInvalid())
3784 return QualType();
3785
John McCall550e0c22009-10-21 00:40:46 +00003786 QualType Result = TL.getType();
3787 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00003788 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003789 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00003790 if (Result.isNull())
3791 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003792 }
John McCall550e0c22009-10-21 00:40:46 +00003793 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003794
John McCall550e0c22009-10-21 00:40:46 +00003795 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003796 NewTL.setTypeofLoc(TL.getTypeofLoc());
3797 NewTL.setLParenLoc(TL.getLParenLoc());
3798 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00003799
3800 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003801}
Mike Stump11289f42009-09-09 15:08:12 +00003802
3803template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003804QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003805 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00003806 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
3807 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
3808 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00003809 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003810
John McCall550e0c22009-10-21 00:40:46 +00003811 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00003812 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
3813 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00003814 if (Result.isNull())
3815 return QualType();
3816 }
Mike Stump11289f42009-09-09 15:08:12 +00003817
John McCall550e0c22009-10-21 00:40:46 +00003818 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00003819 NewTL.setTypeofLoc(TL.getTypeofLoc());
3820 NewTL.setLParenLoc(TL.getLParenLoc());
3821 NewTL.setRParenLoc(TL.getRParenLoc());
3822 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00003823
3824 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003825}
Mike Stump11289f42009-09-09 15:08:12 +00003826
3827template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003828QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003829 DecltypeTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003830 DecltypeType *T = TL.getTypePtr();
3831
Douglas Gregore922c772009-08-04 22:27:00 +00003832 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003833 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003834
John McCalldadc5752010-08-24 06:29:42 +00003835 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003836 if (E.isInvalid())
3837 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003838
John McCall550e0c22009-10-21 00:40:46 +00003839 QualType Result = TL.getType();
3840 if (getDerived().AlwaysRebuild() ||
3841 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00003842 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00003843 if (Result.isNull())
3844 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003845 }
John McCall550e0c22009-10-21 00:40:46 +00003846 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00003847
John McCall550e0c22009-10-21 00:40:46 +00003848 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
3849 NewTL.setNameLoc(TL.getNameLoc());
3850
3851 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003852}
3853
3854template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003855QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003856 RecordTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003857 RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003858 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003859 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3860 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003861 if (!Record)
3862 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003863
John McCall550e0c22009-10-21 00:40:46 +00003864 QualType Result = TL.getType();
3865 if (getDerived().AlwaysRebuild() ||
3866 Record != T->getDecl()) {
3867 Result = getDerived().RebuildRecordType(Record);
3868 if (Result.isNull())
3869 return QualType();
3870 }
Mike Stump11289f42009-09-09 15:08:12 +00003871
John McCall550e0c22009-10-21 00:40:46 +00003872 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
3873 NewTL.setNameLoc(TL.getNameLoc());
3874
3875 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003876}
Mike Stump11289f42009-09-09 15:08:12 +00003877
3878template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003879QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003880 EnumTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003881 EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003882 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00003883 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
3884 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003885 if (!Enum)
3886 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003887
John McCall550e0c22009-10-21 00:40:46 +00003888 QualType Result = TL.getType();
3889 if (getDerived().AlwaysRebuild() ||
3890 Enum != T->getDecl()) {
3891 Result = getDerived().RebuildEnumType(Enum);
3892 if (Result.isNull())
3893 return QualType();
3894 }
Mike Stump11289f42009-09-09 15:08:12 +00003895
John McCall550e0c22009-10-21 00:40:46 +00003896 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
3897 NewTL.setNameLoc(TL.getNameLoc());
3898
3899 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003900}
John McCallfcc33b02009-09-05 00:15:47 +00003901
John McCalle78aac42010-03-10 03:28:59 +00003902template<typename Derived>
3903QualType TreeTransform<Derived>::TransformInjectedClassNameType(
3904 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003905 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00003906 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
3907 TL.getTypePtr()->getDecl());
3908 if (!D) return QualType();
3909
3910 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
3911 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
3912 return T;
3913}
3914
Douglas Gregord6ff3322009-08-04 16:50:30 +00003915template<typename Derived>
3916QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003917 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003918 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003919 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003920}
3921
Mike Stump11289f42009-09-09 15:08:12 +00003922template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00003923QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00003924 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003925 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003926 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00003927}
3928
3929template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003930QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00003931 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003932 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00003933 const TemplateSpecializationType *T = TL.getTypePtr();
3934
Mike Stump11289f42009-09-09 15:08:12 +00003935 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00003936 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003937 if (Template.isNull())
3938 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003939
John McCall31f82722010-11-12 08:19:04 +00003940 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
3941}
3942
Douglas Gregorfe921a72010-12-20 23:36:19 +00003943namespace {
3944 /// \brief Simple iterator that traverses the template arguments in a
3945 /// container that provides a \c getArgLoc() member function.
3946 ///
3947 /// This iterator is intended to be used with the iterator form of
3948 /// \c TreeTransform<Derived>::TransformTemplateArguments().
3949 template<typename ArgLocContainer>
3950 class TemplateArgumentLocContainerIterator {
3951 ArgLocContainer *Container;
3952 unsigned Index;
3953
3954 public:
3955 typedef TemplateArgumentLoc value_type;
3956 typedef TemplateArgumentLoc reference;
3957 typedef int difference_type;
3958 typedef std::input_iterator_tag iterator_category;
3959
3960 class pointer {
3961 TemplateArgumentLoc Arg;
3962
3963 public:
3964 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
3965
3966 const TemplateArgumentLoc *operator->() const {
3967 return &Arg;
3968 }
3969 };
3970
3971
3972 TemplateArgumentLocContainerIterator() {}
3973
3974 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
3975 unsigned Index)
3976 : Container(&Container), Index(Index) { }
3977
3978 TemplateArgumentLocContainerIterator &operator++() {
3979 ++Index;
3980 return *this;
3981 }
3982
3983 TemplateArgumentLocContainerIterator operator++(int) {
3984 TemplateArgumentLocContainerIterator Old(*this);
3985 ++(*this);
3986 return Old;
3987 }
3988
3989 TemplateArgumentLoc operator*() const {
3990 return Container->getArgLoc(Index);
3991 }
3992
3993 pointer operator->() const {
3994 return pointer(Container->getArgLoc(Index));
3995 }
3996
3997 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00003998 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003999 return X.Container == Y.Container && X.Index == Y.Index;
4000 }
4001
4002 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004003 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004004 return !(X == Y);
4005 }
4006 };
4007}
4008
4009
John McCall31f82722010-11-12 08:19:04 +00004010template <typename Derived>
4011QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4012 TypeLocBuilder &TLB,
4013 TemplateSpecializationTypeLoc TL,
4014 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004015 TemplateArgumentListInfo NewTemplateArgs;
4016 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4017 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004018 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4019 ArgIterator;
4020 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4021 ArgIterator(TL, TL.getNumArgs()),
4022 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004023 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004024
John McCall0ad16662009-10-29 08:12:44 +00004025 // FIXME: maybe don't rebuild if all the template arguments are the same.
4026
4027 QualType Result =
4028 getDerived().RebuildTemplateSpecializationType(Template,
4029 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004030 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004031
4032 if (!Result.isNull()) {
4033 TemplateSpecializationTypeLoc NewTL
4034 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4035 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4036 NewTL.setLAngleLoc(TL.getLAngleLoc());
4037 NewTL.setRAngleLoc(TL.getRAngleLoc());
4038 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4039 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004040 }
Mike Stump11289f42009-09-09 15:08:12 +00004041
John McCall0ad16662009-10-29 08:12:44 +00004042 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004043}
Mike Stump11289f42009-09-09 15:08:12 +00004044
4045template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004046QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004047TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004048 ElaboratedTypeLoc TL) {
Abramo Bagnara6150c882010-05-11 21:36:43 +00004049 ElaboratedType *T = TL.getTypePtr();
4050
4051 NestedNameSpecifier *NNS = 0;
4052 // NOTE: the qualifier in an ElaboratedType is optional.
4053 if (T->getQualifier() != 0) {
4054 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004055 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00004056 if (!NNS)
4057 return QualType();
4058 }
Mike Stump11289f42009-09-09 15:08:12 +00004059
John McCall31f82722010-11-12 08:19:04 +00004060 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4061 if (NamedT.isNull())
4062 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004063
John McCall550e0c22009-10-21 00:40:46 +00004064 QualType Result = TL.getType();
4065 if (getDerived().AlwaysRebuild() ||
4066 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004067 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004068 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4069 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004070 if (Result.isNull())
4071 return QualType();
4072 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004073
Abramo Bagnara6150c882010-05-11 21:36:43 +00004074 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004075 NewTL.setKeywordLoc(TL.getKeywordLoc());
4076 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00004077
4078 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004079}
Mike Stump11289f42009-09-09 15:08:12 +00004080
4081template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004082QualType TreeTransform<Derived>::TransformAttributedType(
4083 TypeLocBuilder &TLB,
4084 AttributedTypeLoc TL) {
4085 const AttributedType *oldType = TL.getTypePtr();
4086 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4087 if (modifiedType.isNull())
4088 return QualType();
4089
4090 QualType result = TL.getType();
4091
4092 // FIXME: dependent operand expressions?
4093 if (getDerived().AlwaysRebuild() ||
4094 modifiedType != oldType->getModifiedType()) {
4095 // TODO: this is really lame; we should really be rebuilding the
4096 // equivalent type from first principles.
4097 QualType equivalentType
4098 = getDerived().TransformType(oldType->getEquivalentType());
4099 if (equivalentType.isNull())
4100 return QualType();
4101 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4102 modifiedType,
4103 equivalentType);
4104 }
4105
4106 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4107 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4108 if (TL.hasAttrOperand())
4109 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4110 if (TL.hasAttrExprOperand())
4111 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4112 else if (TL.hasAttrEnumOperand())
4113 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4114
4115 return result;
4116}
4117
4118template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004119QualType
4120TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4121 ParenTypeLoc TL) {
4122 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4123 if (Inner.isNull())
4124 return QualType();
4125
4126 QualType Result = TL.getType();
4127 if (getDerived().AlwaysRebuild() ||
4128 Inner != TL.getInnerLoc().getType()) {
4129 Result = getDerived().RebuildParenType(Inner);
4130 if (Result.isNull())
4131 return QualType();
4132 }
4133
4134 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4135 NewTL.setLParenLoc(TL.getLParenLoc());
4136 NewTL.setRParenLoc(TL.getRParenLoc());
4137 return Result;
4138}
4139
4140template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004141QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004142 DependentNameTypeLoc TL) {
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004143 DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004144
Douglas Gregord6ff3322009-08-04 16:50:30 +00004145 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00004146 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004147 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004148 if (!NNS)
4149 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004150
John McCallc392f372010-06-11 00:33:02 +00004151 QualType Result
4152 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4153 T->getIdentifier(),
4154 TL.getKeywordLoc(),
4155 TL.getQualifierRange(),
4156 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004157 if (Result.isNull())
4158 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004159
Abramo Bagnarad7548482010-05-19 21:37:53 +00004160 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4161 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004162 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4163
Abramo Bagnarad7548482010-05-19 21:37:53 +00004164 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4165 NewTL.setKeywordLoc(TL.getKeywordLoc());
4166 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004167 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004168 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4169 NewTL.setKeywordLoc(TL.getKeywordLoc());
4170 NewTL.setQualifierRange(TL.getQualifierRange());
4171 NewTL.setNameLoc(TL.getNameLoc());
4172 }
John McCall550e0c22009-10-21 00:40:46 +00004173 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004174}
Mike Stump11289f42009-09-09 15:08:12 +00004175
Douglas Gregord6ff3322009-08-04 16:50:30 +00004176template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004177QualType TreeTransform<Derived>::
4178 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004179 DependentTemplateSpecializationTypeLoc TL) {
John McCallc392f372010-06-11 00:33:02 +00004180 DependentTemplateSpecializationType *T = TL.getTypePtr();
4181
4182 NestedNameSpecifier *NNS
4183 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004184 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004185 if (!NNS)
4186 return QualType();
4187
John McCall31f82722010-11-12 08:19:04 +00004188 return getDerived()
4189 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4190}
4191
4192template<typename Derived>
4193QualType TreeTransform<Derived>::
4194 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4195 DependentTemplateSpecializationTypeLoc TL,
4196 NestedNameSpecifier *NNS) {
4197 DependentTemplateSpecializationType *T = TL.getTypePtr();
4198
John McCallc392f372010-06-11 00:33:02 +00004199 TemplateArgumentListInfo NewTemplateArgs;
4200 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4201 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004202
4203 typedef TemplateArgumentLocContainerIterator<
4204 DependentTemplateSpecializationTypeLoc> ArgIterator;
4205 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4206 ArgIterator(TL, TL.getNumArgs()),
4207 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004208 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004209
Douglas Gregora5614c52010-09-08 23:56:00 +00004210 QualType Result
4211 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4212 NNS,
4213 TL.getQualifierRange(),
4214 T->getIdentifier(),
4215 TL.getNameLoc(),
4216 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004217 if (Result.isNull())
4218 return QualType();
4219
4220 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4221 QualType NamedT = ElabT->getNamedType();
4222
4223 // Copy information relevant to the template specialization.
4224 TemplateSpecializationTypeLoc NamedTL
4225 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4226 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4227 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4228 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4229 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4230
4231 // Copy information relevant to the elaborated type.
4232 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4233 NewTL.setKeywordLoc(TL.getKeywordLoc());
4234 NewTL.setQualifierRange(TL.getQualifierRange());
4235 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004236 TypeLoc NewTL(Result, TL.getOpaqueData());
4237 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004238 }
4239 return Result;
4240}
4241
4242template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004243QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4244 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004245 QualType Pattern
4246 = getDerived().TransformType(TLB, TL.getPatternLoc());
4247 if (Pattern.isNull())
4248 return QualType();
4249
4250 QualType Result = TL.getType();
4251 if (getDerived().AlwaysRebuild() ||
4252 Pattern != TL.getPatternLoc().getType()) {
4253 Result = getDerived().RebuildPackExpansionType(Pattern,
4254 TL.getPatternLoc().getSourceRange(),
4255 TL.getEllipsisLoc());
4256 if (Result.isNull())
4257 return QualType();
4258 }
4259
4260 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4261 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4262 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004263}
4264
4265template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004266QualType
4267TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004268 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004269 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004270 TLB.pushFullCopy(TL);
4271 return TL.getType();
4272}
4273
4274template<typename Derived>
4275QualType
4276TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004277 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004278 // ObjCObjectType is never dependent.
4279 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004280 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004281}
Mike Stump11289f42009-09-09 15:08:12 +00004282
4283template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004284QualType
4285TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004286 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004287 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004288 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004289 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004290}
4291
Douglas Gregord6ff3322009-08-04 16:50:30 +00004292//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004293// Statement transformation
4294//===----------------------------------------------------------------------===//
4295template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004296StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004297TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004298 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004299}
4300
4301template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004302StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004303TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4304 return getDerived().TransformCompoundStmt(S, false);
4305}
4306
4307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004308StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004309TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004310 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004311 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004312 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004313 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004314 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4315 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004316 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004317 if (Result.isInvalid()) {
4318 // Immediately fail if this was a DeclStmt, since it's very
4319 // likely that this will cause problems for future statements.
4320 if (isa<DeclStmt>(*B))
4321 return StmtError();
4322
4323 // Otherwise, just keep processing substatements and fail later.
4324 SubStmtInvalid = true;
4325 continue;
4326 }
Mike Stump11289f42009-09-09 15:08:12 +00004327
Douglas Gregorebe10102009-08-20 07:17:43 +00004328 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4329 Statements.push_back(Result.takeAs<Stmt>());
4330 }
Mike Stump11289f42009-09-09 15:08:12 +00004331
John McCall1ababa62010-08-27 19:56:05 +00004332 if (SubStmtInvalid)
4333 return StmtError();
4334
Douglas Gregorebe10102009-08-20 07:17:43 +00004335 if (!getDerived().AlwaysRebuild() &&
4336 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004337 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004338
4339 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4340 move_arg(Statements),
4341 S->getRBracLoc(),
4342 IsStmtExpr);
4343}
Mike Stump11289f42009-09-09 15:08:12 +00004344
Douglas Gregorebe10102009-08-20 07:17:43 +00004345template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004346StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004347TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004348 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004349 {
4350 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004351 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004352
Eli Friedman06577382009-11-19 03:14:00 +00004353 // Transform the left-hand case value.
4354 LHS = getDerived().TransformExpr(S->getLHS());
4355 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004356 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004357
Eli Friedman06577382009-11-19 03:14:00 +00004358 // Transform the right-hand case value (for the GNU case-range extension).
4359 RHS = getDerived().TransformExpr(S->getRHS());
4360 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004361 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004362 }
Mike Stump11289f42009-09-09 15:08:12 +00004363
Douglas Gregorebe10102009-08-20 07:17:43 +00004364 // Build the case statement.
4365 // Case statements are always rebuilt so that they will attached to their
4366 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004367 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004368 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004369 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004370 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004371 S->getColonLoc());
4372 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004373 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004374
Douglas Gregorebe10102009-08-20 07:17:43 +00004375 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004376 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004377 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004378 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004379
Douglas Gregorebe10102009-08-20 07:17:43 +00004380 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004381 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004382}
4383
4384template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004385StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004386TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004387 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004388 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004389 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004390 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004391
Douglas Gregorebe10102009-08-20 07:17:43 +00004392 // Default statements are always rebuilt
4393 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004394 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004395}
Mike Stump11289f42009-09-09 15:08:12 +00004396
Douglas Gregorebe10102009-08-20 07:17:43 +00004397template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004398StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004399TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004400 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004401 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004402 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004403
Douglas Gregorebe10102009-08-20 07:17:43 +00004404 // FIXME: Pass the real colon location in.
4405 SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc());
4406 return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc,
Argyrios Kyrtzidis9f483542010-09-28 14:54:07 +00004407 SubStmt.get(), S->HasUnusedAttribute());
Douglas Gregorebe10102009-08-20 07:17:43 +00004408}
Mike Stump11289f42009-09-09 15:08:12 +00004409
Douglas Gregorebe10102009-08-20 07:17:43 +00004410template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004411StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004412TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004413 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004414 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004415 VarDecl *ConditionVar = 0;
4416 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004417 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004418 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004419 getDerived().TransformDefinition(
4420 S->getConditionVariable()->getLocation(),
4421 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004422 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004423 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004424 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004425 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004426
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004427 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004428 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004429
4430 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004431 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004432 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4433 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004434 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004435 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004436
John McCallb268a282010-08-23 23:25:46 +00004437 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004438 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004439 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004440
John McCallb268a282010-08-23 23:25:46 +00004441 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4442 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004443 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004444
Douglas Gregorebe10102009-08-20 07:17:43 +00004445 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004446 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004447 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004448 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004449
Douglas Gregorebe10102009-08-20 07:17:43 +00004450 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004451 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004452 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004453 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004454
Douglas Gregorebe10102009-08-20 07:17:43 +00004455 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004456 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004457 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004458 Then.get() == S->getThen() &&
4459 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004460 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004461
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004462 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004463 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004464 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004465}
4466
4467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004468StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004469TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004470 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004471 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004472 VarDecl *ConditionVar = 0;
4473 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004474 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004475 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004476 getDerived().TransformDefinition(
4477 S->getConditionVariable()->getLocation(),
4478 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004479 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004480 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004481 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004482 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004483
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004484 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004485 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004486 }
Mike Stump11289f42009-09-09 15:08:12 +00004487
Douglas Gregorebe10102009-08-20 07:17:43 +00004488 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004489 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004490 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004491 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004492 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004493 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004494
Douglas Gregorebe10102009-08-20 07:17:43 +00004495 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004496 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004497 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004498 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004499
Douglas Gregorebe10102009-08-20 07:17:43 +00004500 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004501 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4502 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004503}
Mike Stump11289f42009-09-09 15:08:12 +00004504
Douglas Gregorebe10102009-08-20 07:17:43 +00004505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004506StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004507TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004508 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004509 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004510 VarDecl *ConditionVar = 0;
4511 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004512 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004513 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004514 getDerived().TransformDefinition(
4515 S->getConditionVariable()->getLocation(),
4516 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004517 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004518 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004519 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004520 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004521
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004522 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004523 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004524
4525 if (S->getCond()) {
4526 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004527 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4528 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004529 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004530 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004531 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004532 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004533 }
Mike Stump11289f42009-09-09 15:08:12 +00004534
John McCallb268a282010-08-23 23:25:46 +00004535 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4536 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004537 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004538
Douglas Gregorebe10102009-08-20 07:17:43 +00004539 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004540 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004541 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004542 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004543
Douglas Gregorebe10102009-08-20 07:17:43 +00004544 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004545 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004546 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004547 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004548 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004549
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004550 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004551 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004552}
Mike Stump11289f42009-09-09 15:08:12 +00004553
Douglas Gregorebe10102009-08-20 07:17:43 +00004554template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004555StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004556TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004557 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004558 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004559 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004560 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004561
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004562 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004563 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004564 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004565 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004566
Douglas Gregorebe10102009-08-20 07:17:43 +00004567 if (!getDerived().AlwaysRebuild() &&
4568 Cond.get() == S->getCond() &&
4569 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004570 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004571
John McCallb268a282010-08-23 23:25:46 +00004572 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4573 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004574 S->getRParenLoc());
4575}
Mike Stump11289f42009-09-09 15:08:12 +00004576
Douglas Gregorebe10102009-08-20 07:17:43 +00004577template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004578StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004579TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004580 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004581 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004582 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004583 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004584
Douglas Gregorebe10102009-08-20 07:17:43 +00004585 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004586 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004587 VarDecl *ConditionVar = 0;
4588 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004589 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004590 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004591 getDerived().TransformDefinition(
4592 S->getConditionVariable()->getLocation(),
4593 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004594 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004595 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004596 } else {
4597 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004598
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004599 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004600 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004601
4602 if (S->getCond()) {
4603 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004604 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4605 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004606 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004607 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004608
John McCallb268a282010-08-23 23:25:46 +00004609 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004610 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004611 }
Mike Stump11289f42009-09-09 15:08:12 +00004612
John McCallb268a282010-08-23 23:25:46 +00004613 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4614 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004615 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004616
Douglas Gregorebe10102009-08-20 07:17:43 +00004617 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004618 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004619 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004620 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004621
John McCallb268a282010-08-23 23:25:46 +00004622 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4623 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004624 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004625
Douglas Gregorebe10102009-08-20 07:17:43 +00004626 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004627 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004628 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004629 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004630
Douglas Gregorebe10102009-08-20 07:17:43 +00004631 if (!getDerived().AlwaysRebuild() &&
4632 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004633 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004634 Inc.get() == S->getInc() &&
4635 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004636 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004637
Douglas Gregorebe10102009-08-20 07:17:43 +00004638 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004639 Init.get(), FullCond, ConditionVar,
4640 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004641}
4642
4643template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004644StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004645TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004646 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004647 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004648 S->getLabel());
4649}
4650
4651template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004652StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004653TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004654 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004655 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004656 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004657
Douglas Gregorebe10102009-08-20 07:17:43 +00004658 if (!getDerived().AlwaysRebuild() &&
4659 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004660 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004661
4662 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004663 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004664}
4665
4666template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004667StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004668TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004669 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004670}
Mike Stump11289f42009-09-09 15:08:12 +00004671
Douglas Gregorebe10102009-08-20 07:17:43 +00004672template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004673StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004674TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004675 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004676}
Mike Stump11289f42009-09-09 15:08:12 +00004677
Douglas Gregorebe10102009-08-20 07:17:43 +00004678template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004679StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004680TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004681 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00004682 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004683 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004684
Mike Stump11289f42009-09-09 15:08:12 +00004685 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00004686 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00004687 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004688}
Mike Stump11289f42009-09-09 15:08:12 +00004689
Douglas Gregorebe10102009-08-20 07:17:43 +00004690template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004691StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004692TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004693 bool DeclChanged = false;
4694 llvm::SmallVector<Decl *, 4> Decls;
4695 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
4696 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00004697 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
4698 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00004699 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00004700 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004701
Douglas Gregorebe10102009-08-20 07:17:43 +00004702 if (Transformed != *D)
4703 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00004704
Douglas Gregorebe10102009-08-20 07:17:43 +00004705 Decls.push_back(Transformed);
4706 }
Mike Stump11289f42009-09-09 15:08:12 +00004707
Douglas Gregorebe10102009-08-20 07:17:43 +00004708 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00004709 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004710
4711 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004712 S->getStartLoc(), S->getEndLoc());
4713}
Mike Stump11289f42009-09-09 15:08:12 +00004714
Douglas Gregorebe10102009-08-20 07:17:43 +00004715template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004716StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004717TreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004718 assert(false && "SwitchCase is abstract and cannot be transformed");
John McCallc3007a22010-10-26 07:05:15 +00004719 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004720}
4721
4722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004723StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004724TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004725
John McCall37ad5512010-08-23 06:44:23 +00004726 ASTOwningVector<Expr*> Constraints(getSema());
4727 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00004728 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00004729
John McCalldadc5752010-08-24 06:29:42 +00004730 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00004731 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004732
4733 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004734
Anders Carlssonaaeef072010-01-24 05:50:09 +00004735 // Go through the outputs.
4736 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004737 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004738
Anders Carlssonaaeef072010-01-24 05:50:09 +00004739 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004740 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004741
Anders Carlssonaaeef072010-01-24 05:50:09 +00004742 // Transform the output expr.
4743 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004744 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004745 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004746 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004747
Anders Carlssonaaeef072010-01-24 05:50:09 +00004748 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004749
John McCallb268a282010-08-23 23:25:46 +00004750 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004751 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004752
Anders Carlssonaaeef072010-01-24 05:50:09 +00004753 // Go through the inputs.
4754 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00004755 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004756
Anders Carlssonaaeef072010-01-24 05:50:09 +00004757 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00004758 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00004759
Anders Carlssonaaeef072010-01-24 05:50:09 +00004760 // Transform the input expr.
4761 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00004762 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004763 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004764 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004765
Anders Carlssonaaeef072010-01-24 05:50:09 +00004766 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00004767
John McCallb268a282010-08-23 23:25:46 +00004768 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00004769 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004770
Anders Carlssonaaeef072010-01-24 05:50:09 +00004771 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00004772 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00004773
4774 // Go through the clobbers.
4775 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00004776 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00004777
4778 // No need to transform the asm string literal.
4779 AsmString = SemaRef.Owned(S->getAsmString());
4780
4781 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
4782 S->isSimple(),
4783 S->isVolatile(),
4784 S->getNumOutputs(),
4785 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00004786 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004787 move_arg(Constraints),
4788 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00004789 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00004790 move_arg(Clobbers),
4791 S->getRParenLoc(),
4792 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00004793}
4794
4795
4796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004797StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004798TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004799 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00004800 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004801 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004802 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004803
Douglas Gregor96c79492010-04-23 22:50:49 +00004804 // Transform the @catch statements (if present).
4805 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004806 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00004807 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00004808 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00004809 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004810 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00004811 if (Catch.get() != S->getCatchStmt(I))
4812 AnyCatchChanged = true;
4813 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004814 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004815
Douglas Gregor306de2f2010-04-22 23:59:56 +00004816 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00004817 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00004818 if (S->getFinallyStmt()) {
4819 Finally = getDerived().TransformStmt(S->getFinallyStmt());
4820 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004821 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00004822 }
4823
4824 // If nothing changed, just retain this statement.
4825 if (!getDerived().AlwaysRebuild() &&
4826 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00004827 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00004828 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00004829 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004830
Douglas Gregor306de2f2010-04-22 23:59:56 +00004831 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00004832 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
4833 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004834}
Mike Stump11289f42009-09-09 15:08:12 +00004835
Douglas Gregorebe10102009-08-20 07:17:43 +00004836template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004837StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004838TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004839 // Transform the @catch parameter, if there is one.
4840 VarDecl *Var = 0;
4841 if (VarDecl *FromVar = S->getCatchParamDecl()) {
4842 TypeSourceInfo *TSInfo = 0;
4843 if (FromVar->getTypeSourceInfo()) {
4844 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
4845 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00004846 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004847 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004848
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004849 QualType T;
4850 if (TSInfo)
4851 T = TSInfo->getType();
4852 else {
4853 T = getDerived().TransformType(FromVar->getType());
4854 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00004855 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004856 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004857
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004858 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
4859 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00004860 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004861 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004862
John McCalldadc5752010-08-24 06:29:42 +00004863 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004864 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004865 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004866
4867 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00004868 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004869 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004870}
Mike Stump11289f42009-09-09 15:08:12 +00004871
Douglas Gregorebe10102009-08-20 07:17:43 +00004872template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004873StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004874TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00004875 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004876 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00004877 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004878 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004879
Douglas Gregor306de2f2010-04-22 23:59:56 +00004880 // If nothing changed, just retain this statement.
4881 if (!getDerived().AlwaysRebuild() &&
4882 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00004883 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00004884
4885 // Build a new statement.
4886 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00004887 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004888}
Mike Stump11289f42009-09-09 15:08:12 +00004889
Douglas Gregorebe10102009-08-20 07:17:43 +00004890template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004891StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004892TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004893 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00004894 if (S->getThrowExpr()) {
4895 Operand = getDerived().TransformExpr(S->getThrowExpr());
4896 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004897 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00004898 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004899
Douglas Gregor2900c162010-04-22 21:44:01 +00004900 if (!getDerived().AlwaysRebuild() &&
4901 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00004902 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004903
John McCallb268a282010-08-23 23:25:46 +00004904 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004905}
Mike Stump11289f42009-09-09 15:08:12 +00004906
Douglas Gregorebe10102009-08-20 07:17:43 +00004907template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004908StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004909TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004910 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00004911 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00004912 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00004913 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004914 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004915
Douglas Gregor6148de72010-04-22 22:01:21 +00004916 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004917 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00004918 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004919 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004920
Douglas Gregor6148de72010-04-22 22:01:21 +00004921 // If nothing change, just retain the current statement.
4922 if (!getDerived().AlwaysRebuild() &&
4923 Object.get() == S->getSynchExpr() &&
4924 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00004925 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00004926
4927 // Build a new statement.
4928 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00004929 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004930}
4931
4932template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004933StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004934TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00004935 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00004936 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00004937 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004938 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004939 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004940
Douglas Gregorf68a5082010-04-22 23:10:45 +00004941 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00004942 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004943 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004944 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004945
Douglas Gregorf68a5082010-04-22 23:10:45 +00004946 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00004947 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00004948 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004949 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00004950
Douglas Gregorf68a5082010-04-22 23:10:45 +00004951 // If nothing changed, just retain this statement.
4952 if (!getDerived().AlwaysRebuild() &&
4953 Element.get() == S->getElement() &&
4954 Collection.get() == S->getCollection() &&
4955 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004956 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00004957
Douglas Gregorf68a5082010-04-22 23:10:45 +00004958 // Build a new statement.
4959 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
4960 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00004961 Element.get(),
4962 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00004963 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004964 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004965}
4966
4967
4968template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004969StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004970TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
4971 // Transform the exception declaration, if any.
4972 VarDecl *Var = 0;
4973 if (S->getExceptionDecl()) {
4974 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004975 TypeSourceInfo *T = getDerived().TransformType(
4976 ExceptionDecl->getTypeSourceInfo());
4977 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00004978 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004979
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004980 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00004981 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00004982 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00004983 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00004984 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00004985 }
Mike Stump11289f42009-09-09 15:08:12 +00004986
Douglas Gregorebe10102009-08-20 07:17:43 +00004987 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00004988 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00004989 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004990 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004991
Douglas Gregorebe10102009-08-20 07:17:43 +00004992 if (!getDerived().AlwaysRebuild() &&
4993 !Var &&
4994 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00004995 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004996
4997 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
4998 Var,
John McCallb268a282010-08-23 23:25:46 +00004999 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005000}
Mike Stump11289f42009-09-09 15:08:12 +00005001
Douglas Gregorebe10102009-08-20 07:17:43 +00005002template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005003StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005004TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5005 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005006 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005007 = getDerived().TransformCompoundStmt(S->getTryBlock());
5008 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005009 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005010
Douglas Gregorebe10102009-08-20 07:17:43 +00005011 // Transform the handlers.
5012 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005013 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005014 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005015 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005016 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5017 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005018 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005019
Douglas Gregorebe10102009-08-20 07:17:43 +00005020 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5021 Handlers.push_back(Handler.takeAs<Stmt>());
5022 }
Mike Stump11289f42009-09-09 15:08:12 +00005023
Douglas Gregorebe10102009-08-20 07:17:43 +00005024 if (!getDerived().AlwaysRebuild() &&
5025 TryBlock.get() == S->getTryBlock() &&
5026 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005027 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005028
John McCallb268a282010-08-23 23:25:46 +00005029 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005030 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005031}
Mike Stump11289f42009-09-09 15:08:12 +00005032
Douglas Gregorebe10102009-08-20 07:17:43 +00005033//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005034// Expression transformation
5035//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005036template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005037ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005038TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005039 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005040}
Mike Stump11289f42009-09-09 15:08:12 +00005041
5042template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005043ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005044TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005045 NestedNameSpecifier *Qualifier = 0;
5046 if (E->getQualifier()) {
5047 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005048 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005049 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005050 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005051 }
John McCallce546572009-12-08 09:08:17 +00005052
5053 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005054 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5055 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005056 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005057 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005058
John McCall815039a2010-08-17 21:27:17 +00005059 DeclarationNameInfo NameInfo = E->getNameInfo();
5060 if (NameInfo.getName()) {
5061 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5062 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005063 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005064 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005065
5066 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005067 Qualifier == E->getQualifier() &&
5068 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005069 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005070 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005071
5072 // Mark it referenced in the new context regardless.
5073 // FIXME: this is a bit instantiation-specific.
5074 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5075
John McCallc3007a22010-10-26 07:05:15 +00005076 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005077 }
John McCallce546572009-12-08 09:08:17 +00005078
5079 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005080 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005081 TemplateArgs = &TransArgs;
5082 TransArgs.setLAngleLoc(E->getLAngleLoc());
5083 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005084 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5085 E->getNumTemplateArgs(),
5086 TransArgs))
5087 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005088 }
5089
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005090 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005091 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005092}
Mike Stump11289f42009-09-09 15:08:12 +00005093
Douglas Gregora16548e2009-08-11 05:31:07 +00005094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005095ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005096TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005097 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005098}
Mike Stump11289f42009-09-09 15:08:12 +00005099
Douglas Gregora16548e2009-08-11 05:31:07 +00005100template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005101ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005102TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005103 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005104}
Mike Stump11289f42009-09-09 15:08:12 +00005105
Douglas Gregora16548e2009-08-11 05:31:07 +00005106template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005107ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005108TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005109 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005110}
Mike Stump11289f42009-09-09 15:08:12 +00005111
Douglas Gregora16548e2009-08-11 05:31:07 +00005112template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005113ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005114TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005115 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005116}
Mike Stump11289f42009-09-09 15:08:12 +00005117
Douglas Gregora16548e2009-08-11 05:31:07 +00005118template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005119ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005120TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005121 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005122}
5123
5124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005125ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005126TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005127 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005128 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005129 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005130
Douglas Gregora16548e2009-08-11 05:31:07 +00005131 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005132 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005133
John McCallb268a282010-08-23 23:25:46 +00005134 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005135 E->getRParen());
5136}
5137
Mike Stump11289f42009-09-09 15:08:12 +00005138template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005139ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005140TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005141 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005142 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005143 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005144
Douglas Gregora16548e2009-08-11 05:31:07 +00005145 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005146 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005147
Douglas Gregora16548e2009-08-11 05:31:07 +00005148 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5149 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005150 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005151}
Mike Stump11289f42009-09-09 15:08:12 +00005152
Douglas Gregora16548e2009-08-11 05:31:07 +00005153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005154ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005155TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5156 // Transform the type.
5157 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5158 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005159 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005160
Douglas Gregor882211c2010-04-28 22:16:22 +00005161 // Transform all of the components into components similar to what the
5162 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005163 // FIXME: It would be slightly more efficient in the non-dependent case to
5164 // just map FieldDecls, rather than requiring the rebuilder to look for
5165 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005166 // template code that we don't care.
5167 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005168 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005169 typedef OffsetOfExpr::OffsetOfNode Node;
5170 llvm::SmallVector<Component, 4> Components;
5171 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5172 const Node &ON = E->getComponent(I);
5173 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005174 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005175 Comp.LocStart = ON.getRange().getBegin();
5176 Comp.LocEnd = ON.getRange().getEnd();
5177 switch (ON.getKind()) {
5178 case Node::Array: {
5179 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005180 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005181 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005182 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005183
Douglas Gregor882211c2010-04-28 22:16:22 +00005184 ExprChanged = ExprChanged || Index.get() != FromIndex;
5185 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005186 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005187 break;
5188 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005189
Douglas Gregor882211c2010-04-28 22:16:22 +00005190 case Node::Field:
5191 case Node::Identifier:
5192 Comp.isBrackets = false;
5193 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005194 if (!Comp.U.IdentInfo)
5195 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005196
Douglas Gregor882211c2010-04-28 22:16:22 +00005197 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005198
Douglas Gregord1702062010-04-29 00:18:15 +00005199 case Node::Base:
5200 // Will be recomputed during the rebuild.
5201 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005202 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005203
Douglas Gregor882211c2010-04-28 22:16:22 +00005204 Components.push_back(Comp);
5205 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005206
Douglas Gregor882211c2010-04-28 22:16:22 +00005207 // If nothing changed, retain the existing expression.
5208 if (!getDerived().AlwaysRebuild() &&
5209 Type == E->getTypeSourceInfo() &&
5210 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005211 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005212
Douglas Gregor882211c2010-04-28 22:16:22 +00005213 // Build a new offsetof expression.
5214 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5215 Components.data(), Components.size(),
5216 E->getRParenLoc());
5217}
5218
5219template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005220ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005221TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5222 assert(getDerived().AlreadyTransformed(E->getType()) &&
5223 "opaque value expression requires transformation");
5224 return SemaRef.Owned(E);
5225}
5226
5227template<typename Derived>
5228ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005229TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005230 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005231 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005232
John McCallbcd03502009-12-07 02:54:59 +00005233 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005234 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005235 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005236
John McCall4c98fd82009-11-04 07:28:41 +00005237 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005238 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005239
John McCall4c98fd82009-11-04 07:28:41 +00005240 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005241 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005242 E->getSourceRange());
5243 }
Mike Stump11289f42009-09-09 15:08:12 +00005244
John McCalldadc5752010-08-24 06:29:42 +00005245 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005246 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005247 // C++0x [expr.sizeof]p1:
5248 // The operand is either an expression, which is an unevaluated operand
5249 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005250 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005251
Douglas Gregora16548e2009-08-11 05:31:07 +00005252 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5253 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005254 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005255
Douglas Gregora16548e2009-08-11 05:31:07 +00005256 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005257 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005258 }
Mike Stump11289f42009-09-09 15:08:12 +00005259
John McCallb268a282010-08-23 23:25:46 +00005260 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005261 E->isSizeOf(),
5262 E->getSourceRange());
5263}
Mike Stump11289f42009-09-09 15:08:12 +00005264
Douglas Gregora16548e2009-08-11 05:31:07 +00005265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005266ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005267TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005268 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005269 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005270 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005271
John McCalldadc5752010-08-24 06:29:42 +00005272 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005273 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005274 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005275
5276
Douglas Gregora16548e2009-08-11 05:31:07 +00005277 if (!getDerived().AlwaysRebuild() &&
5278 LHS.get() == E->getLHS() &&
5279 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005280 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005281
John McCallb268a282010-08-23 23:25:46 +00005282 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005283 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005284 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005285 E->getRBracketLoc());
5286}
Mike Stump11289f42009-09-09 15:08:12 +00005287
5288template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005289ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005290TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005291 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005292 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005293 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005294 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005295
5296 // Transform arguments.
5297 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005298 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005299 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5300 &ArgChanged))
5301 return ExprError();
5302
Douglas Gregora16548e2009-08-11 05:31:07 +00005303 if (!getDerived().AlwaysRebuild() &&
5304 Callee.get() == E->getCallee() &&
5305 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005306 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005307
Douglas Gregora16548e2009-08-11 05:31:07 +00005308 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005309 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005310 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005311 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005312 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005313 E->getRParenLoc());
5314}
Mike Stump11289f42009-09-09 15:08:12 +00005315
5316template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005317ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005318TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005319 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005320 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005321 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005322
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005323 NestedNameSpecifier *Qualifier = 0;
5324 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005325 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005326 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005327 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005328 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005329 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005330 }
Mike Stump11289f42009-09-09 15:08:12 +00005331
Eli Friedman2cfcef62009-12-04 06:40:45 +00005332 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005333 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5334 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005335 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005336 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005337
John McCall16df1e52010-03-30 21:47:33 +00005338 NamedDecl *FoundDecl = E->getFoundDecl();
5339 if (FoundDecl == E->getMemberDecl()) {
5340 FoundDecl = Member;
5341 } else {
5342 FoundDecl = cast_or_null<NamedDecl>(
5343 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5344 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005345 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005346 }
5347
Douglas Gregora16548e2009-08-11 05:31:07 +00005348 if (!getDerived().AlwaysRebuild() &&
5349 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005350 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005351 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005352 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005353 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005354
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005355 // Mark it referenced in the new context regardless.
5356 // FIXME: this is a bit instantiation-specific.
5357 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005358 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005359 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005360
John McCall6b51f282009-11-23 01:53:49 +00005361 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005362 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005363 TransArgs.setLAngleLoc(E->getLAngleLoc());
5364 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005365 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5366 E->getNumTemplateArgs(),
5367 TransArgs))
5368 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005369 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005370
Douglas Gregora16548e2009-08-11 05:31:07 +00005371 // FIXME: Bogus source location for the operator
5372 SourceLocation FakeOperatorLoc
5373 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5374
John McCall38836f02010-01-15 08:34:02 +00005375 // FIXME: to do this check properly, we will need to preserve the
5376 // first-qualifier-in-scope here, just in case we had a dependent
5377 // base (and therefore couldn't do the check) and a
5378 // nested-name-qualifier (and therefore could do the lookup).
5379 NamedDecl *FirstQualifierInScope = 0;
5380
John McCallb268a282010-08-23 23:25:46 +00005381 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005382 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005383 Qualifier,
5384 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005385 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005386 Member,
John McCall16df1e52010-03-30 21:47:33 +00005387 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005388 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005389 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005390 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005391}
Mike Stump11289f42009-09-09 15:08:12 +00005392
Douglas Gregora16548e2009-08-11 05:31:07 +00005393template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005394ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005395TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005396 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005397 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005398 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005399
John McCalldadc5752010-08-24 06:29:42 +00005400 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005401 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005402 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005403
Douglas Gregora16548e2009-08-11 05:31:07 +00005404 if (!getDerived().AlwaysRebuild() &&
5405 LHS.get() == E->getLHS() &&
5406 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005407 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005408
Douglas Gregora16548e2009-08-11 05:31:07 +00005409 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005410 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005411}
5412
Mike Stump11289f42009-09-09 15:08:12 +00005413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005414ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005415TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005416 CompoundAssignOperator *E) {
5417 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005418}
Mike Stump11289f42009-09-09 15:08:12 +00005419
Douglas Gregora16548e2009-08-11 05:31:07 +00005420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005421ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005422TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005423 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005424 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005425 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005426
John McCalldadc5752010-08-24 06:29:42 +00005427 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005428 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005429 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005430
John McCalldadc5752010-08-24 06:29:42 +00005431 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005432 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005433 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005434
Douglas Gregora16548e2009-08-11 05:31:07 +00005435 if (!getDerived().AlwaysRebuild() &&
5436 Cond.get() == E->getCond() &&
5437 LHS.get() == E->getLHS() &&
5438 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005439 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005440
John McCallb268a282010-08-23 23:25:46 +00005441 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005442 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005443 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005444 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005445 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005446}
Mike Stump11289f42009-09-09 15:08:12 +00005447
5448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005449ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005450TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005451 // Implicit casts are eliminated during transformation, since they
5452 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005453 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005454}
Mike Stump11289f42009-09-09 15:08:12 +00005455
Douglas Gregora16548e2009-08-11 05:31:07 +00005456template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005457ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005458TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005459 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5460 if (!Type)
5461 return ExprError();
5462
John McCalldadc5752010-08-24 06:29:42 +00005463 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005464 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005465 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005466 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005467
Douglas Gregora16548e2009-08-11 05:31:07 +00005468 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005469 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005470 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005471 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005472
John McCall97513962010-01-15 18:39:57 +00005473 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005474 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005475 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005476 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005477}
Mike Stump11289f42009-09-09 15:08:12 +00005478
Douglas Gregora16548e2009-08-11 05:31:07 +00005479template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005480ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005481TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005482 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5483 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5484 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005485 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005486
John McCalldadc5752010-08-24 06:29:42 +00005487 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005488 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005489 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005490
Douglas Gregora16548e2009-08-11 05:31:07 +00005491 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005492 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005493 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005494 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005495
John McCall5d7aa7f2010-01-19 22:33:45 +00005496 // Note: the expression type doesn't necessarily match the
5497 // type-as-written, but that's okay, because it should always be
5498 // derivable from the initializer.
5499
John McCalle15bbff2010-01-18 19:35:47 +00005500 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005501 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005502 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005503}
Mike Stump11289f42009-09-09 15:08:12 +00005504
Douglas Gregora16548e2009-08-11 05:31:07 +00005505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005506ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005507TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005508 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005509 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005510 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005511
Douglas Gregora16548e2009-08-11 05:31:07 +00005512 if (!getDerived().AlwaysRebuild() &&
5513 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005514 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005515
Douglas Gregora16548e2009-08-11 05:31:07 +00005516 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005517 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005518 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005519 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005520 E->getAccessorLoc(),
5521 E->getAccessor());
5522}
Mike Stump11289f42009-09-09 15:08:12 +00005523
Douglas Gregora16548e2009-08-11 05:31:07 +00005524template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005525ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005526TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005527 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005528
John McCall37ad5512010-08-23 06:44:23 +00005529 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005530 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5531 Inits, &InitChanged))
5532 return ExprError();
5533
Douglas Gregora16548e2009-08-11 05:31:07 +00005534 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005535 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005536
Douglas Gregora16548e2009-08-11 05:31:07 +00005537 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005538 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005539}
Mike Stump11289f42009-09-09 15:08:12 +00005540
Douglas Gregora16548e2009-08-11 05:31:07 +00005541template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005542ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005543TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005544 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005545
Douglas Gregorebe10102009-08-20 07:17:43 +00005546 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005547 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005548 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005549 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005550
Douglas Gregorebe10102009-08-20 07:17:43 +00005551 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005552 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005553 bool ExprChanged = false;
5554 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5555 DEnd = E->designators_end();
5556 D != DEnd; ++D) {
5557 if (D->isFieldDesignator()) {
5558 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5559 D->getDotLoc(),
5560 D->getFieldLoc()));
5561 continue;
5562 }
Mike Stump11289f42009-09-09 15:08:12 +00005563
Douglas Gregora16548e2009-08-11 05:31:07 +00005564 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005565 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005566 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005567 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005568
5569 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005570 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005571
Douglas Gregora16548e2009-08-11 05:31:07 +00005572 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5573 ArrayExprs.push_back(Index.release());
5574 continue;
5575 }
Mike Stump11289f42009-09-09 15:08:12 +00005576
Douglas Gregora16548e2009-08-11 05:31:07 +00005577 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005578 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005579 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5580 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005581 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005582
John McCalldadc5752010-08-24 06:29:42 +00005583 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005584 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005585 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005586
5587 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005588 End.get(),
5589 D->getLBracketLoc(),
5590 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005591
Douglas Gregora16548e2009-08-11 05:31:07 +00005592 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5593 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005594
Douglas Gregora16548e2009-08-11 05:31:07 +00005595 ArrayExprs.push_back(Start.release());
5596 ArrayExprs.push_back(End.release());
5597 }
Mike Stump11289f42009-09-09 15:08:12 +00005598
Douglas Gregora16548e2009-08-11 05:31:07 +00005599 if (!getDerived().AlwaysRebuild() &&
5600 Init.get() == E->getInit() &&
5601 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005602 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005603
Douglas Gregora16548e2009-08-11 05:31:07 +00005604 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5605 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005606 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005607}
Mike Stump11289f42009-09-09 15:08:12 +00005608
Douglas Gregora16548e2009-08-11 05:31:07 +00005609template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005610ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005611TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005612 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005613 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005614
Douglas Gregor3da3c062009-10-28 00:29:27 +00005615 // FIXME: Will we ever have proper type location here? Will we actually
5616 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005617 QualType T = getDerived().TransformType(E->getType());
5618 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005619 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005620
Douglas Gregora16548e2009-08-11 05:31:07 +00005621 if (!getDerived().AlwaysRebuild() &&
5622 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005623 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005624
Douglas Gregora16548e2009-08-11 05:31:07 +00005625 return getDerived().RebuildImplicitValueInitExpr(T);
5626}
Mike Stump11289f42009-09-09 15:08:12 +00005627
Douglas Gregora16548e2009-08-11 05:31:07 +00005628template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005629ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005630TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005631 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5632 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005633 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005634
John McCalldadc5752010-08-24 06:29:42 +00005635 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005636 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005637 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005638
Douglas Gregora16548e2009-08-11 05:31:07 +00005639 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005640 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005641 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005642 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005643
John McCallb268a282010-08-23 23:25:46 +00005644 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005645 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005646}
5647
5648template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005649ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005650TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005651 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005652 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005653 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
5654 &ArgumentChanged))
5655 return ExprError();
5656
Douglas Gregora16548e2009-08-11 05:31:07 +00005657 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
5658 move_arg(Inits),
5659 E->getRParenLoc());
5660}
Mike Stump11289f42009-09-09 15:08:12 +00005661
Douglas Gregora16548e2009-08-11 05:31:07 +00005662/// \brief Transform an address-of-label expression.
5663///
5664/// By default, the transformation of an address-of-label expression always
5665/// rebuilds the expression, so that the label identifier can be resolved to
5666/// the corresponding label statement by semantic analysis.
5667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005668ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005669TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005670 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
5671 E->getLabel());
5672}
Mike Stump11289f42009-09-09 15:08:12 +00005673
5674template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005675ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005676TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005677 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00005678 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
5679 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005680 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005681
Douglas Gregora16548e2009-08-11 05:31:07 +00005682 if (!getDerived().AlwaysRebuild() &&
5683 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00005684 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005685
5686 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005687 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005688 E->getRParenLoc());
5689}
Mike Stump11289f42009-09-09 15:08:12 +00005690
Douglas Gregora16548e2009-08-11 05:31:07 +00005691template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005692ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005693TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005694 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005695 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005696 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005697
John McCalldadc5752010-08-24 06:29:42 +00005698 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005699 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005700 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005701
John McCalldadc5752010-08-24 06:29:42 +00005702 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005703 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005704 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005705
Douglas Gregora16548e2009-08-11 05:31:07 +00005706 if (!getDerived().AlwaysRebuild() &&
5707 Cond.get() == E->getCond() &&
5708 LHS.get() == E->getLHS() &&
5709 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005710 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005711
Douglas Gregora16548e2009-08-11 05:31:07 +00005712 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00005713 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005714 E->getRParenLoc());
5715}
Mike Stump11289f42009-09-09 15:08:12 +00005716
Douglas Gregora16548e2009-08-11 05:31:07 +00005717template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005718ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005719TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005720 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005721}
5722
5723template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005724ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005725TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005726 switch (E->getOperator()) {
5727 case OO_New:
5728 case OO_Delete:
5729 case OO_Array_New:
5730 case OO_Array_Delete:
5731 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00005732 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005733
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005734 case OO_Call: {
5735 // This is a call to an object's operator().
5736 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
5737
5738 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00005739 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005740 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005741 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005742
5743 // FIXME: Poor location information
5744 SourceLocation FakeLParenLoc
5745 = SemaRef.PP.getLocForEndOfToken(
5746 static_cast<Expr *>(Object.get())->getLocEnd());
5747
5748 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00005749 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005750 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
5751 Args))
5752 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005753
John McCallb268a282010-08-23 23:25:46 +00005754 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005755 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005756 E->getLocEnd());
5757 }
5758
5759#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
5760 case OO_##Name:
5761#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
5762#include "clang/Basic/OperatorKinds.def"
5763 case OO_Subscript:
5764 // Handled below.
5765 break;
5766
5767 case OO_Conditional:
5768 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00005769 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005770
5771 case OO_None:
5772 case NUM_OVERLOADED_OPERATORS:
5773 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00005774 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00005775 }
5776
John McCalldadc5752010-08-24 06:29:42 +00005777 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005778 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005779 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005780
John McCalldadc5752010-08-24 06:29:42 +00005781 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00005782 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005783 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005784
John McCalldadc5752010-08-24 06:29:42 +00005785 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00005786 if (E->getNumArgs() == 2) {
5787 Second = getDerived().TransformExpr(E->getArg(1));
5788 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005789 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005790 }
Mike Stump11289f42009-09-09 15:08:12 +00005791
Douglas Gregora16548e2009-08-11 05:31:07 +00005792 if (!getDerived().AlwaysRebuild() &&
5793 Callee.get() == E->getCallee() &&
5794 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00005795 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00005796 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005797
Douglas Gregora16548e2009-08-11 05:31:07 +00005798 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
5799 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00005800 Callee.get(),
5801 First.get(),
5802 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005803}
Mike Stump11289f42009-09-09 15:08:12 +00005804
Douglas Gregora16548e2009-08-11 05:31:07 +00005805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005806ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005807TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
5808 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005809}
Mike Stump11289f42009-09-09 15:08:12 +00005810
Douglas Gregora16548e2009-08-11 05:31:07 +00005811template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005812ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005813TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005814 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5815 if (!Type)
5816 return ExprError();
5817
John McCalldadc5752010-08-24 06:29:42 +00005818 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005819 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005820 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005821 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005822
Douglas Gregora16548e2009-08-11 05:31:07 +00005823 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005824 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005825 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005826 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005827
Douglas Gregora16548e2009-08-11 05:31:07 +00005828 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00005829 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005830 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
5831 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
5832 SourceLocation FakeRParenLoc
5833 = SemaRef.PP.getLocForEndOfToken(
5834 E->getSubExpr()->getSourceRange().getEnd());
5835 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005836 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005837 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005838 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005839 FakeRAngleLoc,
5840 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00005841 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005842 FakeRParenLoc);
5843}
Mike Stump11289f42009-09-09 15:08:12 +00005844
Douglas Gregora16548e2009-08-11 05:31:07 +00005845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005846ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005847TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
5848 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005849}
Mike Stump11289f42009-09-09 15:08:12 +00005850
5851template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005852ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005853TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
5854 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00005855}
5856
Douglas Gregora16548e2009-08-11 05:31:07 +00005857template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005858ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005859TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005860 CXXReinterpretCastExpr *E) {
5861 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005862}
Mike Stump11289f42009-09-09 15:08:12 +00005863
Douglas Gregora16548e2009-08-11 05:31:07 +00005864template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005865ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005866TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
5867 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005868}
Mike Stump11289f42009-09-09 15:08:12 +00005869
Douglas Gregora16548e2009-08-11 05:31:07 +00005870template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005871ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005872TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005873 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005874 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5875 if (!Type)
5876 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005877
John McCalldadc5752010-08-24 06:29:42 +00005878 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005879 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005880 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005881 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005882
Douglas Gregora16548e2009-08-11 05:31:07 +00005883 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005884 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005885 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005886 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005887
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005888 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005889 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005890 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005891 E->getRParenLoc());
5892}
Mike Stump11289f42009-09-09 15:08:12 +00005893
Douglas Gregora16548e2009-08-11 05:31:07 +00005894template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005895ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005896TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005897 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00005898 TypeSourceInfo *TInfo
5899 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5900 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005901 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005902
Douglas Gregora16548e2009-08-11 05:31:07 +00005903 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00005904 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005905 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005906
Douglas Gregor9da64192010-04-26 22:37:10 +00005907 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5908 E->getLocStart(),
5909 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00005910 E->getLocEnd());
5911 }
Mike Stump11289f42009-09-09 15:08:12 +00005912
Douglas Gregora16548e2009-08-11 05:31:07 +00005913 // We don't know whether the expression is potentially evaluated until
5914 // after we perform semantic analysis, so the expression is potentially
5915 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00005916 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00005917 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005918
John McCalldadc5752010-08-24 06:29:42 +00005919 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00005920 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005921 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005922
Douglas Gregora16548e2009-08-11 05:31:07 +00005923 if (!getDerived().AlwaysRebuild() &&
5924 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005925 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005926
Douglas Gregor9da64192010-04-26 22:37:10 +00005927 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5928 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005929 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005930 E->getLocEnd());
5931}
5932
5933template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005934ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00005935TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
5936 if (E->isTypeOperand()) {
5937 TypeSourceInfo *TInfo
5938 = getDerived().TransformType(E->getTypeOperandSourceInfo());
5939 if (!TInfo)
5940 return ExprError();
5941
5942 if (!getDerived().AlwaysRebuild() &&
5943 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00005944 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005945
5946 return getDerived().RebuildCXXTypeidExpr(E->getType(),
5947 E->getLocStart(),
5948 TInfo,
5949 E->getLocEnd());
5950 }
5951
5952 // We don't know whether the expression is potentially evaluated until
5953 // after we perform semantic analysis, so the expression is potentially
5954 // potentially evaluated.
5955 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
5956
5957 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
5958 if (SubExpr.isInvalid())
5959 return ExprError();
5960
5961 if (!getDerived().AlwaysRebuild() &&
5962 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00005963 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00005964
5965 return getDerived().RebuildCXXUuidofExpr(E->getType(),
5966 E->getLocStart(),
5967 SubExpr.get(),
5968 E->getLocEnd());
5969}
5970
5971template<typename Derived>
5972ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005973TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005974 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005975}
Mike Stump11289f42009-09-09 15:08:12 +00005976
Douglas Gregora16548e2009-08-11 05:31:07 +00005977template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005978ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005979TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005980 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005981 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005982}
Mike Stump11289f42009-09-09 15:08:12 +00005983
Douglas Gregora16548e2009-08-11 05:31:07 +00005984template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005985ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005986TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005987 DeclContext *DC = getSema().getFunctionLevelDeclContext();
5988 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
5989 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00005990
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005991 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005992 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005993
Douglas Gregorb15af892010-01-07 23:12:05 +00005994 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005995}
Mike Stump11289f42009-09-09 15:08:12 +00005996
Douglas Gregora16548e2009-08-11 05:31:07 +00005997template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005998ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005999TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006000 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006001 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006002 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006003
Douglas Gregora16548e2009-08-11 05:31:07 +00006004 if (!getDerived().AlwaysRebuild() &&
6005 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006006 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006007
John McCallb268a282010-08-23 23:25:46 +00006008 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006009}
Mike Stump11289f42009-09-09 15:08:12 +00006010
Douglas Gregora16548e2009-08-11 05:31:07 +00006011template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006012ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006013TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006014 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006015 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6016 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006017 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006018 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006019
Chandler Carruth794da4c2010-02-08 06:42:49 +00006020 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006021 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006022 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006023
Douglas Gregor033f6752009-12-23 23:03:06 +00006024 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006025}
Mike Stump11289f42009-09-09 15:08:12 +00006026
Douglas Gregora16548e2009-08-11 05:31:07 +00006027template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006028ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006029TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6030 CXXScalarValueInitExpr *E) {
6031 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6032 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006033 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006034
Douglas Gregora16548e2009-08-11 05:31:07 +00006035 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006036 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006037 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006038
Douglas Gregor2b88c112010-09-08 00:15:04 +00006039 return getDerived().RebuildCXXScalarValueInitExpr(T,
6040 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006041 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006042}
Mike Stump11289f42009-09-09 15:08:12 +00006043
Douglas Gregora16548e2009-08-11 05:31:07 +00006044template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006045ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006046TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006047 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006048 TypeSourceInfo *AllocTypeInfo
6049 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6050 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006051 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006052
Douglas Gregora16548e2009-08-11 05:31:07 +00006053 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006054 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006055 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006056 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006057
Douglas Gregora16548e2009-08-11 05:31:07 +00006058 // Transform the placement arguments (if any).
6059 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006060 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006061 if (getDerived().TransformExprs(E->getPlacementArgs(),
6062 E->getNumPlacementArgs(), true,
6063 PlacementArgs, &ArgumentChanged))
6064 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006065
Douglas Gregorebe10102009-08-20 07:17:43 +00006066 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006067 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006068 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6069 ConstructorArgs, &ArgumentChanged))
6070 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006071
Douglas Gregord2d9da02010-02-26 00:38:10 +00006072 // Transform constructor, new operator, and delete operator.
6073 CXXConstructorDecl *Constructor = 0;
6074 if (E->getConstructor()) {
6075 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006076 getDerived().TransformDecl(E->getLocStart(),
6077 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006078 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006079 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006080 }
6081
6082 FunctionDecl *OperatorNew = 0;
6083 if (E->getOperatorNew()) {
6084 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006085 getDerived().TransformDecl(E->getLocStart(),
6086 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006087 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006088 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006089 }
6090
6091 FunctionDecl *OperatorDelete = 0;
6092 if (E->getOperatorDelete()) {
6093 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006094 getDerived().TransformDecl(E->getLocStart(),
6095 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006096 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006097 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006098 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006099
Douglas Gregora16548e2009-08-11 05:31:07 +00006100 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006101 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006102 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006103 Constructor == E->getConstructor() &&
6104 OperatorNew == E->getOperatorNew() &&
6105 OperatorDelete == E->getOperatorDelete() &&
6106 !ArgumentChanged) {
6107 // Mark any declarations we need as referenced.
6108 // FIXME: instantiation-specific.
6109 if (Constructor)
6110 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6111 if (OperatorNew)
6112 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6113 if (OperatorDelete)
6114 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006115 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006116 }
Mike Stump11289f42009-09-09 15:08:12 +00006117
Douglas Gregor0744ef62010-09-07 21:49:58 +00006118 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006119 if (!ArraySize.get()) {
6120 // If no array size was specified, but the new expression was
6121 // instantiated with an array type (e.g., "new T" where T is
6122 // instantiated with "int[4]"), extract the outer bound from the
6123 // array type as our array size. We do this with constant and
6124 // dependently-sized array types.
6125 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6126 if (!ArrayT) {
6127 // Do nothing
6128 } else if (const ConstantArrayType *ConsArrayT
6129 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006130 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006131 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6132 ConsArrayT->getSize(),
6133 SemaRef.Context.getSizeType(),
6134 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006135 AllocType = ConsArrayT->getElementType();
6136 } else if (const DependentSizedArrayType *DepArrayT
6137 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6138 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006139 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006140 AllocType = DepArrayT->getElementType();
6141 }
6142 }
6143 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006144
Douglas Gregora16548e2009-08-11 05:31:07 +00006145 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6146 E->isGlobalNew(),
6147 /*FIXME:*/E->getLocStart(),
6148 move_arg(PlacementArgs),
6149 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006150 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006151 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006152 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006153 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006154 /*FIXME:*/E->getLocStart(),
6155 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006156 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006157}
Mike Stump11289f42009-09-09 15:08:12 +00006158
Douglas Gregora16548e2009-08-11 05:31:07 +00006159template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006160ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006161TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006162 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006163 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006164 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006165
Douglas Gregord2d9da02010-02-26 00:38:10 +00006166 // Transform the delete operator, if known.
6167 FunctionDecl *OperatorDelete = 0;
6168 if (E->getOperatorDelete()) {
6169 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006170 getDerived().TransformDecl(E->getLocStart(),
6171 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006172 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006173 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006174 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006175
Douglas Gregora16548e2009-08-11 05:31:07 +00006176 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006177 Operand.get() == E->getArgument() &&
6178 OperatorDelete == E->getOperatorDelete()) {
6179 // Mark any declarations we need as referenced.
6180 // FIXME: instantiation-specific.
6181 if (OperatorDelete)
6182 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006183
6184 if (!E->getArgument()->isTypeDependent()) {
6185 QualType Destroyed = SemaRef.Context.getBaseElementType(
6186 E->getDestroyedType());
6187 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6188 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6189 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6190 SemaRef.LookupDestructor(Record));
6191 }
6192 }
6193
John McCallc3007a22010-10-26 07:05:15 +00006194 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006195 }
Mike Stump11289f42009-09-09 15:08:12 +00006196
Douglas Gregora16548e2009-08-11 05:31:07 +00006197 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6198 E->isGlobalDelete(),
6199 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006200 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006201}
Mike Stump11289f42009-09-09 15:08:12 +00006202
Douglas Gregora16548e2009-08-11 05:31:07 +00006203template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006204ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006205TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006206 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006207 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006208 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006209 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006210
John McCallba7bf592010-08-24 05:47:05 +00006211 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006212 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006213 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006214 E->getOperatorLoc(),
6215 E->isArrow()? tok::arrow : tok::period,
6216 ObjectTypePtr,
6217 MayBePseudoDestructor);
6218 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006219 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006220
John McCallba7bf592010-08-24 05:47:05 +00006221 QualType ObjectType = ObjectTypePtr.get();
John McCall31f82722010-11-12 08:19:04 +00006222 NestedNameSpecifier *Qualifier = E->getQualifier();
6223 if (Qualifier) {
6224 Qualifier
6225 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6226 E->getQualifierRange(),
6227 ObjectType);
6228 if (!Qualifier)
6229 return ExprError();
6230 }
Mike Stump11289f42009-09-09 15:08:12 +00006231
Douglas Gregor678f90d2010-02-25 01:56:36 +00006232 PseudoDestructorTypeStorage Destroyed;
6233 if (E->getDestroyedTypeInfo()) {
6234 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006235 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
6236 ObjectType, 0, Qualifier);
Douglas Gregor678f90d2010-02-25 01:56:36 +00006237 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006238 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006239 Destroyed = DestroyedTypeInfo;
6240 } else if (ObjectType->isDependentType()) {
6241 // We aren't likely to be able to resolve the identifier down to a type
6242 // now anyway, so just retain the identifier.
6243 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6244 E->getDestroyedTypeLoc());
6245 } else {
6246 // Look for a destructor known with the given name.
6247 CXXScopeSpec SS;
6248 if (Qualifier) {
6249 SS.setScopeRep(Qualifier);
6250 SS.setRange(E->getQualifierRange());
6251 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006252
John McCallba7bf592010-08-24 05:47:05 +00006253 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006254 *E->getDestroyedTypeIdentifier(),
6255 E->getDestroyedTypeLoc(),
6256 /*Scope=*/0,
6257 SS, ObjectTypePtr,
6258 false);
6259 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006260 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006261
Douglas Gregor678f90d2010-02-25 01:56:36 +00006262 Destroyed
6263 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6264 E->getDestroyedTypeLoc());
6265 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006266
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006267 TypeSourceInfo *ScopeTypeInfo = 0;
6268 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006269 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006270 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006271 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006272 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006273
John McCallb268a282010-08-23 23:25:46 +00006274 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006275 E->getOperatorLoc(),
6276 E->isArrow(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006277 Qualifier,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006278 E->getQualifierRange(),
6279 ScopeTypeInfo,
6280 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006281 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006282 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006283}
Mike Stump11289f42009-09-09 15:08:12 +00006284
Douglas Gregorad8a3362009-09-04 17:36:40 +00006285template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006286ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006287TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006288 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006289 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6290
6291 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6292 Sema::LookupOrdinaryName);
6293
6294 // Transform all the decls.
6295 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6296 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006297 NamedDecl *InstD = static_cast<NamedDecl*>(
6298 getDerived().TransformDecl(Old->getNameLoc(),
6299 *I));
John McCall84d87672009-12-10 09:41:52 +00006300 if (!InstD) {
6301 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6302 // This can happen because of dependent hiding.
6303 if (isa<UsingShadowDecl>(*I))
6304 continue;
6305 else
John McCallfaf5fb42010-08-26 23:41:50 +00006306 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006307 }
John McCalle66edc12009-11-24 19:00:30 +00006308
6309 // Expand using declarations.
6310 if (isa<UsingDecl>(InstD)) {
6311 UsingDecl *UD = cast<UsingDecl>(InstD);
6312 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6313 E = UD->shadow_end(); I != E; ++I)
6314 R.addDecl(*I);
6315 continue;
6316 }
6317
6318 R.addDecl(InstD);
6319 }
6320
6321 // Resolve a kind, but don't do any further analysis. If it's
6322 // ambiguous, the callee needs to deal with it.
6323 R.resolveKind();
6324
6325 // Rebuild the nested-name qualifier, if present.
6326 CXXScopeSpec SS;
6327 NestedNameSpecifier *Qualifier = 0;
6328 if (Old->getQualifier()) {
6329 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006330 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00006331 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006332 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006333
John McCalle66edc12009-11-24 19:00:30 +00006334 SS.setScopeRep(Qualifier);
6335 SS.setRange(Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006336 }
6337
Douglas Gregor9262f472010-04-27 18:19:34 +00006338 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006339 CXXRecordDecl *NamingClass
6340 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6341 Old->getNameLoc(),
6342 Old->getNamingClass()));
6343 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006344 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006345
Douglas Gregorda7be082010-04-27 16:10:10 +00006346 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006347 }
6348
6349 // If we have no template arguments, it's a normal declaration name.
6350 if (!Old->hasExplicitTemplateArgs())
6351 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6352
6353 // If we have template arguments, rebuild them, then rebuild the
6354 // templateid expression.
6355 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006356 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6357 Old->getNumTemplateArgs(),
6358 TransArgs))
6359 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006360
6361 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6362 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006363}
Mike Stump11289f42009-09-09 15:08:12 +00006364
Douglas Gregora16548e2009-08-11 05:31:07 +00006365template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006366ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006367TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006368 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6369 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006370 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006371
Douglas Gregora16548e2009-08-11 05:31:07 +00006372 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006373 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006374 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006375
Mike Stump11289f42009-09-09 15:08:12 +00006376 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006377 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006378 T,
6379 E->getLocEnd());
6380}
Mike Stump11289f42009-09-09 15:08:12 +00006381
Douglas Gregora16548e2009-08-11 05:31:07 +00006382template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006383ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006384TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6385 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6386 if (!LhsT)
6387 return ExprError();
6388
6389 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6390 if (!RhsT)
6391 return ExprError();
6392
6393 if (!getDerived().AlwaysRebuild() &&
6394 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6395 return SemaRef.Owned(E);
6396
6397 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6398 E->getLocStart(),
6399 LhsT, RhsT,
6400 E->getLocEnd());
6401}
6402
6403template<typename Derived>
6404ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006405TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006406 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006407 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006408 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006409 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006410 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006411 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006412
John McCall31f82722010-11-12 08:19:04 +00006413 // TODO: If this is a conversion-function-id, verify that the
6414 // destination type name (if present) resolves the same way after
6415 // instantiation as it did in the local scope.
6416
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006417 DeclarationNameInfo NameInfo
6418 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6419 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006420 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006421
John McCalle66edc12009-11-24 19:00:30 +00006422 if (!E->hasExplicitTemplateArgs()) {
6423 if (!getDerived().AlwaysRebuild() &&
6424 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006425 // Note: it is sufficient to compare the Name component of NameInfo:
6426 // if name has not changed, DNLoc has not changed either.
6427 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006428 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006429
John McCalle66edc12009-11-24 19:00:30 +00006430 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6431 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006432 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006433 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006434 }
John McCall6b51f282009-11-23 01:53:49 +00006435
6436 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006437 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6438 E->getNumTemplateArgs(),
6439 TransArgs))
6440 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006441
John McCalle66edc12009-11-24 19:00:30 +00006442 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6443 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006444 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006445 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006446}
6447
6448template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006449ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006450TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006451 // CXXConstructExprs are always implicit, so when we have a
6452 // 1-argument construction we just transform that argument.
6453 if (E->getNumArgs() == 1 ||
6454 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6455 return getDerived().TransformExpr(E->getArg(0));
6456
Douglas Gregora16548e2009-08-11 05:31:07 +00006457 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6458
6459 QualType T = getDerived().TransformType(E->getType());
6460 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006461 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006462
6463 CXXConstructorDecl *Constructor
6464 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006465 getDerived().TransformDecl(E->getLocStart(),
6466 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006467 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006468 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006469
Douglas Gregora16548e2009-08-11 05:31:07 +00006470 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006471 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006472 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6473 &ArgumentChanged))
6474 return ExprError();
6475
Douglas Gregora16548e2009-08-11 05:31:07 +00006476 if (!getDerived().AlwaysRebuild() &&
6477 T == E->getType() &&
6478 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006479 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006480 // Mark the constructor as referenced.
6481 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006482 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006483 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006484 }
Mike Stump11289f42009-09-09 15:08:12 +00006485
Douglas Gregordb121ba2009-12-14 16:27:04 +00006486 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6487 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006488 move_arg(Args),
6489 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006490 E->getConstructionKind(),
6491 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006492}
Mike Stump11289f42009-09-09 15:08:12 +00006493
Douglas Gregora16548e2009-08-11 05:31:07 +00006494/// \brief Transform a C++ temporary-binding expression.
6495///
Douglas Gregor363b1512009-12-24 18:51:59 +00006496/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6497/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006498template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006499ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006500TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006501 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006502}
Mike Stump11289f42009-09-09 15:08:12 +00006503
John McCall5d413782010-12-06 08:20:24 +00006504/// \brief Transform a C++ expression that contains cleanups that should
6505/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006506///
John McCall5d413782010-12-06 08:20:24 +00006507/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006508/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006509template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006510ExprResult
John McCall5d413782010-12-06 08:20:24 +00006511TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006512 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006513}
Mike Stump11289f42009-09-09 15:08:12 +00006514
Douglas Gregora16548e2009-08-11 05:31:07 +00006515template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006516ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006517TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006518 CXXTemporaryObjectExpr *E) {
6519 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6520 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006521 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006522
Douglas Gregora16548e2009-08-11 05:31:07 +00006523 CXXConstructorDecl *Constructor
6524 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006525 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006526 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006527 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006528 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006529
Douglas Gregora16548e2009-08-11 05:31:07 +00006530 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006531 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006532 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006533 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6534 &ArgumentChanged))
6535 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006536
Douglas Gregora16548e2009-08-11 05:31:07 +00006537 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006538 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006539 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006540 !ArgumentChanged) {
6541 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006542 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006543 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006544 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006545
6546 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6547 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006548 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006549 E->getLocEnd());
6550}
Mike Stump11289f42009-09-09 15:08:12 +00006551
Douglas Gregora16548e2009-08-11 05:31:07 +00006552template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006553ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006554TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006555 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006556 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6557 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006558 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006559
Douglas Gregora16548e2009-08-11 05:31:07 +00006560 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006561 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006562 Args.reserve(E->arg_size());
6563 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6564 &ArgumentChanged))
6565 return ExprError();
6566
Douglas Gregora16548e2009-08-11 05:31:07 +00006567 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006568 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006569 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006570 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006571
Douglas Gregora16548e2009-08-11 05:31:07 +00006572 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006573 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006574 E->getLParenLoc(),
6575 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006576 E->getRParenLoc());
6577}
Mike Stump11289f42009-09-09 15:08:12 +00006578
Douglas Gregora16548e2009-08-11 05:31:07 +00006579template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006580ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006581TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006582 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006583 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006584 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006585 Expr *OldBase;
6586 QualType BaseType;
6587 QualType ObjectType;
6588 if (!E->isImplicitAccess()) {
6589 OldBase = E->getBase();
6590 Base = getDerived().TransformExpr(OldBase);
6591 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006592 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006593
John McCall2d74de92009-12-01 22:10:20 +00006594 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006595 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006596 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006597 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006598 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006599 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006600 ObjectTy,
6601 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006602 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006603 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006604
John McCallba7bf592010-08-24 05:47:05 +00006605 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006606 BaseType = ((Expr*) Base.get())->getType();
6607 } else {
6608 OldBase = 0;
6609 BaseType = getDerived().TransformType(E->getBaseType());
6610 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6611 }
Mike Stump11289f42009-09-09 15:08:12 +00006612
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006613 // Transform the first part of the nested-name-specifier that qualifies
6614 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006615 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006616 = getDerived().TransformFirstQualifierInScope(
6617 E->getFirstQualifierFoundInScope(),
6618 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00006619
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006620 NestedNameSpecifier *Qualifier = 0;
6621 if (E->getQualifier()) {
6622 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
6623 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00006624 ObjectType,
6625 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006626 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006627 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006628 }
Mike Stump11289f42009-09-09 15:08:12 +00006629
John McCall31f82722010-11-12 08:19:04 +00006630 // TODO: If this is a conversion-function-id, verify that the
6631 // destination type name (if present) resolves the same way after
6632 // instantiation as it did in the local scope.
6633
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006634 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00006635 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006636 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006637 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006638
John McCall2d74de92009-12-01 22:10:20 +00006639 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00006640 // This is a reference to a member without an explicitly-specified
6641 // template argument list. Optimize for this common case.
6642 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00006643 Base.get() == OldBase &&
6644 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006645 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006646 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00006647 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00006648 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006649
John McCallb268a282010-08-23 23:25:46 +00006650 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006651 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00006652 E->isArrow(),
6653 E->getOperatorLoc(),
6654 Qualifier,
6655 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00006656 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006657 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006658 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00006659 }
6660
John McCall6b51f282009-11-23 01:53:49 +00006661 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006662 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6663 E->getNumTemplateArgs(),
6664 TransArgs))
6665 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006666
John McCallb268a282010-08-23 23:25:46 +00006667 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006668 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00006669 E->isArrow(),
6670 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006671 Qualifier,
6672 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00006673 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006674 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00006675 &TransArgs);
6676}
6677
6678template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006679ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006680TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00006681 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006682 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006683 QualType BaseType;
6684 if (!Old->isImplicitAccess()) {
6685 Base = getDerived().TransformExpr(Old->getBase());
6686 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006687 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006688 BaseType = ((Expr*) Base.get())->getType();
6689 } else {
6690 BaseType = getDerived().TransformType(Old->getBaseType());
6691 }
John McCall10eae182009-11-30 22:42:35 +00006692
6693 NestedNameSpecifier *Qualifier = 0;
6694 if (Old->getQualifier()) {
6695 Qualifier
6696 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006697 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00006698 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00006699 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006700 }
6701
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006702 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00006703 Sema::LookupOrdinaryName);
6704
6705 // Transform all the decls.
6706 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
6707 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006708 NamedDecl *InstD = static_cast<NamedDecl*>(
6709 getDerived().TransformDecl(Old->getMemberLoc(),
6710 *I));
John McCall84d87672009-12-10 09:41:52 +00006711 if (!InstD) {
6712 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6713 // This can happen because of dependent hiding.
6714 if (isa<UsingShadowDecl>(*I))
6715 continue;
6716 else
John McCallfaf5fb42010-08-26 23:41:50 +00006717 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006718 }
John McCall10eae182009-11-30 22:42:35 +00006719
6720 // Expand using declarations.
6721 if (isa<UsingDecl>(InstD)) {
6722 UsingDecl *UD = cast<UsingDecl>(InstD);
6723 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6724 E = UD->shadow_end(); I != E; ++I)
6725 R.addDecl(*I);
6726 continue;
6727 }
6728
6729 R.addDecl(InstD);
6730 }
6731
6732 R.resolveKind();
6733
Douglas Gregor9262f472010-04-27 18:19:34 +00006734 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00006735 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006736 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00006737 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00006738 Old->getMemberLoc(),
6739 Old->getNamingClass()));
6740 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006741 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006742
Douglas Gregorda7be082010-04-27 16:10:10 +00006743 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00006744 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006745
John McCall10eae182009-11-30 22:42:35 +00006746 TemplateArgumentListInfo TransArgs;
6747 if (Old->hasExplicitTemplateArgs()) {
6748 TransArgs.setLAngleLoc(Old->getLAngleLoc());
6749 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006750 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6751 Old->getNumTemplateArgs(),
6752 TransArgs))
6753 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00006754 }
John McCall38836f02010-01-15 08:34:02 +00006755
6756 // FIXME: to do this check properly, we will need to preserve the
6757 // first-qualifier-in-scope here, just in case we had a dependent
6758 // base (and therefore couldn't do the check) and a
6759 // nested-name-qualifier (and therefore could do the lookup).
6760 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00006761
John McCallb268a282010-08-23 23:25:46 +00006762 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006763 BaseType,
John McCall10eae182009-11-30 22:42:35 +00006764 Old->getOperatorLoc(),
6765 Old->isArrow(),
6766 Qualifier,
6767 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00006768 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00006769 R,
6770 (Old->hasExplicitTemplateArgs()
6771 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006772}
6773
6774template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006775ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006776TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
6777 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
6778 if (SubExpr.isInvalid())
6779 return ExprError();
6780
6781 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00006782 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00006783
6784 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
6785}
6786
6787template<typename Derived>
6788ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006789TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00006790 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
6791 if (Pattern.isInvalid())
6792 return ExprError();
6793
6794 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
6795 return SemaRef.Owned(E);
6796
6797 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006798}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006799
6800template<typename Derived>
6801ExprResult
6802TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
6803 // If E is not value-dependent, then nothing will change when we transform it.
6804 // Note: This is an instantiation-centric view.
6805 if (!E->isValueDependent())
6806 return SemaRef.Owned(E);
6807
6808 // Note: None of the implementations of TryExpandParameterPacks can ever
6809 // produce a diagnostic when given only a single unexpanded parameter pack,
6810 // so
6811 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
6812 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006813 bool RetainExpansion = false;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006814 unsigned NumExpansions = 0;
6815 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
6816 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006817 ShouldExpand, RetainExpansion,
6818 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006819 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006820
Douglas Gregora8bac7f2011-01-10 07:32:04 +00006821 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00006822 return SemaRef.Owned(E);
6823
6824 // We now know the length of the parameter pack, so build a new expression
6825 // that stores that length.
6826 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
6827 E->getPackLoc(), E->getRParenLoc(),
6828 NumExpansions);
6829}
6830
Douglas Gregore8e9dd62011-01-03 17:17:50 +00006831template<typename Derived>
6832ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006833TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00006834 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006835}
6836
Mike Stump11289f42009-09-09 15:08:12 +00006837template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006838ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006839TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00006840 TypeSourceInfo *EncodedTypeInfo
6841 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
6842 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006843 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006844
Douglas Gregora16548e2009-08-11 05:31:07 +00006845 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00006846 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006847 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006848
6849 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00006850 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006851 E->getRParenLoc());
6852}
Mike Stump11289f42009-09-09 15:08:12 +00006853
Douglas Gregora16548e2009-08-11 05:31:07 +00006854template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006855ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006856TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006857 // Transform arguments.
6858 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006859 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006860 Args.reserve(E->getNumArgs());
6861 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
6862 &ArgChanged))
6863 return ExprError();
6864
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006865 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
6866 // Class message: transform the receiver type.
6867 TypeSourceInfo *ReceiverTypeInfo
6868 = getDerived().TransformType(E->getClassReceiverTypeInfo());
6869 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006870 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006871
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006872 // If nothing changed, just retain the existing message send.
6873 if (!getDerived().AlwaysRebuild() &&
6874 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006875 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006876
6877 // Build a new class message send.
6878 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
6879 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006880 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006881 E->getMethodDecl(),
6882 E->getLeftLoc(),
6883 move_arg(Args),
6884 E->getRightLoc());
6885 }
6886
6887 // Instance message: transform the receiver
6888 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
6889 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00006890 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006891 = getDerived().TransformExpr(E->getInstanceReceiver());
6892 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006893 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006894
6895 // If nothing changed, just retain the existing message send.
6896 if (!getDerived().AlwaysRebuild() &&
6897 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006898 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006899
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006900 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00006901 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006902 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00006903 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00006904 E->getMethodDecl(),
6905 E->getLeftLoc(),
6906 move_arg(Args),
6907 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006908}
6909
Mike Stump11289f42009-09-09 15:08:12 +00006910template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006911ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006912TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006913 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006914}
6915
Mike Stump11289f42009-09-09 15:08:12 +00006916template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006917ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006918TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006919 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006920}
6921
Mike Stump11289f42009-09-09 15:08:12 +00006922template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006923ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006924TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006925 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006926 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006927 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006928 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00006929
6930 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006931
Douglas Gregord51d90d2010-04-26 20:11:03 +00006932 // If nothing changed, just retain the existing expression.
6933 if (!getDerived().AlwaysRebuild() &&
6934 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006935 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006936
John McCallb268a282010-08-23 23:25:46 +00006937 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006938 E->getLocation(),
6939 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00006940}
6941
Mike Stump11289f42009-09-09 15:08:12 +00006942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006943ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006944TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00006945 // 'super' and types never change. Property never changes. Just
6946 // retain the existing expression.
6947 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00006948 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00006949
Douglas Gregor9faee212010-04-26 20:47:02 +00006950 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006951 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00006952 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006953 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006954
Douglas Gregor9faee212010-04-26 20:47:02 +00006955 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00006956
Douglas Gregor9faee212010-04-26 20:47:02 +00006957 // If nothing changed, just retain the existing expression.
6958 if (!getDerived().AlwaysRebuild() &&
6959 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006960 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006961
John McCallb7bd14f2010-12-02 01:19:52 +00006962 if (E->isExplicitProperty())
6963 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6964 E->getExplicitProperty(),
6965 E->getLocation());
6966
6967 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
6968 E->getType(),
6969 E->getImplicitPropertyGetter(),
6970 E->getImplicitPropertySetter(),
6971 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006972}
6973
Mike Stump11289f42009-09-09 15:08:12 +00006974template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006975ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006976TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00006977 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00006978 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00006979 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006980 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006981
Douglas Gregord51d90d2010-04-26 20:11:03 +00006982 // If nothing changed, just retain the existing expression.
6983 if (!getDerived().AlwaysRebuild() &&
6984 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006985 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00006986
John McCallb268a282010-08-23 23:25:46 +00006987 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00006988 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00006989}
6990
Mike Stump11289f42009-09-09 15:08:12 +00006991template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006992ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006993TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006994 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006995 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006996 SubExprs.reserve(E->getNumSubExprs());
6997 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
6998 SubExprs, &ArgumentChanged))
6999 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007000
Douglas Gregora16548e2009-08-11 05:31:07 +00007001 if (!getDerived().AlwaysRebuild() &&
7002 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007003 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007004
Douglas Gregora16548e2009-08-11 05:31:07 +00007005 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7006 move_arg(SubExprs),
7007 E->getRParenLoc());
7008}
7009
Mike Stump11289f42009-09-09 15:08:12 +00007010template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007011ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007012TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007013 SourceLocation CaretLoc(E->getExprLoc());
7014
7015 SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0);
7016 BlockScopeInfo *CurBlock = SemaRef.getCurBlock();
7017 CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic());
7018 llvm::SmallVector<ParmVarDecl*, 4> Params;
7019 llvm::SmallVector<QualType, 4> ParamTypes;
7020
7021 // Parameter substitution.
Douglas Gregorf3010112011-01-07 16:43:16 +00007022 // FIXME: Variadic templates
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007023 const BlockDecl *BD = E->getBlockDecl();
7024 for (BlockDecl::param_const_iterator P = BD->param_begin(),
7025 EN = BD->param_end(); P != EN; ++P) {
7026 ParmVarDecl *OldParm = (*P);
7027 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm);
7028 QualType NewType = NewParm->getType();
7029 Params.push_back(NewParm);
7030 ParamTypes.push_back(NewParm->getType());
7031 }
7032
7033 const FunctionType *BExprFunctionType = E->getFunctionType();
7034 QualType BExprResultType = BExprFunctionType->getResultType();
7035 if (!BExprResultType.isNull()) {
7036 if (!BExprResultType->isDependentType())
7037 CurBlock->ReturnType = BExprResultType;
7038 else if (BExprResultType != SemaRef.Context.DependentTy)
7039 CurBlock->ReturnType = getDerived().TransformType(BExprResultType);
7040 }
John McCall3882ace2011-01-05 12:14:39 +00007041
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007042 QualType FunctionType = getDerived().RebuildFunctionProtoType(
7043 CurBlock->ReturnType,
7044 ParamTypes.data(),
7045 ParamTypes.size(),
7046 BD->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007047 0,
7048 BExprFunctionType->getExtInfo());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007049 CurBlock->FunctionType = FunctionType;
John McCall3882ace2011-01-05 12:14:39 +00007050
7051 // Set the parameters on the block decl.
7052 if (!Params.empty())
7053 CurBlock->TheDecl->setParams(Params.data(), Params.size());
7054
7055 // Transform the body
7056 StmtResult Body = getDerived().TransformStmt(E->getBody());
7057 if (Body.isInvalid())
7058 return ExprError();
7059
John McCallb268a282010-08-23 23:25:46 +00007060 return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007061}
7062
Mike Stump11289f42009-09-09 15:08:12 +00007063template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007064ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007065TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007066 NestedNameSpecifier *Qualifier = 0;
7067
7068 ValueDecl *ND
7069 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7070 E->getDecl()));
7071 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007072 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007073
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007074 if (!getDerived().AlwaysRebuild() &&
7075 ND == E->getDecl()) {
7076 // Mark it referenced in the new context regardless.
7077 // FIXME: this is a bit instantiation-specific.
7078 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7079
John McCallc3007a22010-10-26 07:05:15 +00007080 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007081 }
7082
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007083 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007084 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007085 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007086}
Mike Stump11289f42009-09-09 15:08:12 +00007087
Douglas Gregora16548e2009-08-11 05:31:07 +00007088//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007089// Type reconstruction
7090//===----------------------------------------------------------------------===//
7091
Mike Stump11289f42009-09-09 15:08:12 +00007092template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007093QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7094 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007095 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007096 getDerived().getBaseEntity());
7097}
7098
Mike Stump11289f42009-09-09 15:08:12 +00007099template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007100QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7101 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007102 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007103 getDerived().getBaseEntity());
7104}
7105
Mike Stump11289f42009-09-09 15:08:12 +00007106template<typename Derived>
7107QualType
John McCall70dd5f62009-10-30 00:06:24 +00007108TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7109 bool WrittenAsLValue,
7110 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007111 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007112 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007113}
7114
7115template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007116QualType
John McCall70dd5f62009-10-30 00:06:24 +00007117TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7118 QualType ClassType,
7119 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007120 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007121 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007122}
7123
7124template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007125QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007126TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7127 ArrayType::ArraySizeModifier SizeMod,
7128 const llvm::APInt *Size,
7129 Expr *SizeExpr,
7130 unsigned IndexTypeQuals,
7131 SourceRange BracketsRange) {
7132 if (SizeExpr || !Size)
7133 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7134 IndexTypeQuals, BracketsRange,
7135 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007136
7137 QualType Types[] = {
7138 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7139 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7140 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007141 };
7142 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7143 QualType SizeType;
7144 for (unsigned I = 0; I != NumTypes; ++I)
7145 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7146 SizeType = Types[I];
7147 break;
7148 }
Mike Stump11289f42009-09-09 15:08:12 +00007149
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007150 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7151 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007152 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007153 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007154 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007155}
Mike Stump11289f42009-09-09 15:08:12 +00007156
Douglas Gregord6ff3322009-08-04 16:50:30 +00007157template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007158QualType
7159TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007160 ArrayType::ArraySizeModifier SizeMod,
7161 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007162 unsigned IndexTypeQuals,
7163 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007164 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007165 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007166}
7167
7168template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007169QualType
Mike Stump11289f42009-09-09 15:08:12 +00007170TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007171 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007172 unsigned IndexTypeQuals,
7173 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007174 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007175 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007176}
Mike Stump11289f42009-09-09 15:08:12 +00007177
Douglas Gregord6ff3322009-08-04 16:50:30 +00007178template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007179QualType
7180TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007181 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007182 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007183 unsigned IndexTypeQuals,
7184 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007185 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007186 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007187 IndexTypeQuals, BracketsRange);
7188}
7189
7190template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007191QualType
7192TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007193 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007194 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007195 unsigned IndexTypeQuals,
7196 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007197 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007198 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007199 IndexTypeQuals, BracketsRange);
7200}
7201
7202template<typename Derived>
7203QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007204 unsigned NumElements,
7205 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007206 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007207 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007208}
Mike Stump11289f42009-09-09 15:08:12 +00007209
Douglas Gregord6ff3322009-08-04 16:50:30 +00007210template<typename Derived>
7211QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7212 unsigned NumElements,
7213 SourceLocation AttributeLoc) {
7214 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7215 NumElements, true);
7216 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007217 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7218 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007219 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007220}
Mike Stump11289f42009-09-09 15:08:12 +00007221
Douglas Gregord6ff3322009-08-04 16:50:30 +00007222template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007223QualType
7224TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007225 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007226 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007227 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007228}
Mike Stump11289f42009-09-09 15:08:12 +00007229
Douglas Gregord6ff3322009-08-04 16:50:30 +00007230template<typename Derived>
7231QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007232 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007233 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007234 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007235 unsigned Quals,
7236 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007237 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007238 Quals,
7239 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007240 getDerived().getBaseEntity(),
7241 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007242}
Mike Stump11289f42009-09-09 15:08:12 +00007243
Douglas Gregord6ff3322009-08-04 16:50:30 +00007244template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007245QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7246 return SemaRef.Context.getFunctionNoProtoType(T);
7247}
7248
7249template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007250QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7251 assert(D && "no decl found");
7252 if (D->isInvalidDecl()) return QualType();
7253
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007254 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007255 TypeDecl *Ty;
7256 if (isa<UsingDecl>(D)) {
7257 UsingDecl *Using = cast<UsingDecl>(D);
7258 assert(Using->isTypeName() &&
7259 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7260
7261 // A valid resolved using typename decl points to exactly one type decl.
7262 assert(++Using->shadow_begin() == Using->shadow_end());
7263 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007264
John McCallb96ec562009-12-04 22:46:56 +00007265 } else {
7266 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7267 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7268 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7269 }
7270
7271 return SemaRef.Context.getTypeDeclType(Ty);
7272}
7273
7274template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007275QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7276 SourceLocation Loc) {
7277 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007278}
7279
7280template<typename Derived>
7281QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7282 return SemaRef.Context.getTypeOfType(Underlying);
7283}
7284
7285template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007286QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7287 SourceLocation Loc) {
7288 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007289}
7290
7291template<typename Derived>
7292QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007293 TemplateName Template,
7294 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007295 const TemplateArgumentListInfo &TemplateArgs) {
7296 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007297}
Mike Stump11289f42009-09-09 15:08:12 +00007298
Douglas Gregor1135c352009-08-06 05:28:30 +00007299template<typename Derived>
7300NestedNameSpecifier *
7301TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7302 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007303 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007304 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007305 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007306 CXXScopeSpec SS;
7307 // FIXME: The source location information is all wrong.
7308 SS.setRange(Range);
7309 SS.setScopeRep(Prefix);
7310 return static_cast<NestedNameSpecifier *>(
Mike Stump11289f42009-09-09 15:08:12 +00007311 SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(),
Douglas Gregore861bac2009-08-25 22:51:20 +00007312 Range.getEnd(), II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007313 ObjectType,
7314 FirstQualifierInScope,
Chris Lattner1c428032009-12-07 01:36:53 +00007315 false, false));
Douglas Gregor1135c352009-08-06 05:28:30 +00007316}
7317
7318template<typename Derived>
7319NestedNameSpecifier *
7320TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7321 SourceRange Range,
7322 NamespaceDecl *NS) {
7323 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7324}
7325
7326template<typename Derived>
7327NestedNameSpecifier *
7328TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7329 SourceRange Range,
7330 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007331 QualType T) {
7332 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007333 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007334 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007335 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7336 T.getTypePtr());
7337 }
Mike Stump11289f42009-09-09 15:08:12 +00007338
Douglas Gregor1135c352009-08-06 05:28:30 +00007339 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7340 return 0;
7341}
Mike Stump11289f42009-09-09 15:08:12 +00007342
Douglas Gregor71dc5092009-08-06 06:41:21 +00007343template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007344TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007345TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7346 bool TemplateKW,
7347 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007348 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007349 Template);
7350}
7351
7352template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007353TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007354TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007355 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007356 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007357 QualType ObjectType,
7358 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007359 CXXScopeSpec SS;
Douglas Gregora5614c52010-09-08 23:56:00 +00007360 SS.setRange(QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00007361 SS.setScopeRep(Qualifier);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007362 UnqualifiedId Name;
7363 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007364 Sema::TemplateTy Template;
7365 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7366 /*FIXME:*/getDerived().getBaseLocation(),
7367 SS,
7368 Name,
John McCallba7bf592010-08-24 05:47:05 +00007369 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007370 /*EnteringContext=*/false,
7371 Template);
John McCall31f82722010-11-12 08:19:04 +00007372 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007373}
Mike Stump11289f42009-09-09 15:08:12 +00007374
Douglas Gregora16548e2009-08-11 05:31:07 +00007375template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007376TemplateName
7377TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7378 OverloadedOperatorKind Operator,
7379 QualType ObjectType) {
7380 CXXScopeSpec SS;
7381 SS.setRange(SourceRange(getDerived().getBaseLocation()));
7382 SS.setScopeRep(Qualifier);
7383 UnqualifiedId Name;
7384 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7385 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7386 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007387 Sema::TemplateTy Template;
7388 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007389 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007390 SS,
7391 Name,
John McCallba7bf592010-08-24 05:47:05 +00007392 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007393 /*EnteringContext=*/false,
7394 Template);
7395 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007396}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007397
Douglas Gregor71395fa2009-11-04 00:56:37 +00007398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007399ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007400TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7401 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007402 Expr *OrigCallee,
7403 Expr *First,
7404 Expr *Second) {
7405 Expr *Callee = OrigCallee->IgnoreParenCasts();
7406 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007407
Douglas Gregora16548e2009-08-11 05:31:07 +00007408 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007409 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007410 if (!First->getType()->isOverloadableType() &&
7411 !Second->getType()->isOverloadableType())
7412 return getSema().CreateBuiltinArraySubscriptExpr(First,
7413 Callee->getLocStart(),
7414 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007415 } else if (Op == OO_Arrow) {
7416 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007417 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7418 } else if (Second == 0 || isPostIncDec) {
7419 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007420 // The argument is not of overloadable type, so try to create a
7421 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007422 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007423 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007424
John McCallb268a282010-08-23 23:25:46 +00007425 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007426 }
7427 } else {
John McCallb268a282010-08-23 23:25:46 +00007428 if (!First->getType()->isOverloadableType() &&
7429 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007430 // Neither of the arguments is an overloadable type, so try to
7431 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007432 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007433 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007434 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007435 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007436 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007437
Douglas Gregora16548e2009-08-11 05:31:07 +00007438 return move(Result);
7439 }
7440 }
Mike Stump11289f42009-09-09 15:08:12 +00007441
7442 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007443 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007444 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007445
John McCallb268a282010-08-23 23:25:46 +00007446 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007447 assert(ULE->requiresADL());
7448
7449 // FIXME: Do we have to check
7450 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007451 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007452 } else {
John McCallb268a282010-08-23 23:25:46 +00007453 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007454 }
Mike Stump11289f42009-09-09 15:08:12 +00007455
Douglas Gregora16548e2009-08-11 05:31:07 +00007456 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007457 Expr *Args[2] = { First, Second };
7458 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007459
Douglas Gregora16548e2009-08-11 05:31:07 +00007460 // Create the overloaded operator invocation for unary operators.
7461 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007462 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007463 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007464 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007465 }
Mike Stump11289f42009-09-09 15:08:12 +00007466
Sebastian Redladba46e2009-10-29 20:17:01 +00007467 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007468 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007469 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007470 First,
7471 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007472
Douglas Gregora16548e2009-08-11 05:31:07 +00007473 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007474 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007475 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007476 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7477 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007478 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007479
Mike Stump11289f42009-09-09 15:08:12 +00007480 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007481}
Mike Stump11289f42009-09-09 15:08:12 +00007482
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007483template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007484ExprResult
John McCallb268a282010-08-23 23:25:46 +00007485TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007486 SourceLocation OperatorLoc,
7487 bool isArrow,
7488 NestedNameSpecifier *Qualifier,
7489 SourceRange QualifierRange,
7490 TypeSourceInfo *ScopeType,
7491 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007492 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007493 PseudoDestructorTypeStorage Destroyed) {
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007494 CXXScopeSpec SS;
7495 if (Qualifier) {
7496 SS.setRange(QualifierRange);
7497 SS.setScopeRep(Qualifier);
7498 }
7499
John McCallb268a282010-08-23 23:25:46 +00007500 QualType BaseType = Base->getType();
7501 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007502 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007503 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007504 !BaseType->getAs<PointerType>()->getPointeeType()
7505 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007506 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007507 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007508 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007509 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007510 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007511 /*FIXME?*/true);
7512 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007513
Douglas Gregor678f90d2010-02-25 01:56:36 +00007514 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007515 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7516 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7517 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7518 NameInfo.setNamedTypeInfo(DestroyedType);
7519
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007520 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007521
John McCallb268a282010-08-23 23:25:46 +00007522 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007523 OperatorLoc, isArrow,
7524 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007525 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007526 /*TemplateArgs*/ 0);
7527}
7528
Douglas Gregord6ff3322009-08-04 16:50:30 +00007529} // end namespace clang
7530
7531#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H