blob: 99ddd239129fa9b0afa42d23eae33f968d90190d [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +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.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Douglas Gregord6ff3322009-08-04 16:50:30 +000014#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_SEMA_TREETRANSFORM_H
16
John McCall83024632010-08-25 22:03:47 +000017#include "clang/Sema/SemaInternal.h"
Douglas Gregorc3a6ade2010-08-12 20:07:10 +000018#include "clang/Sema/Lookup.h"
Douglas Gregor840bd6c2010-12-20 22:05:00 +000019#include "clang/Sema/ParsedTemplate.h"
Douglas Gregor1135c352009-08-06 05:28:30 +000020#include "clang/Sema/SemaDiagnostic.h"
John McCallaab3e412010-08-25 08:40:02 +000021#include "clang/Sema/ScopeInfo.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000022#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000023#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000024#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000025#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000026#include "clang/AST/ExprCXX.h"
27#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000028#include "clang/AST/Stmt.h"
29#include "clang/AST/StmtCXX.h"
30#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000031#include "clang/Sema/Ownership.h"
32#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000033#include "clang/Lex/Preprocessor.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000034#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000035#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000036#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000037#include <algorithm>
38
39namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000040using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000041
Douglas Gregord6ff3322009-08-04 16:50:30 +000042/// \brief A semantic tree transformation that allows one to transform one
43/// abstract syntax tree into another.
44///
Mike Stump11289f42009-09-09 15:08:12 +000045/// A new tree transformation is defined by creating a new subclass \c X of
46/// \c TreeTransform<X> and then overriding certain operations to provide
47/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000048/// instantiation is implemented as a tree transformation where the
49/// transformation of TemplateTypeParmType nodes involves substituting the
50/// template arguments for their corresponding template parameters; a similar
51/// transformation is performed for non-type template parameters and
52/// template template parameters.
53///
54/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000055/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000056/// override any of the transformation or rebuild operators by providing an
57/// operation with the same signature as the default implementation. The
58/// overridding function should not be virtual.
59///
60/// Semantic tree transformations are split into two stages, either of which
61/// can be replaced by a subclass. The "transform" step transforms an AST node
62/// or the parts of an AST node using the various transformation functions,
63/// then passes the pieces on to the "rebuild" step, which constructs a new AST
64/// node of the appropriate kind from the pieces. The default transformation
65/// routines recursively transform the operands to composite AST nodes (e.g.,
66/// the pointee type of a PointerType node) and, if any of those operand nodes
67/// were changed by the transformation, invokes the rebuild operation to create
68/// a new AST node.
69///
Mike Stump11289f42009-09-09 15:08:12 +000070/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000071/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000072/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000073/// TransformTemplateName(), or TransformTemplateArgument() with entirely
74/// new implementations.
75///
76/// For more fine-grained transformations, subclasses can replace any of the
77/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000078/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000080/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000081/// parameters. Additionally, subclasses can override the \c RebuildXXX
82/// functions to control how AST nodes are rebuilt when their operands change.
83/// By default, \c TreeTransform will invoke semantic analysis to rebuild
84/// AST nodes. However, certain other tree transformations (e.g, cloning) may
85/// be able to use more efficient rebuild steps.
86///
87/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000088/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000089/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
90/// operands have not changed (\c AlwaysRebuild()), and customize the
91/// default locations and entity names used for type-checking
92/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000093template<typename Derived>
94class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000095 /// \brief Private RAII object that helps us forget and then re-remember
96 /// the template argument corresponding to a partially-substituted parameter
97 /// pack.
98 class ForgetPartiallySubstitutedPackRAII {
99 Derived &Self;
100 TemplateArgument Old;
101
102 public:
103 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
104 Old = Self.ForgetPartiallySubstitutedPack();
105 }
106
107 ~ForgetPartiallySubstitutedPackRAII() {
108 Self.RememberPartiallySubstitutedPack(Old);
109 }
110 };
111
Douglas Gregord6ff3322009-08-04 16:50:30 +0000112protected:
113 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000114
Mike Stump11289f42009-09-09 15:08:12 +0000115public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000116 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000117 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000118
Douglas Gregord6ff3322009-08-04 16:50:30 +0000119 /// \brief Retrieves a reference to the derived class.
120 Derived &getDerived() { return static_cast<Derived&>(*this); }
121
122 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000123 const Derived &getDerived() const {
124 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 }
126
John McCalldadc5752010-08-24 06:29:42 +0000127 static inline ExprResult Owned(Expr *E) { return E; }
128 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000129
Douglas Gregord6ff3322009-08-04 16:50:30 +0000130 /// \brief Retrieves a reference to the semantic analysis object used for
131 /// this tree transform.
132 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000133
Douglas Gregord6ff3322009-08-04 16:50:30 +0000134 /// \brief Whether the transformation should always rebuild AST nodes, even
135 /// if none of the children have changed.
136 ///
137 /// Subclasses may override this function to specify when the transformation
138 /// should rebuild all AST nodes.
139 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000140
Douglas Gregord6ff3322009-08-04 16:50:30 +0000141 /// \brief Returns the location of the entity being transformed, if that
142 /// information was not available elsewhere in the AST.
143 ///
Mike Stump11289f42009-09-09 15:08:12 +0000144 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000145 /// provide an alternative implementation that provides better location
146 /// information.
147 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000148
Douglas Gregord6ff3322009-08-04 16:50:30 +0000149 /// \brief Returns the name of the entity being transformed, if that
150 /// information was not available elsewhere in the AST.
151 ///
152 /// By default, returns an empty name. Subclasses can provide an alternative
153 /// implementation with a more precise name.
154 DeclarationName getBaseEntity() { return DeclarationName(); }
155
Douglas Gregora16548e2009-08-11 05:31:07 +0000156 /// \brief Sets the "base" location and entity when that
157 /// information is known based on another transformation.
158 ///
159 /// By default, the source location and entity are ignored. Subclasses can
160 /// override this function to provide a customized implementation.
161 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000162
Douglas Gregora16548e2009-08-11 05:31:07 +0000163 /// \brief RAII object that temporarily sets the base location and entity
164 /// used for reporting diagnostics in types.
165 class TemporaryBase {
166 TreeTransform &Self;
167 SourceLocation OldLocation;
168 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000169
Douglas Gregora16548e2009-08-11 05:31:07 +0000170 public:
171 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000172 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 OldLocation = Self.getDerived().getBaseLocation();
174 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000175
176 if (Location.isValid())
177 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000178 }
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 ~TemporaryBase() {
181 Self.getDerived().setBase(OldLocation, OldEntity);
182 }
183 };
Mike Stump11289f42009-09-09 15:08:12 +0000184
185 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000186 /// transformed.
187 ///
188 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000189 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000190 /// not change. For example, template instantiation need not traverse
191 /// non-dependent types.
192 bool AlreadyTransformed(QualType T) {
193 return T.isNull();
194 }
195
Douglas Gregord196a582009-12-14 19:27:10 +0000196 /// \brief Determine whether the given call argument should be dropped, e.g.,
197 /// because it is a default argument.
198 ///
199 /// Subclasses can provide an alternative implementation of this routine to
200 /// determine which kinds of call arguments get dropped. By default,
201 /// CXXDefaultArgument nodes are dropped (prior to transformation).
202 bool DropCallArgument(Expr *E) {
203 return E->isDefaultArgument();
204 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000205
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000206 /// \brief Determine whether we should expand a pack expansion with the
207 /// given set of parameter packs into separate arguments by repeatedly
208 /// transforming the pattern.
209 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000210 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000211 /// Subclasses can override this routine to provide different behavior.
212 ///
213 /// \param EllipsisLoc The location of the ellipsis that identifies the
214 /// pack expansion.
215 ///
216 /// \param PatternRange The source range that covers the entire pattern of
217 /// the pack expansion.
218 ///
219 /// \param Unexpanded The set of unexpanded parameter packs within the
220 /// pattern.
221 ///
222 /// \param NumUnexpanded The number of unexpanded parameter packs in
223 /// \p Unexpanded.
224 ///
225 /// \param ShouldExpand Will be set to \c true if the transformer should
226 /// expand the corresponding pack expansions into separate arguments. When
227 /// set, \c NumExpansions must also be set.
228 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000229 /// \param RetainExpansion Whether the caller should add an unexpanded
230 /// pack expansion after all of the expanded arguments. This is used
231 /// when extending explicitly-specified template argument packs per
232 /// C++0x [temp.arg.explicit]p9.
233 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000234 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000235 /// the expanded form of the corresponding pack expansion. This is both an
236 /// input and an output parameter, which can be set by the caller if the
237 /// number of expansions is known a priori (e.g., due to a prior substitution)
238 /// and will be set by the callee when the number of expansions is known.
239 /// The callee must set this value when \c ShouldExpand is \c true; it may
240 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 ///
242 /// \returns true if an error occurred (e.g., because the parameter packs
243 /// are to be instantiated with arguments of different lengths), false
244 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
245 /// must be set.
246 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
247 SourceRange PatternRange,
David Blaikieb9c168a2011-09-22 02:34:54 +0000248 llvm::ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000249 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000250 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000251 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 ShouldExpand = false;
253 return false;
254 }
255
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000256 /// \brief "Forget" about the partially-substituted pack template argument,
257 /// when performing an instantiation that must preserve the parameter pack
258 /// use.
259 ///
260 /// This routine is meant to be overridden by the template instantiator.
261 TemplateArgument ForgetPartiallySubstitutedPack() {
262 return TemplateArgument();
263 }
264
265 /// \brief "Remember" the partially-substituted pack template argument
266 /// after performing an instantiation that must preserve the parameter pack
267 /// use.
268 ///
269 /// This routine is meant to be overridden by the template instantiator.
270 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
271
Douglas Gregorf3010112011-01-07 16:43:16 +0000272 /// \brief Note to the derived class when a function parameter pack is
273 /// being expanded.
274 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
275
Douglas Gregord6ff3322009-08-04 16:50:30 +0000276 /// \brief Transforms the given type into another type.
277 ///
John McCall550e0c22009-10-21 00:40:46 +0000278 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000279 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000280 /// function. This is expensive, but we don't mind, because
281 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000282 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 ///
284 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000285 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000286
John McCall550e0c22009-10-21 00:40:46 +0000287 /// \brief Transforms the given type-with-location into a new
288 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000289 ///
John McCall550e0c22009-10-21 00:40:46 +0000290 /// By default, this routine transforms a type by delegating to the
291 /// appropriate TransformXXXType to build a new type. Subclasses
292 /// may override this function (to take over all type
293 /// transformations) or some set of the TransformXXXType functions
294 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000295 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000296
297 /// \brief Transform the given type-with-location into a new
298 /// type, collecting location information in the given builder
299 /// as necessary.
300 ///
John McCall31f82722010-11-12 08:19:04 +0000301 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000302
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000303 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000304 ///
Mike Stump11289f42009-09-09 15:08:12 +0000305 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000306 /// appropriate TransformXXXStmt function to transform a specific kind of
307 /// statement or the TransformExpr() function to transform an expression.
308 /// Subclasses may override this function to transform statements using some
309 /// other mechanism.
310 ///
311 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000312 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000313
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000314 /// \brief Transform the given expression.
315 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000316 /// By default, this routine transforms an expression by delegating to the
317 /// appropriate TransformXXXExpr function to build a new expression.
318 /// Subclasses may override this function to transform expressions using some
319 /// other mechanism.
320 ///
321 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000322 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000323
Douglas Gregora3efea12011-01-03 19:04:46 +0000324 /// \brief Transform the given list of expressions.
325 ///
326 /// This routine transforms a list of expressions by invoking
327 /// \c TransformExpr() for each subexpression. However, it also provides
328 /// support for variadic templates by expanding any pack expansions (if the
329 /// derived class permits such expansion) along the way. When pack expansions
330 /// are present, the number of outputs may not equal the number of inputs.
331 ///
332 /// \param Inputs The set of expressions to be transformed.
333 ///
334 /// \param NumInputs The number of expressions in \c Inputs.
335 ///
336 /// \param IsCall If \c true, then this transform is being performed on
337 /// function-call arguments, and any arguments that should be dropped, will
338 /// be.
339 ///
340 /// \param Outputs The transformed input expressions will be added to this
341 /// vector.
342 ///
343 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
344 /// due to transformation.
345 ///
346 /// \returns true if an error occurred, false otherwise.
347 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000348 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +0000349 bool *ArgChanged = 0);
350
Douglas Gregord6ff3322009-08-04 16:50:30 +0000351 /// \brief Transform the given declaration, which is referenced from a type
352 /// or expression.
353 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000354 /// By default, acts as the identity function on declarations. Subclasses
355 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000356 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000357
358 /// \brief Transform the definition of the given declaration.
359 ///
Mike Stump11289f42009-09-09 15:08:12 +0000360 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000361 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000362 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
363 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000364 }
Mike Stump11289f42009-09-09 15:08:12 +0000365
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000366 /// \brief Transform the given declaration, which was the first part of a
367 /// nested-name-specifier in a member access expression.
368 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000369 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000370 /// identifier in a nested-name-specifier of a member access expression, e.g.,
371 /// the \c T in \c x->T::member
372 ///
373 /// By default, invokes TransformDecl() to transform the declaration.
374 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000375 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
376 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000377 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000378
Douglas Gregor14454802011-02-25 02:25:35 +0000379 /// \brief Transform the given nested-name-specifier with source-location
380 /// information.
381 ///
382 /// By default, transforms all of the types and declarations within the
383 /// nested-name-specifier. Subclasses may override this function to provide
384 /// alternate behavior.
385 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
386 NestedNameSpecifierLoc NNS,
387 QualType ObjectType = QualType(),
388 NamedDecl *FirstQualifierInScope = 0);
389
Douglas Gregorf816bd72009-09-03 22:13:48 +0000390 /// \brief Transform the given declaration name.
391 ///
392 /// By default, transforms the types of conversion function, constructor,
393 /// and destructor names and then (if needed) rebuilds the declaration name.
394 /// Identifiers and selectors are returned unmodified. Sublcasses may
395 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000396 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000397 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000398
Douglas Gregord6ff3322009-08-04 16:50:30 +0000399 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000400 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000401 /// \param SS The nested-name-specifier that qualifies the template
402 /// name. This nested-name-specifier must already have been transformed.
403 ///
404 /// \param Name The template name to transform.
405 ///
406 /// \param NameLoc The source location of the template name.
407 ///
408 /// \param ObjectType If we're translating a template name within a member
409 /// access expression, this is the type of the object whose member template
410 /// is being referenced.
411 ///
412 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
413 /// also refers to a name within the current (lexical) scope, this is the
414 /// declaration it refers to.
415 ///
416 /// By default, transforms the template name by transforming the declarations
417 /// and nested-name-specifiers that occur within the template name.
418 /// Subclasses may override this function to provide alternate behavior.
419 TemplateName TransformTemplateName(CXXScopeSpec &SS,
420 TemplateName Name,
421 SourceLocation NameLoc,
422 QualType ObjectType = QualType(),
423 NamedDecl *FirstQualifierInScope = 0);
424
Douglas Gregord6ff3322009-08-04 16:50:30 +0000425 /// \brief Transform the given template argument.
426 ///
Mike Stump11289f42009-09-09 15:08:12 +0000427 /// By default, this operation transforms the type, expression, or
428 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000429 /// new template argument from the transformed result. Subclasses may
430 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000431 ///
432 /// Returns true if there was an error.
433 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
434 TemplateArgumentLoc &Output);
435
Douglas Gregor62e06f22010-12-20 17:31:10 +0000436 /// \brief Transform the given set of template arguments.
437 ///
438 /// By default, this operation transforms all of the template arguments
439 /// in the input set using \c TransformTemplateArgument(), and appends
440 /// the transformed arguments to the output list.
441 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000442 /// Note that this overload of \c TransformTemplateArguments() is merely
443 /// a convenience function. Subclasses that wish to override this behavior
444 /// should override the iterator-based member template version.
445 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000446 /// \param Inputs The set of template arguments to be transformed.
447 ///
448 /// \param NumInputs The number of template arguments in \p Inputs.
449 ///
450 /// \param Outputs The set of transformed template arguments output by this
451 /// routine.
452 ///
453 /// Returns true if an error occurred.
454 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
455 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000456 TemplateArgumentListInfo &Outputs) {
457 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
458 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000459
460 /// \brief Transform the given set of template arguments.
461 ///
462 /// By default, this operation transforms all of the template arguments
463 /// in the input set using \c TransformTemplateArgument(), and appends
464 /// the transformed arguments to the output list.
465 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000466 /// \param First An iterator to the first template argument.
467 ///
468 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000469 ///
470 /// \param Outputs The set of transformed template arguments output by this
471 /// routine.
472 ///
473 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000474 template<typename InputIterator>
475 bool TransformTemplateArguments(InputIterator First,
476 InputIterator Last,
477 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000478
John McCall0ad16662009-10-29 08:12:44 +0000479 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
480 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
481 TemplateArgumentLoc &ArgLoc);
482
John McCallbcd03502009-12-07 02:54:59 +0000483 /// \brief Fakes up a TypeSourceInfo for a type.
484 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
485 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000486 getDerived().getBaseLocation());
487 }
Mike Stump11289f42009-09-09 15:08:12 +0000488
John McCall550e0c22009-10-21 00:40:46 +0000489#define ABSTRACT_TYPELOC(CLASS, PARENT)
490#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000491 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000492#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000493
John Wiegley1c0675e2011-04-28 01:08:34 +0000494 StmtResult
495 TransformSEHHandler(Stmt *Handler);
496
John McCall31f82722010-11-12 08:19:04 +0000497 QualType
498 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
499 TemplateSpecializationTypeLoc TL,
500 TemplateName Template);
501
502 QualType
503 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
504 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000505 TemplateName Template,
506 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000507
508 QualType
509 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000510 DependentTemplateSpecializationTypeLoc TL,
511 NestedNameSpecifierLoc QualifierLoc);
512
John McCall58f10c32010-03-11 09:03:00 +0000513 /// \brief Transforms the parameters of a function type into the
514 /// given vectors.
515 ///
516 /// The result vectors should be kept in sync; null entries in the
517 /// variables vector are acceptable.
518 ///
519 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000520 bool TransformFunctionTypeParams(SourceLocation Loc,
521 ParmVarDecl **Params, unsigned NumParams,
522 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000523 SmallVectorImpl<QualType> &PTypes,
524 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000525
526 /// \brief Transforms a single function-type parameter. Return null
527 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000528 ///
529 /// \param indexAdjustment - A number to add to the parameter's
530 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000531 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000532 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +0000533 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000534
John McCall31f82722010-11-12 08:19:04 +0000535 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000536
John McCalldadc5752010-08-24 06:29:42 +0000537 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
538 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000539
Douglas Gregorebe10102009-08-20 07:17:43 +0000540#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000541 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000542#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000543 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000544#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000545#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000546
Douglas Gregord6ff3322009-08-04 16:50:30 +0000547 /// \brief Build a new pointer type given its pointee type.
548 ///
549 /// By default, performs semantic analysis when building the pointer type.
550 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000551 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000552
553 /// \brief Build a new block pointer type given its pointee type.
554 ///
Mike Stump11289f42009-09-09 15:08:12 +0000555 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000556 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000557 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000558
John McCall70dd5f62009-10-30 00:06:24 +0000559 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000560 ///
John McCall70dd5f62009-10-30 00:06:24 +0000561 /// By default, performs semantic analysis when building the
562 /// reference type. Subclasses may override this routine to provide
563 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000564 ///
John McCall70dd5f62009-10-30 00:06:24 +0000565 /// \param LValue whether the type was written with an lvalue sigil
566 /// or an rvalue sigil.
567 QualType RebuildReferenceType(QualType ReferentType,
568 bool LValue,
569 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000570
Douglas Gregord6ff3322009-08-04 16:50:30 +0000571 /// \brief Build a new member pointer type given the pointee type and the
572 /// class type it refers into.
573 ///
574 /// By default, performs semantic analysis when building the member pointer
575 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000576 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
577 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000578
Douglas Gregord6ff3322009-08-04 16:50:30 +0000579 /// \brief Build a new array type given the element type, size
580 /// modifier, size of the array (if known), size expression, and index type
581 /// qualifiers.
582 ///
583 /// By default, performs semantic analysis when building the array type.
584 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000585 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000586 QualType RebuildArrayType(QualType ElementType,
587 ArrayType::ArraySizeModifier SizeMod,
588 const llvm::APInt *Size,
589 Expr *SizeExpr,
590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000592
Douglas Gregord6ff3322009-08-04 16:50:30 +0000593 /// \brief Build a new constant array type given the element type, size
594 /// modifier, (known) size of the array, and index type qualifiers.
595 ///
596 /// By default, performs semantic analysis when building the array type.
597 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000598 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
600 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000603
Douglas Gregord6ff3322009-08-04 16:50:30 +0000604 /// \brief Build a new incomplete array type given the element type, size
605 /// modifier, and index type qualifiers.
606 ///
607 /// By default, performs semantic analysis when building the array type.
608 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000609 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000610 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000611 unsigned IndexTypeQuals,
612 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000613
Mike Stump11289f42009-09-09 15:08:12 +0000614 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000615 /// size modifier, size expression, and index type qualifiers.
616 ///
617 /// By default, performs semantic analysis when building the array type.
618 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000619 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000620 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000621 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000622 unsigned IndexTypeQuals,
623 SourceRange BracketsRange);
624
Mike Stump11289f42009-09-09 15:08:12 +0000625 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000626 /// size modifier, size expression, and index type qualifiers.
627 ///
628 /// By default, performs semantic analysis when building the array type.
629 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000630 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000631 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000632 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000633 unsigned IndexTypeQuals,
634 SourceRange BracketsRange);
635
636 /// \brief Build a new vector type given the element type and
637 /// number of elements.
638 ///
639 /// By default, performs semantic analysis when building the vector type.
640 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000641 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000642 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000643
Douglas Gregord6ff3322009-08-04 16:50:30 +0000644 /// \brief Build a new extended vector type given the element type and
645 /// number of elements.
646 ///
647 /// By default, performs semantic analysis when building the vector type.
648 /// Subclasses may override this routine to provide different behavior.
649 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
650 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000651
652 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000653 /// given the element type and number of elements.
654 ///
655 /// By default, performs semantic analysis when building the vector type.
656 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000657 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000658 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000659 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000660
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 /// \brief Build a new function type.
662 ///
663 /// By default, performs semantic analysis when building the function type.
664 /// Subclasses may override this routine to provide different behavior.
665 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000666 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000667 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000668 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000669 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000670 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000671
John McCall550e0c22009-10-21 00:40:46 +0000672 /// \brief Build a new unprototyped function type.
673 QualType RebuildFunctionNoProtoType(QualType ResultType);
674
John McCallb96ec562009-12-04 22:46:56 +0000675 /// \brief Rebuild an unresolved typename type, given the decl that
676 /// the UnresolvedUsingTypenameDecl was transformed to.
677 QualType RebuildUnresolvedUsingType(Decl *D);
678
Douglas Gregord6ff3322009-08-04 16:50:30 +0000679 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000680 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000681 return SemaRef.Context.getTypeDeclType(Typedef);
682 }
683
684 /// \brief Build a new class/struct/union type.
685 QualType RebuildRecordType(RecordDecl *Record) {
686 return SemaRef.Context.getTypeDeclType(Record);
687 }
688
689 /// \brief Build a new Enum type.
690 QualType RebuildEnumType(EnumDecl *Enum) {
691 return SemaRef.Context.getTypeDeclType(Enum);
692 }
John McCallfcc33b02009-09-05 00:15:47 +0000693
Mike Stump11289f42009-09-09 15:08:12 +0000694 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000695 ///
696 /// By default, performs semantic analysis when building the typeof type.
697 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000698 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000699
Mike Stump11289f42009-09-09 15:08:12 +0000700 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000701 ///
702 /// By default, builds a new TypeOfType with the given underlying type.
703 QualType RebuildTypeOfType(QualType Underlying);
704
Alexis Hunte852b102011-05-24 22:41:36 +0000705 /// \brief Build a new unary transform type.
706 QualType RebuildUnaryTransformType(QualType BaseType,
707 UnaryTransformType::UTTKind UKind,
708 SourceLocation Loc);
709
Mike Stump11289f42009-09-09 15:08:12 +0000710 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000711 ///
712 /// By default, performs semantic analysis when building the decltype type.
713 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000714 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000715
Richard Smith30482bc2011-02-20 03:19:35 +0000716 /// \brief Build a new C++0x auto type.
717 ///
718 /// By default, builds a new AutoType with the given deduced type.
719 QualType RebuildAutoType(QualType Deduced) {
720 return SemaRef.Context.getAutoType(Deduced);
721 }
722
Douglas Gregord6ff3322009-08-04 16:50:30 +0000723 /// \brief Build a new template specialization type.
724 ///
725 /// By default, performs semantic analysis when building the template
726 /// specialization type. Subclasses may override this routine to provide
727 /// different behavior.
728 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000729 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000730 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000731
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000732 /// \brief Build a new parenthesized type.
733 ///
734 /// By default, builds a new ParenType type from the inner type.
735 /// Subclasses may override this routine to provide different behavior.
736 QualType RebuildParenType(QualType InnerType) {
737 return SemaRef.Context.getParenType(InnerType);
738 }
739
Douglas Gregord6ff3322009-08-04 16:50:30 +0000740 /// \brief Build a new qualified name type.
741 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000742 /// By default, builds a new ElaboratedType type from the keyword,
743 /// the nested-name-specifier and the named type.
744 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000745 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
746 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000747 NestedNameSpecifierLoc QualifierLoc,
748 QualType Named) {
749 return SemaRef.Context.getElaboratedType(Keyword,
750 QualifierLoc.getNestedNameSpecifier(),
751 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000752 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000753
754 /// \brief Build a new typename type that refers to a template-id.
755 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000756 /// By default, builds a new DependentNameType type from the
757 /// nested-name-specifier and the given type. Subclasses may override
758 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000759 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000760 ElaboratedTypeKeyword Keyword,
761 NestedNameSpecifierLoc QualifierLoc,
762 const IdentifierInfo *Name,
763 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000764 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000765 // Rebuild the template name.
766 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000767 CXXScopeSpec SS;
768 SS.Adopt(QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000769 TemplateName InstName
Douglas Gregor9db53502011-03-02 18:07:45 +0000770 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000771
772 if (InstName.isNull())
773 return QualType();
774
775 // If it's still dependent, make a dependent specialization.
776 if (InstName.getAsDependentTemplateName())
777 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
778 QualifierLoc.getNestedNameSpecifier(),
779 Name,
780 Args);
781
782 // Otherwise, make an elaborated type wrapping a non-dependent
783 // specialization.
784 QualType T =
785 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
786 if (T.isNull()) return QualType();
787
788 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0)
789 return T;
790
791 return SemaRef.Context.getElaboratedType(Keyword,
792 QualifierLoc.getNestedNameSpecifier(),
793 T);
794 }
795
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 /// \brief Build a new typename type that refers to an identifier.
797 ///
798 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000799 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000800 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000801 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000802 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000803 NestedNameSpecifierLoc QualifierLoc,
804 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000805 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000806 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000807 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000808
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000809 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000810 // If the name is still dependent, just build a new dependent name type.
811 if (!SemaRef.computeDeclContext(SS))
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000812 return SemaRef.Context.getDependentNameType(Keyword,
813 QualifierLoc.getNestedNameSpecifier(),
814 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000815 }
816
Abramo Bagnara6150c882010-05-11 21:36:43 +0000817 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000818 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000819 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000820
821 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
822
Abramo Bagnarad7548482010-05-19 21:37:53 +0000823 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000824 // into a non-dependent elaborated-type-specifier. Find the tag we're
825 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000826 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000827 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
828 if (!DC)
829 return QualType();
830
John McCallbf8c5192010-05-27 06:40:31 +0000831 if (SemaRef.RequireCompleteDeclContext(SS, DC))
832 return QualType();
833
Douglas Gregore677daf2010-03-31 22:19:08 +0000834 TagDecl *Tag = 0;
835 SemaRef.LookupQualifiedName(Result, DC);
836 switch (Result.getResultKind()) {
837 case LookupResult::NotFound:
838 case LookupResult::NotFoundInCurrentInstantiation:
839 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000840
Douglas Gregore677daf2010-03-31 22:19:08 +0000841 case LookupResult::Found:
842 Tag = Result.getAsSingle<TagDecl>();
843 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000844
Douglas Gregore677daf2010-03-31 22:19:08 +0000845 case LookupResult::FoundOverloaded:
846 case LookupResult::FoundUnresolvedValue:
847 llvm_unreachable("Tag lookup cannot find non-tags");
848 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000849
Douglas Gregore677daf2010-03-31 22:19:08 +0000850 case LookupResult::Ambiguous:
851 // Let the LookupResult structure handle ambiguities.
852 return QualType();
853 }
854
855 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000856 // Check where the name exists but isn't a tag type and use that to emit
857 // better diagnostics.
858 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
859 SemaRef.LookupQualifiedName(Result, DC);
860 switch (Result.getResultKind()) {
861 case LookupResult::Found:
862 case LookupResult::FoundOverloaded:
863 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000864 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000865 unsigned Kind = 0;
866 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000867 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
868 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +0000869 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
870 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
871 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +0000872 }
Nick Lewycky0c438082011-01-24 19:01:04 +0000873 default:
874 // FIXME: Would be nice to highlight just the source range.
875 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
876 << Kind << Id << DC;
877 break;
878 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000879 return QualType();
880 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000881
Richard Trieucaa33d32011-06-10 03:11:26 +0000882 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
883 IdLoc, *Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +0000884 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000885 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
886 return QualType();
887 }
888
889 // Build the elaborated-type-specifier type.
890 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000891 return SemaRef.Context.getElaboratedType(Keyword,
892 QualifierLoc.getNestedNameSpecifier(),
893 T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000894 }
Mike Stump11289f42009-09-09 15:08:12 +0000895
Douglas Gregor822d0302011-01-12 17:07:58 +0000896 /// \brief Build a new pack expansion type.
897 ///
898 /// By default, builds a new PackExpansionType type from the given pattern.
899 /// Subclasses may override this routine to provide different behavior.
900 QualType RebuildPackExpansionType(QualType Pattern,
901 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000902 SourceLocation EllipsisLoc,
903 llvm::Optional<unsigned> NumExpansions) {
904 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
905 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000906 }
907
Douglas Gregor71dc5092009-08-06 06:41:21 +0000908 /// \brief Build a new template name given a nested name specifier, a flag
909 /// indicating whether the "template" keyword was provided, and the template
910 /// that the template name refers to.
911 ///
912 /// By default, builds the new template name directly. Subclasses may override
913 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000914 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +0000915 bool TemplateKW,
916 TemplateDecl *Template);
917
Douglas Gregor71dc5092009-08-06 06:41:21 +0000918 /// \brief Build a new template name given a nested name specifier and the
919 /// name that is referred to as a template.
920 ///
921 /// By default, performs semantic analysis to determine whether the name can
922 /// be resolved to a specific template, then builds the appropriate kind of
923 /// template name. Subclasses may override this routine to provide different
924 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000925 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
926 const IdentifierInfo &Name,
927 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +0000928 QualType ObjectType,
929 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000930
Douglas Gregor71395fa2009-11-04 00:56:37 +0000931 /// \brief Build a new template name given a nested name specifier and the
932 /// overloaded operator name that is referred to as a template.
933 ///
934 /// By default, performs semantic analysis to determine whether the name can
935 /// be resolved to a specific template, then builds the appropriate kind of
936 /// template name. Subclasses may override this routine to provide different
937 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +0000938 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000939 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +0000940 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +0000941 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000942
943 /// \brief Build a new template name given a template template parameter pack
944 /// and the
945 ///
946 /// By default, performs semantic analysis to determine whether the name can
947 /// be resolved to a specific template, then builds the appropriate kind of
948 /// template name. Subclasses may override this routine to provide different
949 /// behavior.
950 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
951 const TemplateArgument &ArgPack) {
952 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
953 }
954
Douglas Gregorebe10102009-08-20 07:17:43 +0000955 /// \brief Build a new compound statement.
956 ///
957 /// By default, performs semantic analysis to build the new statement.
958 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000959 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000960 MultiStmtArg Statements,
961 SourceLocation RBraceLoc,
962 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000963 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000964 IsStmtExpr);
965 }
966
967 /// \brief Build a new case statement.
968 ///
969 /// By default, performs semantic analysis to build the new statement.
970 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000971 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000972 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000973 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000974 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000975 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000976 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000977 ColonLoc);
978 }
Mike Stump11289f42009-09-09 15:08:12 +0000979
Douglas Gregorebe10102009-08-20 07:17:43 +0000980 /// \brief Attach the body to a new case statement.
981 ///
982 /// By default, performs semantic analysis to build the new statement.
983 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000984 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000985 getSema().ActOnCaseStmtBody(S, Body);
986 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000987 }
Mike Stump11289f42009-09-09 15:08:12 +0000988
Douglas Gregorebe10102009-08-20 07:17:43 +0000989 /// \brief Build a new default statement.
990 ///
991 /// By default, performs semantic analysis to build the new statement.
992 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000993 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000994 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000995 Stmt *SubStmt) {
996 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000997 /*CurScope=*/0);
998 }
Mike Stump11289f42009-09-09 15:08:12 +0000999
Douglas Gregorebe10102009-08-20 07:17:43 +00001000 /// \brief Build a new label statement.
1001 ///
1002 /// By default, performs semantic analysis to build the new statement.
1003 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001004 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1005 SourceLocation ColonLoc, Stmt *SubStmt) {
1006 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001007 }
Mike Stump11289f42009-09-09 15:08:12 +00001008
Douglas Gregorebe10102009-08-20 07:17:43 +00001009 /// \brief Build a new "if" statement.
1010 ///
1011 /// By default, performs semantic analysis to build the new statement.
1012 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001013 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001014 VarDecl *CondVar, Stmt *Then,
1015 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001016 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001017 }
Mike Stump11289f42009-09-09 15:08:12 +00001018
Douglas Gregorebe10102009-08-20 07:17:43 +00001019 /// \brief Start building a new switch statement.
1020 ///
1021 /// By default, performs semantic analysis to build the new statement.
1022 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001023 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001024 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001025 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001026 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001027 }
Mike Stump11289f42009-09-09 15:08:12 +00001028
Douglas Gregorebe10102009-08-20 07:17:43 +00001029 /// \brief Attach the body to the switch statement.
1030 ///
1031 /// By default, performs semantic analysis to build the new statement.
1032 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001033 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001034 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001035 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001036 }
1037
1038 /// \brief Build a new while statement.
1039 ///
1040 /// By default, performs semantic analysis to build the new statement.
1041 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001042 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1043 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001044 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001045 }
Mike Stump11289f42009-09-09 15:08:12 +00001046
Douglas Gregorebe10102009-08-20 07:17:43 +00001047 /// \brief Build a new do-while statement.
1048 ///
1049 /// By default, performs semantic analysis to build the new statement.
1050 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001051 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001052 SourceLocation WhileLoc, SourceLocation LParenLoc,
1053 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001054 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1055 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001056 }
1057
1058 /// \brief Build a new for statement.
1059 ///
1060 /// By default, performs semantic analysis to build the new statement.
1061 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001062 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1063 Stmt *Init, Sema::FullExprArg Cond,
1064 VarDecl *CondVar, Sema::FullExprArg Inc,
1065 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001066 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001067 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001068 }
Mike Stump11289f42009-09-09 15:08:12 +00001069
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 /// \brief Build a new goto statement.
1071 ///
1072 /// By default, performs semantic analysis to build the new statement.
1073 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001074 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1075 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001076 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001077 }
1078
1079 /// \brief Build a new indirect goto statement.
1080 ///
1081 /// By default, performs semantic analysis to build the new statement.
1082 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001083 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001084 SourceLocation StarLoc,
1085 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001086 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001087 }
Mike Stump11289f42009-09-09 15:08:12 +00001088
Douglas Gregorebe10102009-08-20 07:17:43 +00001089 /// \brief Build a new return statement.
1090 ///
1091 /// By default, performs semantic analysis to build the new statement.
1092 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001093 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001094 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001095 }
Mike Stump11289f42009-09-09 15:08:12 +00001096
Douglas Gregorebe10102009-08-20 07:17:43 +00001097 /// \brief Build a new declaration statement.
1098 ///
1099 /// By default, performs semantic analysis to build the new statement.
1100 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001101 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001102 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001103 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001104 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1105 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001106 }
Mike Stump11289f42009-09-09 15:08:12 +00001107
Anders Carlssonaaeef072010-01-24 05:50:09 +00001108 /// \brief Build a new inline asm statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001112 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001113 bool IsSimple,
1114 bool IsVolatile,
1115 unsigned NumOutputs,
1116 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001117 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001118 MultiExprArg Constraints,
1119 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001120 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001121 MultiExprArg Clobbers,
1122 SourceLocation RParenLoc,
1123 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001124 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001125 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001126 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001127 RParenLoc, MSAsm);
1128 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001129
1130 /// \brief Build a new Objective-C @try statement.
1131 ///
1132 /// By default, performs semantic analysis to build the new statement.
1133 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001134 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001135 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001136 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001137 Stmt *Finally) {
1138 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1139 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001140 }
1141
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001142 /// \brief Rebuild an Objective-C exception declaration.
1143 ///
1144 /// By default, performs semantic analysis to build the new declaration.
1145 /// Subclasses may override this routine to provide different behavior.
1146 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1147 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001148 return getSema().BuildObjCExceptionDecl(TInfo, T,
1149 ExceptionDecl->getInnerLocStart(),
1150 ExceptionDecl->getLocation(),
1151 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001152 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001153
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001154 /// \brief Build a new Objective-C @catch statement.
1155 ///
1156 /// By default, performs semantic analysis to build the new statement.
1157 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001158 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001159 SourceLocation RParenLoc,
1160 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001161 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001162 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001163 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001164 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001165
Douglas Gregor306de2f2010-04-22 23:59:56 +00001166 /// \brief Build a new Objective-C @finally statement.
1167 ///
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001170 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001171 Stmt *Body) {
1172 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001173 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001174
Douglas Gregor6148de72010-04-22 22:01:21 +00001175 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001176 ///
1177 /// By default, performs semantic analysis to build the new statement.
1178 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001179 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001180 Expr *Operand) {
1181 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001182 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001183
John McCalld9bb7432011-07-27 21:50:02 +00001184 /// \brief Rebuild the operand to an Objective-C @synchronized statement.
1185 ///
1186 /// By default, performs semantic analysis to build the new statement.
1187 /// Subclasses may override this routine to provide different behavior.
1188 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1189 Expr *object) {
1190 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1191 }
1192
Douglas Gregor6148de72010-04-22 22:01:21 +00001193 /// \brief Build a new Objective-C @synchronized statement.
1194 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001195 /// By default, performs semantic analysis to build the new statement.
1196 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001197 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001198 Expr *Object, Stmt *Body) {
1199 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001200 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001201
John McCall31168b02011-06-15 23:02:42 +00001202 /// \brief Build a new Objective-C @autoreleasepool statement.
1203 ///
1204 /// By default, performs semantic analysis to build the new statement.
1205 /// Subclasses may override this routine to provide different behavior.
1206 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1207 Stmt *Body) {
1208 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1209 }
John McCall53848232011-07-27 01:07:15 +00001210
1211 /// \brief Build the collection operand to a new Objective-C fast
1212 /// enumeration statement.
1213 ///
1214 /// By default, performs semantic analysis to build the new statement.
1215 /// Subclasses may override this routine to provide different behavior.
1216 ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc,
1217 Expr *collection) {
1218 return getSema().ActOnObjCForCollectionOperand(forLoc, collection);
1219 }
John McCall31168b02011-06-15 23:02:42 +00001220
Douglas Gregorf68a5082010-04-22 23:10:45 +00001221 /// \brief Build a new Objective-C fast enumeration statement.
1222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001225 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001226 SourceLocation LParenLoc,
1227 Stmt *Element,
1228 Expr *Collection,
1229 SourceLocation RParenLoc,
1230 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001231 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001232 Element,
1233 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001234 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001235 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001236 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001237
Douglas Gregorebe10102009-08-20 07:17:43 +00001238 /// \brief Build a new C++ exception declaration.
1239 ///
1240 /// By default, performs semantic analysis to build the new decaration.
1241 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001242 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001243 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001244 SourceLocation StartLoc,
1245 SourceLocation IdLoc,
1246 IdentifierInfo *Id) {
Douglas Gregor40965fa2011-04-14 22:32:28 +00001247 VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator,
1248 StartLoc, IdLoc, Id);
1249 if (Var)
1250 getSema().CurContext->addDecl(Var);
1251 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001252 }
1253
1254 /// \brief Build a new C++ catch statement.
1255 ///
1256 /// By default, performs semantic analysis to build the new statement.
1257 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001258 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001259 VarDecl *ExceptionDecl,
1260 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001261 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1262 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001263 }
Mike Stump11289f42009-09-09 15:08:12 +00001264
Douglas Gregorebe10102009-08-20 07:17:43 +00001265 /// \brief Build a new C++ try statement.
1266 ///
1267 /// By default, performs semantic analysis to build the new statement.
1268 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001269 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001270 Stmt *TryBlock,
1271 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001272 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001273 }
Mike Stump11289f42009-09-09 15:08:12 +00001274
Richard Smith02e85f32011-04-14 22:09:26 +00001275 /// \brief Build a new C++0x range-based for statement.
1276 ///
1277 /// By default, performs semantic analysis to build the new statement.
1278 /// Subclasses may override this routine to provide different behavior.
1279 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1280 SourceLocation ColonLoc,
1281 Stmt *Range, Stmt *BeginEnd,
1282 Expr *Cond, Expr *Inc,
1283 Stmt *LoopVar,
1284 SourceLocation RParenLoc) {
1285 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
1286 Cond, Inc, LoopVar, RParenLoc);
1287 }
1288
1289 /// \brief Attach body to a C++0x range-based for statement.
1290 ///
1291 /// By default, performs semantic analysis to finish the new statement.
1292 /// Subclasses may override this routine to provide different behavior.
1293 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1294 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1295 }
1296
John Wiegley1c0675e2011-04-28 01:08:34 +00001297 StmtResult RebuildSEHTryStmt(bool IsCXXTry,
1298 SourceLocation TryLoc,
1299 Stmt *TryBlock,
1300 Stmt *Handler) {
1301 return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler);
1302 }
1303
1304 StmtResult RebuildSEHExceptStmt(SourceLocation Loc,
1305 Expr *FilterExpr,
1306 Stmt *Block) {
1307 return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block);
1308 }
1309
1310 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc,
1311 Stmt *Block) {
1312 return getSema().ActOnSEHFinallyBlock(Loc,Block);
1313 }
1314
Douglas Gregora16548e2009-08-11 05:31:07 +00001315 /// \brief Build a new expression that references a declaration.
1316 ///
1317 /// 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 RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001320 LookupResult &R,
1321 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001322 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1323 }
1324
1325
1326 /// \brief Build a new expression that references a declaration.
1327 ///
1328 /// By default, performs semantic analysis to build the new expression.
1329 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001330 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001331 ValueDecl *VD,
1332 const DeclarationNameInfo &NameInfo,
1333 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001334 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001335 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001336
1337 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001338
1339 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 }
Mike Stump11289f42009-09-09 15:08:12 +00001341
Douglas Gregora16548e2009-08-11 05:31:07 +00001342 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001343 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001344 /// By default, performs semantic analysis to build the new expression.
1345 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001346 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001347 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001348 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001349 }
1350
Douglas Gregorad8a3362009-09-04 17:36:40 +00001351 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001352 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001353 /// By default, performs semantic analysis to build the new expression.
1354 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001355 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001356 SourceLocation OperatorLoc,
1357 bool isArrow,
1358 CXXScopeSpec &SS,
1359 TypeSourceInfo *ScopeType,
1360 SourceLocation CCLoc,
1361 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001362 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001363
Douglas Gregora16548e2009-08-11 05:31:07 +00001364 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001365 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001366 /// By default, performs semantic analysis to build the new expression.
1367 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001368 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001369 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001370 Expr *SubExpr) {
1371 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001372 }
Mike Stump11289f42009-09-09 15:08:12 +00001373
Douglas Gregor882211c2010-04-28 22:16:22 +00001374 /// \brief Build a new builtin offsetof expression.
1375 ///
1376 /// By default, performs semantic analysis to build the new expression.
1377 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001378 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001379 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001380 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001381 unsigned NumComponents,
1382 SourceLocation RParenLoc) {
1383 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1384 NumComponents, RParenLoc);
1385 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001386
Peter Collingbournee190dee2011-03-11 19:24:49 +00001387 /// \brief Build a new sizeof, alignof or vec_step expression with a
1388 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001389 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001390 /// By default, performs semantic analysis to build the new expression.
1391 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001392 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1393 SourceLocation OpLoc,
1394 UnaryExprOrTypeTrait ExprKind,
1395 SourceRange R) {
1396 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001397 }
1398
Peter Collingbournee190dee2011-03-11 19:24:49 +00001399 /// \brief Build a new sizeof, alignof or vec step expression with an
1400 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001401 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001402 /// By default, performs semantic analysis to build the new expression.
1403 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001404 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1405 UnaryExprOrTypeTrait ExprKind,
1406 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001407 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001408 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001409 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001410 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001411
Douglas Gregora16548e2009-08-11 05:31:07 +00001412 return move(Result);
1413 }
Mike Stump11289f42009-09-09 15:08:12 +00001414
Douglas Gregora16548e2009-08-11 05:31:07 +00001415 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001416 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001417 /// By default, performs semantic analysis to build the new expression.
1418 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001419 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001420 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001421 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001422 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001423 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1424 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001425 RBracketLoc);
1426 }
1427
1428 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001429 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001430 /// By default, performs semantic analysis to build the new expression.
1431 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001432 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001434 SourceLocation RParenLoc,
1435 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001436 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001437 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001438 }
1439
1440 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001441 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001442 /// By default, performs semantic analysis to build the new expression.
1443 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001444 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001445 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001446 NestedNameSpecifierLoc QualifierLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001447 const DeclarationNameInfo &MemberNameInfo,
1448 ValueDecl *Member,
1449 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001450 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001451 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001452 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001453 // We have a reference to an unnamed field. This is always the
1454 // base of an anonymous struct/union member access, i.e. the
1455 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001456 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001457 assert(Member->getType()->isRecordType() &&
1458 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001459
John Wiegley01296292011-04-08 18:41:53 +00001460 ExprResult BaseResult =
1461 getSema().PerformObjectMemberConversion(Base,
1462 QualifierLoc.getNestedNameSpecifier(),
1463 FoundDecl, Member);
1464 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001465 return ExprError();
John Wiegley01296292011-04-08 18:41:53 +00001466 Base = BaseResult.take();
John McCall7decc9e2010-11-18 06:31:45 +00001467 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001468 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001469 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001470 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001471 cast<FieldDecl>(Member)->getType(),
1472 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001473 return getSema().Owned(ME);
1474 }
Mike Stump11289f42009-09-09 15:08:12 +00001475
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001476 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001477 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001478
John Wiegley01296292011-04-08 18:41:53 +00001479 ExprResult BaseResult = getSema().DefaultFunctionArrayConversion(Base);
1480 if (BaseResult.isInvalid())
1481 return ExprError();
1482 Base = BaseResult.take();
John McCallb268a282010-08-23 23:25:46 +00001483 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001484
John McCall16df1e52010-03-30 21:47:33 +00001485 // FIXME: this involves duplicating earlier analysis in a lot of
1486 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001487 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001488 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001489 R.resolveKind();
1490
John McCallb268a282010-08-23 23:25:46 +00001491 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001492 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001493 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001494 }
Mike Stump11289f42009-09-09 15:08:12 +00001495
Douglas Gregora16548e2009-08-11 05:31:07 +00001496 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001497 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001498 /// By default, performs semantic analysis to build the new expression.
1499 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001500 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001501 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001502 Expr *LHS, Expr *RHS) {
1503 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 }
1505
1506 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001507 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001508 /// By default, performs semantic analysis to build the new expression.
1509 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001510 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001511 SourceLocation QuestionLoc,
1512 Expr *LHS,
1513 SourceLocation ColonLoc,
1514 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001515 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1516 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001517 }
1518
Douglas Gregora16548e2009-08-11 05:31:07 +00001519 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001520 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 /// By default, performs semantic analysis to build the new expression.
1522 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001523 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001524 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001526 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001527 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001528 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001529 }
Mike Stump11289f42009-09-09 15:08:12 +00001530
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001532 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001533 /// By default, performs semantic analysis to build the new expression.
1534 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001535 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001536 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001537 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001538 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001539 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001540 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001541 }
Mike Stump11289f42009-09-09 15:08:12 +00001542
Douglas Gregora16548e2009-08-11 05:31:07 +00001543 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001544 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001545 /// By default, performs semantic analysis to build the new expression.
1546 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001547 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 SourceLocation OpLoc,
1549 SourceLocation AccessorLoc,
1550 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001551
John McCall10eae182009-11-30 22:42:35 +00001552 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001553 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001554 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001555 OpLoc, /*IsArrow*/ false,
1556 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001557 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001558 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001559 }
Mike Stump11289f42009-09-09 15:08:12 +00001560
Douglas Gregora16548e2009-08-11 05:31:07 +00001561 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001562 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001563 /// By default, performs semantic analysis to build the new expression.
1564 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001565 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00001566 MultiExprArg Inits,
1567 SourceLocation RBraceLoc,
1568 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001569 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001570 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1571 if (Result.isInvalid() || ResultTy->isDependentType())
1572 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001573
Douglas Gregord3d93062009-11-09 17:16:50 +00001574 // Patch in the result type we were given, which may have been computed
1575 // when the initial InitListExpr was built.
1576 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1577 ILE->setType(ResultTy);
1578 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001579 }
Mike Stump11289f42009-09-09 15:08:12 +00001580
Douglas Gregora16548e2009-08-11 05:31:07 +00001581 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00001582 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 /// By default, performs semantic analysis to build the new expression.
1584 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001585 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001586 MultiExprArg ArrayExprs,
1587 SourceLocation EqualOrColonLoc,
1588 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001589 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001590 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001591 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001592 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001593 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001594 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001595
Douglas Gregora16548e2009-08-11 05:31:07 +00001596 ArrayExprs.release();
1597 return move(Result);
1598 }
Mike Stump11289f42009-09-09 15:08:12 +00001599
Douglas Gregora16548e2009-08-11 05:31:07 +00001600 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001601 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001602 /// By default, builds the implicit value initialization without performing
1603 /// any semantic analysis. Subclasses may override this routine to provide
1604 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001605 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001606 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1607 }
Mike Stump11289f42009-09-09 15:08:12 +00001608
Douglas Gregora16548e2009-08-11 05:31:07 +00001609 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001610 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001611 /// By default, performs semantic analysis to build the new expression.
1612 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001613 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001614 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001615 SourceLocation RParenLoc) {
1616 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001617 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001618 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001619 }
1620
1621 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001622 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001623 /// By default, performs semantic analysis to build the new expression.
1624 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001625 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001626 MultiExprArg SubExprs,
1627 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001628 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001629 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001630 }
Mike Stump11289f42009-09-09 15:08:12 +00001631
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001633 ///
1634 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001635 /// rather than attempting to map the label statement itself.
1636 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001637 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001638 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001639 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001640 }
Mike Stump11289f42009-09-09 15:08:12 +00001641
Douglas Gregora16548e2009-08-11 05:31:07 +00001642 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001643 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001644 /// By default, performs semantic analysis to build the new expression.
1645 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001646 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001647 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001648 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001649 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001650 }
Mike Stump11289f42009-09-09 15:08:12 +00001651
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 /// \brief Build a new __builtin_choose_expr expression.
1653 ///
1654 /// By default, performs semantic analysis to build the new expression.
1655 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001656 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001657 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001658 SourceLocation RParenLoc) {
1659 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001660 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001661 RParenLoc);
1662 }
Mike Stump11289f42009-09-09 15:08:12 +00001663
Peter Collingbourne91147592011-04-15 00:35:48 +00001664 /// \brief Build a new generic selection expression.
1665 ///
1666 /// By default, performs semantic analysis to build the new expression.
1667 /// Subclasses may override this routine to provide different behavior.
1668 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
1669 SourceLocation DefaultLoc,
1670 SourceLocation RParenLoc,
1671 Expr *ControllingExpr,
1672 TypeSourceInfo **Types,
1673 Expr **Exprs,
1674 unsigned NumAssocs) {
1675 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
1676 ControllingExpr, Types, Exprs,
1677 NumAssocs);
1678 }
1679
Douglas Gregora16548e2009-08-11 05:31:07 +00001680 /// \brief Build a new overloaded operator call expression.
1681 ///
1682 /// By default, performs semantic analysis to build the new expression.
1683 /// The semantic analysis provides the behavior of template instantiation,
1684 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001685 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001686 /// argument-dependent lookup, etc. Subclasses may override this routine to
1687 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001688 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001689 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001690 Expr *Callee,
1691 Expr *First,
1692 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001693
1694 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001695 /// reinterpret_cast.
1696 ///
1697 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001698 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001699 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001700 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001701 Stmt::StmtClass Class,
1702 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001703 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001704 SourceLocation RAngleLoc,
1705 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001706 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001707 SourceLocation RParenLoc) {
1708 switch (Class) {
1709 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001710 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001711 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001712 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001713
1714 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001715 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001716 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001717 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001718
Douglas Gregora16548e2009-08-11 05:31:07 +00001719 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001720 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001721 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001722 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001723 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001724
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001726 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001727 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001728 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001729
Douglas Gregora16548e2009-08-11 05:31:07 +00001730 default:
David Blaikie83d382b2011-09-23 05:06:16 +00001731 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00001732 }
Mike Stump11289f42009-09-09 15:08:12 +00001733
John McCallfaf5fb42010-08-26 23:41:50 +00001734 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001735 }
Mike Stump11289f42009-09-09 15:08:12 +00001736
Douglas Gregora16548e2009-08-11 05:31:07 +00001737 /// \brief Build a new C++ static_cast expression.
1738 ///
1739 /// By default, performs semantic analysis to build the new expression.
1740 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001741 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001742 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001743 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001744 SourceLocation RAngleLoc,
1745 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001746 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001747 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001748 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001749 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001750 SourceRange(LAngleLoc, RAngleLoc),
1751 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001752 }
1753
1754 /// \brief Build a new C++ dynamic_cast expression.
1755 ///
1756 /// By default, performs semantic analysis to build the new expression.
1757 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001758 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001759 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001760 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001761 SourceLocation RAngleLoc,
1762 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001763 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001764 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001765 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001766 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001767 SourceRange(LAngleLoc, RAngleLoc),
1768 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001769 }
1770
1771 /// \brief Build a new C++ reinterpret_cast expression.
1772 ///
1773 /// By default, performs semantic analysis to build the new expression.
1774 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001775 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001776 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001777 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001778 SourceLocation RAngleLoc,
1779 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001780 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001781 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001782 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001783 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001784 SourceRange(LAngleLoc, RAngleLoc),
1785 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001786 }
1787
1788 /// \brief Build a new C++ const_cast expression.
1789 ///
1790 /// By default, performs semantic analysis to build the new expression.
1791 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001792 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001793 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001794 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001795 SourceLocation RAngleLoc,
1796 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001797 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001798 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001799 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001800 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001801 SourceRange(LAngleLoc, RAngleLoc),
1802 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001803 }
Mike Stump11289f42009-09-09 15:08:12 +00001804
Douglas Gregora16548e2009-08-11 05:31:07 +00001805 /// \brief Build a new C++ functional-style cast expression.
1806 ///
1807 /// By default, performs semantic analysis to build the new expression.
1808 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001809 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1810 SourceLocation LParenLoc,
1811 Expr *Sub,
1812 SourceLocation RParenLoc) {
1813 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001814 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001815 RParenLoc);
1816 }
Mike Stump11289f42009-09-09 15:08:12 +00001817
Douglas Gregora16548e2009-08-11 05:31:07 +00001818 /// \brief Build a new C++ typeid(type) expression.
1819 ///
1820 /// By default, performs semantic analysis to build the new expression.
1821 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001822 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001823 SourceLocation TypeidLoc,
1824 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001825 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001826 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001827 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001828 }
Mike Stump11289f42009-09-09 15:08:12 +00001829
Francois Pichet9f4f2072010-09-08 12:20:18 +00001830
Douglas Gregora16548e2009-08-11 05:31:07 +00001831 /// \brief Build a new C++ typeid(expr) expression.
1832 ///
1833 /// By default, performs semantic analysis to build the new expression.
1834 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001835 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001836 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001837 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001838 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001839 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001840 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001841 }
1842
Francois Pichet9f4f2072010-09-08 12:20:18 +00001843 /// \brief Build a new C++ __uuidof(type) expression.
1844 ///
1845 /// By default, performs semantic analysis to build the new expression.
1846 /// Subclasses may override this routine to provide different behavior.
1847 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1848 SourceLocation TypeidLoc,
1849 TypeSourceInfo *Operand,
1850 SourceLocation RParenLoc) {
1851 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1852 RParenLoc);
1853 }
1854
1855 /// \brief Build a new C++ __uuidof(expr) expression.
1856 ///
1857 /// By default, performs semantic analysis to build the new expression.
1858 /// Subclasses may override this routine to provide different behavior.
1859 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1860 SourceLocation TypeidLoc,
1861 Expr *Operand,
1862 SourceLocation RParenLoc) {
1863 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1864 RParenLoc);
1865 }
1866
Douglas Gregora16548e2009-08-11 05:31:07 +00001867 /// \brief Build a new C++ "this" expression.
1868 ///
1869 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001870 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001871 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001872 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001873 QualType ThisType,
1874 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001875 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001876 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1877 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001878 }
1879
1880 /// \brief Build a new C++ throw expression.
1881 ///
1882 /// By default, performs semantic analysis to build the new expression.
1883 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00001884 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
1885 bool IsThrownVariableInScope) {
1886 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00001887 }
1888
1889 /// \brief Build a new C++ default-argument expression.
1890 ///
1891 /// By default, builds a new default-argument expression, which does not
1892 /// require any semantic analysis. Subclasses may override this routine to
1893 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001894 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001895 ParmVarDecl *Param) {
1896 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1897 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001898 }
1899
1900 /// \brief Build a new C++ zero-initialization expression.
1901 ///
1902 /// By default, performs semantic analysis to build the new expression.
1903 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001904 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1905 SourceLocation LParenLoc,
1906 SourceLocation RParenLoc) {
1907 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001908 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001909 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001910 }
Mike Stump11289f42009-09-09 15:08:12 +00001911
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 /// \brief Build a new C++ "new" expression.
1913 ///
1914 /// By default, performs semantic analysis to build the new expression.
1915 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001916 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001917 bool UseGlobal,
1918 SourceLocation PlacementLParen,
1919 MultiExprArg PlacementArgs,
1920 SourceLocation PlacementRParen,
1921 SourceRange TypeIdParens,
1922 QualType AllocatedType,
1923 TypeSourceInfo *AllocatedTypeInfo,
1924 Expr *ArraySize,
1925 SourceLocation ConstructorLParen,
1926 MultiExprArg ConstructorArgs,
1927 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001928 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001929 PlacementLParen,
1930 move(PlacementArgs),
1931 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001932 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001933 AllocatedType,
1934 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001935 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 ConstructorLParen,
1937 move(ConstructorArgs),
1938 ConstructorRParen);
1939 }
Mike Stump11289f42009-09-09 15:08:12 +00001940
Douglas Gregora16548e2009-08-11 05:31:07 +00001941 /// \brief Build a new C++ "delete" expression.
1942 ///
1943 /// By default, performs semantic analysis to build the new expression.
1944 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001945 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001946 bool IsGlobalDelete,
1947 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001948 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001950 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001951 }
Mike Stump11289f42009-09-09 15:08:12 +00001952
Douglas Gregora16548e2009-08-11 05:31:07 +00001953 /// \brief Build a new unary type trait expression.
1954 ///
1955 /// By default, performs semantic analysis to build the new expression.
1956 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001957 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001958 SourceLocation StartLoc,
1959 TypeSourceInfo *T,
1960 SourceLocation RParenLoc) {
1961 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001962 }
1963
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001964 /// \brief Build a new binary type trait expression.
1965 ///
1966 /// By default, performs semantic analysis to build the new expression.
1967 /// Subclasses may override this routine to provide different behavior.
1968 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1969 SourceLocation StartLoc,
1970 TypeSourceInfo *LhsT,
1971 TypeSourceInfo *RhsT,
1972 SourceLocation RParenLoc) {
1973 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1974 }
1975
John Wiegley6242b6a2011-04-28 00:16:57 +00001976 /// \brief Build a new array type trait expression.
1977 ///
1978 /// By default, performs semantic analysis to build the new expression.
1979 /// Subclasses may override this routine to provide different behavior.
1980 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
1981 SourceLocation StartLoc,
1982 TypeSourceInfo *TSInfo,
1983 Expr *DimExpr,
1984 SourceLocation RParenLoc) {
1985 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
1986 }
1987
John Wiegleyf9f65842011-04-25 06:54:41 +00001988 /// \brief Build a new expression trait expression.
1989 ///
1990 /// By default, performs semantic analysis to build the new expression.
1991 /// Subclasses may override this routine to provide different behavior.
1992 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
1993 SourceLocation StartLoc,
1994 Expr *Queried,
1995 SourceLocation RParenLoc) {
1996 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
1997 }
1998
Mike Stump11289f42009-09-09 15:08:12 +00001999 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002000 /// expression.
2001 ///
2002 /// By default, performs semantic analysis to build the new expression.
2003 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002004 ExprResult RebuildDependentScopeDeclRefExpr(
2005 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002006 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00002007 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002008 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002009 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002010
2011 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002012 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00002013 *TemplateArgs);
2014
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002015 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 }
2017
2018 /// \brief Build a new template-id expression.
2019 ///
2020 /// By default, performs semantic analysis to build the new expression.
2021 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002022 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00002023 LookupResult &R,
2024 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00002025 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00002026 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002027 }
2028
2029 /// \brief Build a new object-construction expression.
2030 ///
2031 /// By default, performs semantic analysis to build the new expression.
2032 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002033 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002034 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002035 CXXConstructorDecl *Constructor,
2036 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002037 MultiExprArg Args,
2038 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002039 CXXConstructExpr::ConstructionKind ConstructKind,
2040 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00002041 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002042 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002043 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002044 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002045
Douglas Gregordb121ba2009-12-14 16:27:04 +00002046 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00002047 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00002048 RequiresZeroInit, ConstructKind,
2049 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 }
2051
2052 /// \brief Build a new object-construction expression.
2053 ///
2054 /// By default, performs semantic analysis to build the new expression.
2055 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002056 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2057 SourceLocation LParenLoc,
2058 MultiExprArg Args,
2059 SourceLocation RParenLoc) {
2060 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002061 LParenLoc,
2062 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002063 RParenLoc);
2064 }
2065
2066 /// \brief Build a new object-construction expression.
2067 ///
2068 /// By default, performs semantic analysis to build the new expression.
2069 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002070 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2071 SourceLocation LParenLoc,
2072 MultiExprArg Args,
2073 SourceLocation RParenLoc) {
2074 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002075 LParenLoc,
2076 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00002077 RParenLoc);
2078 }
Mike Stump11289f42009-09-09 15:08:12 +00002079
Douglas Gregora16548e2009-08-11 05:31:07 +00002080 /// \brief Build a new member reference expression.
2081 ///
2082 /// By default, performs semantic analysis to build the new expression.
2083 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002084 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002085 QualType BaseType,
2086 bool IsArrow,
2087 SourceLocation OperatorLoc,
2088 NestedNameSpecifierLoc QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00002089 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002090 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002091 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002092 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002093 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002094
John McCallb268a282010-08-23 23:25:46 +00002095 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002096 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00002097 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002098 MemberNameInfo,
2099 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002100 }
2101
John McCall10eae182009-11-30 22:42:35 +00002102 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002103 ///
2104 /// By default, performs semantic analysis to build the new expression.
2105 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002106 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00002107 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00002108 SourceLocation OperatorLoc,
2109 bool IsArrow,
Douglas Gregor0da1d432011-02-28 20:01:57 +00002110 NestedNameSpecifierLoc QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00002111 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002112 LookupResult &R,
2113 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002114 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002115 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002116
John McCallb268a282010-08-23 23:25:46 +00002117 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002118 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002119 SS, FirstQualifierInScope,
2120 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002121 }
Mike Stump11289f42009-09-09 15:08:12 +00002122
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002123 /// \brief Build a new noexcept expression.
2124 ///
2125 /// By default, performs semantic analysis to build the new expression.
2126 /// Subclasses may override this routine to provide different behavior.
2127 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2128 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2129 }
2130
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002131 /// \brief Build a new expression to compute the length of a parameter pack.
2132 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2133 SourceLocation PackLoc,
2134 SourceLocation RParenLoc,
2135 unsigned Length) {
2136 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2137 OperatorLoc, Pack, PackLoc,
2138 RParenLoc, Length);
2139 }
2140
Douglas Gregora16548e2009-08-11 05:31:07 +00002141 /// \brief Build a new Objective-C @encode expression.
2142 ///
2143 /// By default, performs semantic analysis to build the new expression.
2144 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002145 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002146 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002148 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002149 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002150 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002151
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002152 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002153 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002154 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002155 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002156 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002157 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002158 MultiExprArg Args,
2159 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002160 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2161 ReceiverTypeInfo->getType(),
2162 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002163 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002164 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002165 }
2166
2167 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002168 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002169 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002170 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002171 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002172 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002173 MultiExprArg Args,
2174 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002175 return SemaRef.BuildInstanceMessage(Receiver,
2176 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002177 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002178 Sel, Method, LBracLoc, SelectorLocs,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002179 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002180 }
2181
Douglas Gregord51d90d2010-04-26 20:11:03 +00002182 /// \brief Build a new Objective-C ivar reference expression.
2183 ///
2184 /// By default, performs semantic analysis to build the new expression.
2185 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002186 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002187 SourceLocation IvarLoc,
2188 bool IsArrow, bool IsFreeIvar) {
2189 // FIXME: We lose track of the IsFreeIvar bit.
2190 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002191 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002192 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2193 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002194 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002195 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002196 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002197 false);
John Wiegley01296292011-04-08 18:41:53 +00002198 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002199 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002200
Douglas Gregord51d90d2010-04-26 20:11:03 +00002201 if (Result.get())
2202 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002203
John Wiegley01296292011-04-08 18:41:53 +00002204 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002205 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002206 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002207 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002208 /*TemplateArgs=*/0);
2209 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002210
2211 /// \brief Build a new Objective-C property reference expression.
2212 ///
2213 /// By default, performs semantic analysis to build the new expression.
2214 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002215 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002216 ObjCPropertyDecl *Property,
2217 SourceLocation PropertyLoc) {
2218 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002219 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregor9faee212010-04-26 20:47:02 +00002220 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2221 Sema::LookupMemberName);
2222 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002223 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002224 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002225 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002226 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002227 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002228
Douglas Gregor9faee212010-04-26 20:47:02 +00002229 if (Result.get())
2230 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002231
John Wiegley01296292011-04-08 18:41:53 +00002232 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002233 /*FIXME:*/PropertyLoc, IsArrow,
2234 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002235 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002236 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002237 /*TemplateArgs=*/0);
2238 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002239
John McCallb7bd14f2010-12-02 01:19:52 +00002240 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002241 ///
2242 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002243 /// Subclasses may override this routine to provide different behavior.
2244 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2245 ObjCMethodDecl *Getter,
2246 ObjCMethodDecl *Setter,
2247 SourceLocation PropertyLoc) {
2248 // Since these expressions can only be value-dependent, we do not
2249 // need to perform semantic analysis again.
2250 return Owned(
2251 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2252 VK_LValue, OK_ObjCProperty,
2253 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002254 }
2255
Douglas Gregord51d90d2010-04-26 20:11:03 +00002256 /// \brief Build a new Objective-C "isa" expression.
2257 ///
2258 /// By default, performs semantic analysis to build the new expression.
2259 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002260 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002261 bool IsArrow) {
2262 CXXScopeSpec SS;
John Wiegley01296292011-04-08 18:41:53 +00002263 ExprResult Base = getSema().Owned(BaseArg);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002264 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2265 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002266 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002267 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002268 SS, 0, false);
John Wiegley01296292011-04-08 18:41:53 +00002269 if (Result.isInvalid() || Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002270 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002271
Douglas Gregord51d90d2010-04-26 20:11:03 +00002272 if (Result.get())
2273 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002274
John Wiegley01296292011-04-08 18:41:53 +00002275 return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002276 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002277 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002278 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002279 /*TemplateArgs=*/0);
2280 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002281
Douglas Gregora16548e2009-08-11 05:31:07 +00002282 /// \brief Build a new shuffle vector expression.
2283 ///
2284 /// By default, performs semantic analysis to build the new expression.
2285 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002286 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002287 MultiExprArg SubExprs,
2288 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002289 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002290 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002291 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2292 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2293 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2294 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002295
Douglas Gregora16548e2009-08-11 05:31:07 +00002296 // Build a reference to the __builtin_shufflevector builtin
2297 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
John Wiegley01296292011-04-08 18:41:53 +00002298 ExprResult Callee
2299 = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
2300 VK_LValue, BuiltinLoc));
2301 Callee = SemaRef.UsualUnaryConversions(Callee.take());
2302 if (Callee.isInvalid())
2303 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002304
2305 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002306 unsigned NumSubExprs = SubExprs.size();
2307 Expr **Subs = (Expr **)SubExprs.release();
John Wiegley01296292011-04-08 18:41:53 +00002308 ExprResult TheCall = SemaRef.Owned(
2309 new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(),
Douglas Gregora16548e2009-08-11 05:31:07 +00002310 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002311 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002312 Expr::getValueKindForType(Builtin->getResultType()),
John Wiegley01296292011-04-08 18:41:53 +00002313 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002314
Douglas Gregora16548e2009-08-11 05:31:07 +00002315 // Type-check the __builtin_shufflevector expression.
John Wiegley01296292011-04-08 18:41:53 +00002316 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002317 }
John McCall31f82722010-11-12 08:19:04 +00002318
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002319 /// \brief Build a new template argument pack expansion.
2320 ///
2321 /// By default, performs semantic analysis to build a new pack expansion
2322 /// for a template argument. Subclasses may override this routine to provide
2323 /// different behavior.
2324 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002325 SourceLocation EllipsisLoc,
2326 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002327 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002328 case TemplateArgument::Expression: {
2329 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002330 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2331 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002332 if (Result.isInvalid())
2333 return TemplateArgumentLoc();
2334
2335 return TemplateArgumentLoc(Result.get(), Result.get());
2336 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002337
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002338 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002339 return TemplateArgumentLoc(TemplateArgument(
2340 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002341 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002342 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002343 Pattern.getTemplateNameLoc(),
2344 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002345
2346 case TemplateArgument::Null:
2347 case TemplateArgument::Integral:
2348 case TemplateArgument::Declaration:
2349 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002350 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002351 llvm_unreachable("Pack expansion pattern has no parameter packs");
2352
2353 case TemplateArgument::Type:
2354 if (TypeSourceInfo *Expansion
2355 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002356 EllipsisLoc,
2357 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002358 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2359 Expansion);
2360 break;
2361 }
2362
2363 return TemplateArgumentLoc();
2364 }
2365
Douglas Gregor968f23a2011-01-03 19:31:53 +00002366 /// \brief Build a new expression pack expansion.
2367 ///
2368 /// By default, performs semantic analysis to build a new pack expansion
2369 /// for an expression. Subclasses may override this routine to provide
2370 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002371 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2372 llvm::Optional<unsigned> NumExpansions) {
2373 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002374 }
2375
John McCall31f82722010-11-12 08:19:04 +00002376private:
Douglas Gregor14454802011-02-25 02:25:35 +00002377 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2378 QualType ObjectType,
2379 NamedDecl *FirstQualifierInScope,
2380 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002381
2382 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2383 QualType ObjectType,
2384 NamedDecl *FirstQualifierInScope,
2385 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002386};
Douglas Gregora16548e2009-08-11 05:31:07 +00002387
Douglas Gregorebe10102009-08-20 07:17:43 +00002388template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002389StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002390 if (!S)
2391 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002392
Douglas Gregorebe10102009-08-20 07:17:43 +00002393 switch (S->getStmtClass()) {
2394 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002395
Douglas Gregorebe10102009-08-20 07:17:43 +00002396 // Transform individual statement nodes
2397#define STMT(Node, Parent) \
2398 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002399#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002400#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002401#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002402
Douglas Gregorebe10102009-08-20 07:17:43 +00002403 // Transform expressions by calling TransformExpr.
2404#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002405#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002406#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002407#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002408 {
John McCalldadc5752010-08-24 06:29:42 +00002409 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002410 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002411 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002412
John McCallb268a282010-08-23 23:25:46 +00002413 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002414 }
Mike Stump11289f42009-09-09 15:08:12 +00002415 }
2416
John McCallc3007a22010-10-26 07:05:15 +00002417 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002418}
Mike Stump11289f42009-09-09 15:08:12 +00002419
2420
Douglas Gregore922c772009-08-04 22:27:00 +00002421template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002422ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002423 if (!E)
2424 return SemaRef.Owned(E);
2425
2426 switch (E->getStmtClass()) {
2427 case Stmt::NoStmtClass: break;
2428#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002429#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002430#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002431 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002432#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002433 }
2434
John McCallc3007a22010-10-26 07:05:15 +00002435 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002436}
2437
2438template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002439bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2440 unsigned NumInputs,
2441 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00002442 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00002443 bool *ArgChanged) {
2444 for (unsigned I = 0; I != NumInputs; ++I) {
2445 // If requested, drop call arguments that need to be dropped.
2446 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2447 if (ArgChanged)
2448 *ArgChanged = true;
2449
2450 break;
2451 }
2452
Douglas Gregor968f23a2011-01-03 19:31:53 +00002453 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2454 Expr *Pattern = Expansion->getPattern();
2455
Chris Lattner01cf8db2011-07-20 06:58:45 +00002456 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002457 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2458 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2459
2460 // Determine whether the set of unexpanded parameter packs can and should
2461 // be expanded.
2462 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002463 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002464 llvm::Optional<unsigned> OrigNumExpansions
2465 = Expansion->getNumExpansions();
2466 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002467 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2468 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00002469 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002470 Expand, RetainExpansion,
2471 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002472 return true;
2473
2474 if (!Expand) {
2475 // The transform has determined that we should perform a simple
2476 // transformation on the pack expansion, producing another pack
2477 // expansion.
2478 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2479 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2480 if (OutPattern.isInvalid())
2481 return true;
2482
2483 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002484 Expansion->getEllipsisLoc(),
2485 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002486 if (Out.isInvalid())
2487 return true;
2488
2489 if (ArgChanged)
2490 *ArgChanged = true;
2491 Outputs.push_back(Out.get());
2492 continue;
2493 }
John McCall542e7c62011-07-06 07:30:07 +00002494
2495 // Record right away that the argument was changed. This needs
2496 // to happen even if the array expands to nothing.
2497 if (ArgChanged) *ArgChanged = true;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002498
2499 // The transform has determined that we should perform an elementwise
2500 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002501 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002502 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2503 ExprResult Out = getDerived().TransformExpr(Pattern);
2504 if (Out.isInvalid())
2505 return true;
2506
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002507 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002508 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2509 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002510 if (Out.isInvalid())
2511 return true;
2512 }
2513
Douglas Gregor968f23a2011-01-03 19:31:53 +00002514 Outputs.push_back(Out.get());
2515 }
2516
2517 continue;
2518 }
2519
Douglas Gregora3efea12011-01-03 19:04:46 +00002520 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2521 if (Result.isInvalid())
2522 return true;
2523
2524 if (Result.get() != Inputs[I] && ArgChanged)
2525 *ArgChanged = true;
2526
2527 Outputs.push_back(Result.get());
2528 }
2529
2530 return false;
2531}
2532
2533template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002534NestedNameSpecifierLoc
2535TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2536 NestedNameSpecifierLoc NNS,
2537 QualType ObjectType,
2538 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002539 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Douglas Gregor14454802011-02-25 02:25:35 +00002540 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2541 Qualifier = Qualifier.getPrefix())
2542 Qualifiers.push_back(Qualifier);
2543
2544 CXXScopeSpec SS;
2545 while (!Qualifiers.empty()) {
2546 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2547 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2548
2549 switch (QNNS->getKind()) {
2550 case NestedNameSpecifier::Identifier:
2551 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2552 *QNNS->getAsIdentifier(),
2553 Q.getLocalBeginLoc(),
2554 Q.getLocalEndLoc(),
2555 ObjectType, false, SS,
2556 FirstQualifierInScope, false))
2557 return NestedNameSpecifierLoc();
2558
2559 break;
2560
2561 case NestedNameSpecifier::Namespace: {
2562 NamespaceDecl *NS
2563 = cast_or_null<NamespaceDecl>(
2564 getDerived().TransformDecl(
2565 Q.getLocalBeginLoc(),
2566 QNNS->getAsNamespace()));
2567 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2568 break;
2569 }
2570
2571 case NestedNameSpecifier::NamespaceAlias: {
2572 NamespaceAliasDecl *Alias
2573 = cast_or_null<NamespaceAliasDecl>(
2574 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2575 QNNS->getAsNamespaceAlias()));
2576 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2577 Q.getLocalEndLoc());
2578 break;
2579 }
2580
2581 case NestedNameSpecifier::Global:
2582 // There is no meaningful transformation that one could perform on the
2583 // global scope.
2584 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2585 break;
2586
2587 case NestedNameSpecifier::TypeSpecWithTemplate:
2588 case NestedNameSpecifier::TypeSpec: {
2589 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2590 FirstQualifierInScope, SS);
2591
2592 if (!TL)
2593 return NestedNameSpecifierLoc();
2594
2595 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2596 (SemaRef.getLangOptions().CPlusPlus0x &&
2597 TL.getType()->isEnumeralType())) {
2598 assert(!TL.getType().hasLocalQualifiers() &&
2599 "Can't get cv-qualifiers here");
2600 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2601 Q.getLocalEndLoc());
2602 break;
2603 }
Richard Trieude756fb2011-05-07 01:36:37 +00002604 // If the nested-name-specifier is an invalid type def, don't emit an
2605 // error because a previous error should have already been emitted.
2606 TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL);
2607 if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) {
2608 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2609 << TL.getType() << SS.getRange();
2610 }
Douglas Gregor14454802011-02-25 02:25:35 +00002611 return NestedNameSpecifierLoc();
2612 }
Douglas Gregore16af532011-02-28 18:50:33 +00002613 }
Douglas Gregor14454802011-02-25 02:25:35 +00002614
Douglas Gregore16af532011-02-28 18:50:33 +00002615 // The qualifier-in-scope and object type only apply to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002616 FirstQualifierInScope = 0;
Douglas Gregore16af532011-02-28 18:50:33 +00002617 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00002618 }
2619
2620 // Don't rebuild the nested-name-specifier if we don't have to.
2621 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2622 !getDerived().AlwaysRebuild())
2623 return NNS;
2624
2625 // If we can re-use the source-location data from the original
2626 // nested-name-specifier, do so.
2627 if (SS.location_size() == NNS.getDataLength() &&
2628 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2629 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2630
2631 // Allocate new nested-name-specifier location information.
2632 return SS.getWithLocInContext(SemaRef.Context);
2633}
2634
2635template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002636DeclarationNameInfo
2637TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002638::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002639 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002640 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002641 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002642
2643 switch (Name.getNameKind()) {
2644 case DeclarationName::Identifier:
2645 case DeclarationName::ObjCZeroArgSelector:
2646 case DeclarationName::ObjCOneArgSelector:
2647 case DeclarationName::ObjCMultiArgSelector:
2648 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002649 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002650 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002651 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002652
Douglas Gregorf816bd72009-09-03 22:13:48 +00002653 case DeclarationName::CXXConstructorName:
2654 case DeclarationName::CXXDestructorName:
2655 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002656 TypeSourceInfo *NewTInfo;
2657 CanQualType NewCanTy;
2658 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002659 NewTInfo = getDerived().TransformType(OldTInfo);
2660 if (!NewTInfo)
2661 return DeclarationNameInfo();
2662 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002663 }
2664 else {
2665 NewTInfo = 0;
2666 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002667 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002668 if (NewT.isNull())
2669 return DeclarationNameInfo();
2670 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2671 }
Mike Stump11289f42009-09-09 15:08:12 +00002672
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002673 DeclarationName NewName
2674 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2675 NewCanTy);
2676 DeclarationNameInfo NewNameInfo(NameInfo);
2677 NewNameInfo.setName(NewName);
2678 NewNameInfo.setNamedTypeInfo(NewTInfo);
2679 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002680 }
Mike Stump11289f42009-09-09 15:08:12 +00002681 }
2682
David Blaikie83d382b2011-09-23 05:06:16 +00002683 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00002684}
2685
2686template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002687TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00002688TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
2689 TemplateName Name,
2690 SourceLocation NameLoc,
2691 QualType ObjectType,
2692 NamedDecl *FirstQualifierInScope) {
2693 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
2694 TemplateDecl *Template = QTN->getTemplateDecl();
2695 assert(Template && "qualified template name must refer to a template");
2696
2697 TemplateDecl *TransTemplate
2698 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2699 Template));
2700 if (!TransTemplate)
2701 return TemplateName();
2702
2703 if (!getDerived().AlwaysRebuild() &&
2704 SS.getScopeRep() == QTN->getQualifier() &&
2705 TransTemplate == Template)
2706 return Name;
2707
2708 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
2709 TransTemplate);
2710 }
2711
2712 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
2713 if (SS.getScopeRep()) {
2714 // These apply to the scope specifier, not the template.
2715 ObjectType = QualType();
2716 FirstQualifierInScope = 0;
2717 }
2718
2719 if (!getDerived().AlwaysRebuild() &&
2720 SS.getScopeRep() == DTN->getQualifier() &&
2721 ObjectType.isNull())
2722 return Name;
2723
2724 if (DTN->isIdentifier()) {
2725 return getDerived().RebuildTemplateName(SS,
2726 *DTN->getIdentifier(),
2727 NameLoc,
2728 ObjectType,
2729 FirstQualifierInScope);
2730 }
2731
2732 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
2733 ObjectType);
2734 }
2735
2736 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
2737 TemplateDecl *TransTemplate
2738 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
2739 Template));
2740 if (!TransTemplate)
2741 return TemplateName();
2742
2743 if (!getDerived().AlwaysRebuild() &&
2744 TransTemplate == Template)
2745 return Name;
2746
2747 return TemplateName(TransTemplate);
2748 }
2749
2750 if (SubstTemplateTemplateParmPackStorage *SubstPack
2751 = Name.getAsSubstTemplateTemplateParmPack()) {
2752 TemplateTemplateParmDecl *TransParam
2753 = cast_or_null<TemplateTemplateParmDecl>(
2754 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
2755 if (!TransParam)
2756 return TemplateName();
2757
2758 if (!getDerived().AlwaysRebuild() &&
2759 TransParam == SubstPack->getParameterPack())
2760 return Name;
2761
2762 return getDerived().RebuildTemplateName(TransParam,
2763 SubstPack->getArgumentPack());
2764 }
2765
2766 // These should be getting filtered out before they reach the AST.
2767 llvm_unreachable("overloaded function decl survived to here");
2768 return TemplateName();
2769}
2770
2771template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00002772void TreeTransform<Derived>::InventTemplateArgumentLoc(
2773 const TemplateArgument &Arg,
2774 TemplateArgumentLoc &Output) {
2775 SourceLocation Loc = getDerived().getBaseLocation();
2776 switch (Arg.getKind()) {
2777 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00002778 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00002779 break;
2780
2781 case TemplateArgument::Type:
2782 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00002783 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Alexis Hunta8136cc2010-05-05 15:23:54 +00002784
John McCall0ad16662009-10-29 08:12:44 +00002785 break;
2786
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002787 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00002788 case TemplateArgument::TemplateExpansion: {
2789 NestedNameSpecifierLocBuilder Builder;
2790 TemplateName Template = Arg.getAsTemplate();
2791 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
2792 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
2793 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
2794 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
2795
2796 if (Arg.getKind() == TemplateArgument::Template)
2797 Output = TemplateArgumentLoc(Arg,
2798 Builder.getWithLocInContext(SemaRef.Context),
2799 Loc);
2800 else
2801 Output = TemplateArgumentLoc(Arg,
2802 Builder.getWithLocInContext(SemaRef.Context),
2803 Loc, Loc);
2804
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002805 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00002806 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002807
John McCall0ad16662009-10-29 08:12:44 +00002808 case TemplateArgument::Expression:
2809 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2810 break;
2811
2812 case TemplateArgument::Declaration:
2813 case TemplateArgument::Integral:
2814 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002815 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002816 break;
2817 }
2818}
2819
2820template<typename Derived>
2821bool TreeTransform<Derived>::TransformTemplateArgument(
2822 const TemplateArgumentLoc &Input,
2823 TemplateArgumentLoc &Output) {
2824 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002825 switch (Arg.getKind()) {
2826 case TemplateArgument::Null:
2827 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002828 Output = Input;
2829 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002830
Douglas Gregore922c772009-08-04 22:27:00 +00002831 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002832 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002833 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002834 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002835
2836 DI = getDerived().TransformType(DI);
2837 if (!DI) return true;
2838
2839 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2840 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002841 }
Mike Stump11289f42009-09-09 15:08:12 +00002842
Douglas Gregore922c772009-08-04 22:27:00 +00002843 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002844 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002845 DeclarationName Name;
2846 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2847 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002848 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002849 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002850 if (!D) return true;
2851
John McCall0d07eb32009-10-29 18:45:58 +00002852 Expr *SourceExpr = Input.getSourceDeclExpression();
2853 if (SourceExpr) {
2854 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002855 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002856 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002857 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002858 }
2859
2860 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002861 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002862 }
Mike Stump11289f42009-09-09 15:08:12 +00002863
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002864 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00002865 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
2866 if (QualifierLoc) {
2867 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
2868 if (!QualifierLoc)
2869 return true;
2870 }
2871
Douglas Gregordf846d12011-03-02 18:46:51 +00002872 CXXScopeSpec SS;
2873 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002874 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00002875 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
2876 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002877 if (Template.isNull())
2878 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002879
Douglas Gregor9d802122011-03-02 17:09:35 +00002880 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002881 Input.getTemplateNameLoc());
2882 return false;
2883 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002884
2885 case TemplateArgument::TemplateExpansion:
2886 llvm_unreachable("Caller should expand pack expansions");
2887
Douglas Gregore922c772009-08-04 22:27:00 +00002888 case TemplateArgument::Expression: {
2889 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002890 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002891 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002892
John McCall0ad16662009-10-29 08:12:44 +00002893 Expr *InputExpr = Input.getSourceExpression();
2894 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2895
Chris Lattnercdb591a2011-04-25 20:37:58 +00002896 ExprResult E = getDerived().TransformExpr(InputExpr);
John McCall0ad16662009-10-29 08:12:44 +00002897 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002898 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002899 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002900 }
Mike Stump11289f42009-09-09 15:08:12 +00002901
Douglas Gregore922c772009-08-04 22:27:00 +00002902 case TemplateArgument::Pack: {
Chris Lattner01cf8db2011-07-20 06:58:45 +00002903 SmallVector<TemplateArgument, 4> TransformedArgs;
Douglas Gregore922c772009-08-04 22:27:00 +00002904 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002905 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002906 AEnd = Arg.pack_end();
2907 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002908
John McCall0ad16662009-10-29 08:12:44 +00002909 // FIXME: preserve source information here when we start
2910 // caring about parameter packs.
2911
John McCall0d07eb32009-10-29 18:45:58 +00002912 TemplateArgumentLoc InputArg;
2913 TemplateArgumentLoc OutputArg;
2914 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2915 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002916 return true;
2917
John McCall0d07eb32009-10-29 18:45:58 +00002918 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002919 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002920
2921 TemplateArgument *TransformedArgsPtr
2922 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2923 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2924 TransformedArgsPtr);
2925 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2926 TransformedArgs.size()),
2927 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002928 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002929 }
2930 }
Mike Stump11289f42009-09-09 15:08:12 +00002931
Douglas Gregore922c772009-08-04 22:27:00 +00002932 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002933 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002934}
2935
Douglas Gregorfe921a72010-12-20 23:36:19 +00002936/// \brief Iterator adaptor that invents template argument location information
2937/// for each of the template arguments in its underlying iterator.
2938template<typename Derived, typename InputIterator>
2939class TemplateArgumentLocInventIterator {
2940 TreeTransform<Derived> &Self;
2941 InputIterator Iter;
2942
2943public:
2944 typedef TemplateArgumentLoc value_type;
2945 typedef TemplateArgumentLoc reference;
2946 typedef typename std::iterator_traits<InputIterator>::difference_type
2947 difference_type;
2948 typedef std::input_iterator_tag iterator_category;
2949
2950 class pointer {
2951 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002952
Douglas Gregorfe921a72010-12-20 23:36:19 +00002953 public:
2954 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2955
2956 const TemplateArgumentLoc *operator->() const { return &Arg; }
2957 };
2958
2959 TemplateArgumentLocInventIterator() { }
2960
2961 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2962 InputIterator Iter)
2963 : Self(Self), Iter(Iter) { }
2964
2965 TemplateArgumentLocInventIterator &operator++() {
2966 ++Iter;
2967 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002968 }
2969
Douglas Gregorfe921a72010-12-20 23:36:19 +00002970 TemplateArgumentLocInventIterator operator++(int) {
2971 TemplateArgumentLocInventIterator Old(*this);
2972 ++(*this);
2973 return Old;
2974 }
2975
2976 reference operator*() const {
2977 TemplateArgumentLoc Result;
2978 Self.InventTemplateArgumentLoc(*Iter, Result);
2979 return Result;
2980 }
2981
2982 pointer operator->() const { return pointer(**this); }
2983
2984 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2985 const TemplateArgumentLocInventIterator &Y) {
2986 return X.Iter == Y.Iter;
2987 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002988
Douglas Gregorfe921a72010-12-20 23:36:19 +00002989 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2990 const TemplateArgumentLocInventIterator &Y) {
2991 return X.Iter != Y.Iter;
2992 }
2993};
2994
Douglas Gregor42cafa82010-12-20 17:42:22 +00002995template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002996template<typename InputIterator>
2997bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2998 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002999 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003000 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003001 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003002 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003003
3004 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3005 // Unpack argument packs, which we translate them into separate
3006 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003007 // FIXME: We could do much better if we could guarantee that the
3008 // TemplateArgumentLocInfo for the pack expansion would be usable for
3009 // all of the template arguments in the argument pack.
3010 typedef TemplateArgumentLocInventIterator<Derived,
3011 TemplateArgument::pack_iterator>
3012 PackLocIterator;
3013 if (TransformTemplateArguments(PackLocIterator(*this,
3014 In.getArgument().pack_begin()),
3015 PackLocIterator(*this,
3016 In.getArgument().pack_end()),
3017 Outputs))
3018 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003019
3020 continue;
3021 }
3022
3023 if (In.getArgument().isPackExpansion()) {
3024 // We have a pack expansion, for which we will be substituting into
3025 // the pattern.
3026 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003027 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003028 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003029 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3030 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003031
Chris Lattner01cf8db2011-07-20 06:58:45 +00003032 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003033 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3034 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3035
3036 // Determine whether the set of unexpanded parameter packs can and should
3037 // be expanded.
3038 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003039 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003040 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003041 if (getDerived().TryExpandParameterPacks(Ellipsis,
3042 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003043 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003044 Expand,
3045 RetainExpansion,
3046 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003047 return true;
3048
3049 if (!Expand) {
3050 // The transform has determined that we should perform a simple
3051 // transformation on the pack expansion, producing another pack
3052 // expansion.
3053 TemplateArgumentLoc OutPattern;
3054 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3055 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3056 return true;
3057
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003058 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3059 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003060 if (Out.getArgument().isNull())
3061 return true;
3062
3063 Outputs.addArgument(Out);
3064 continue;
3065 }
3066
3067 // The transform has determined that we should perform an elementwise
3068 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003069 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003070 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3071
3072 if (getDerived().TransformTemplateArgument(Pattern, Out))
3073 return true;
3074
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003075 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003076 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3077 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003078 if (Out.getArgument().isNull())
3079 return true;
3080 }
3081
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003082 Outputs.addArgument(Out);
3083 }
3084
Douglas Gregor48d24112011-01-10 20:53:55 +00003085 // If we're supposed to retain a pack expansion, do so by temporarily
3086 // forgetting the partially-substituted parameter pack.
3087 if (RetainExpansion) {
3088 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3089
3090 if (getDerived().TransformTemplateArgument(Pattern, Out))
3091 return true;
3092
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003093 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3094 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003095 if (Out.getArgument().isNull())
3096 return true;
3097
3098 Outputs.addArgument(Out);
3099 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003100
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003101 continue;
3102 }
3103
3104 // The simple case:
3105 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003106 return true;
3107
3108 Outputs.addArgument(Out);
3109 }
3110
3111 return false;
3112
3113}
3114
Douglas Gregord6ff3322009-08-04 16:50:30 +00003115//===----------------------------------------------------------------------===//
3116// Type transformation
3117//===----------------------------------------------------------------------===//
3118
3119template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003120QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003121 if (getDerived().AlreadyTransformed(T))
3122 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003123
John McCall550e0c22009-10-21 00:40:46 +00003124 // Temporary workaround. All of these transformations should
3125 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003126 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3127 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003128
John McCall31f82722010-11-12 08:19:04 +00003129 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003130
John McCall550e0c22009-10-21 00:40:46 +00003131 if (!NewDI)
3132 return QualType();
3133
3134 return NewDI->getType();
3135}
3136
3137template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003138TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003139 if (getDerived().AlreadyTransformed(DI->getType()))
3140 return DI;
3141
3142 TypeLocBuilder TLB;
3143
3144 TypeLoc TL = DI->getTypeLoc();
3145 TLB.reserve(TL.getFullDataSize());
3146
John McCall31f82722010-11-12 08:19:04 +00003147 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003148 if (Result.isNull())
3149 return 0;
3150
John McCallbcd03502009-12-07 02:54:59 +00003151 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003152}
3153
3154template<typename Derived>
3155QualType
John McCall31f82722010-11-12 08:19:04 +00003156TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003157 switch (T.getTypeLocClass()) {
3158#define ABSTRACT_TYPELOC(CLASS, PARENT)
3159#define TYPELOC(CLASS, PARENT) \
3160 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003161 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003162#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003163 }
Mike Stump11289f42009-09-09 15:08:12 +00003164
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003165 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003166 return QualType();
3167}
3168
3169/// FIXME: By default, this routine adds type qualifiers only to types
3170/// that can have qualifiers, and silently suppresses those qualifiers
3171/// that are not permitted (e.g., qualifiers on reference or function
3172/// types). This is the right thing for template instantiation, but
3173/// probably not for other clients.
3174template<typename Derived>
3175QualType
3176TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003177 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003178 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003179
John McCall31f82722010-11-12 08:19:04 +00003180 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003181 if (Result.isNull())
3182 return QualType();
3183
3184 // Silently suppress qualifiers if the result type can't be qualified.
3185 // FIXME: this is the right thing for template instantiation, but
3186 // probably not for other clients.
3187 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003188 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003189
John McCall31168b02011-06-15 23:02:42 +00003190 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003191 // resulting type.
3192 if (Quals.hasObjCLifetime()) {
3193 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3194 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003195 else if (Result.getObjCLifetime()) {
Douglas Gregore46db902011-06-17 22:11:49 +00003196 // Objective-C ARC:
3197 // A lifetime qualifier applied to a substituted template parameter
3198 // overrides the lifetime qualifier from the template argument.
3199 if (const SubstTemplateTypeParmType *SubstTypeParam
3200 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3201 QualType Replacement = SubstTypeParam->getReplacementType();
3202 Qualifiers Qs = Replacement.getQualifiers();
3203 Qs.removeObjCLifetime();
3204 Replacement
3205 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3206 Qs);
3207 Result = SemaRef.Context.getSubstTemplateTypeParmType(
3208 SubstTypeParam->getReplacedParameter(),
3209 Replacement);
3210 TLB.TypeWasModifiedSafely(Result);
3211 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003212 // Otherwise, complain about the addition of a qualifier to an
3213 // already-qualified type.
3214 SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003215 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003216 << Result << R;
3217
Douglas Gregore46db902011-06-17 22:11:49 +00003218 Quals.removeObjCLifetime();
3219 }
3220 }
3221 }
John McCallcb0f89a2010-06-05 06:41:15 +00003222 if (!Quals.empty()) {
3223 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3224 TLB.push<QualifiedTypeLoc>(Result);
3225 // No location information to preserve.
3226 }
John McCall550e0c22009-10-21 00:40:46 +00003227
3228 return Result;
3229}
3230
Douglas Gregor14454802011-02-25 02:25:35 +00003231template<typename Derived>
3232TypeLoc
3233TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3234 QualType ObjectType,
3235 NamedDecl *UnqualLookup,
3236 CXXScopeSpec &SS) {
Douglas Gregor14454802011-02-25 02:25:35 +00003237 QualType T = TL.getType();
3238 if (getDerived().AlreadyTransformed(T))
3239 return TL;
3240
3241 TypeLocBuilder TLB;
3242 QualType Result;
3243
3244 if (isa<TemplateSpecializationType>(T)) {
3245 TemplateSpecializationTypeLoc SpecTL
3246 = cast<TemplateSpecializationTypeLoc>(TL);
3247
3248 TemplateName Template =
Douglas Gregor9db53502011-03-02 18:07:45 +00003249 getDerived().TransformTemplateName(SS,
3250 SpecTL.getTypePtr()->getTemplateName(),
3251 SpecTL.getTemplateNameLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003252 ObjectType, UnqualLookup);
3253 if (Template.isNull())
3254 return TypeLoc();
3255
3256 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3257 Template);
3258 } else if (isa<DependentTemplateSpecializationType>(T)) {
3259 DependentTemplateSpecializationTypeLoc SpecTL
3260 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3261
Douglas Gregor5a064722011-02-28 17:23:35 +00003262 TemplateName Template
Douglas Gregor9db53502011-03-02 18:07:45 +00003263 = getDerived().RebuildTemplateName(SS,
Douglas Gregore16af532011-02-28 18:50:33 +00003264 *SpecTL.getTypePtr()->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003265 SpecTL.getNameLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00003266 ObjectType, UnqualLookup);
Douglas Gregor5a064722011-02-28 17:23:35 +00003267 if (Template.isNull())
3268 return TypeLoc();
3269
Douglas Gregor14454802011-02-25 02:25:35 +00003270 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor5a064722011-02-28 17:23:35 +00003271 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003272 Template,
3273 SS);
Douglas Gregor14454802011-02-25 02:25:35 +00003274 } else {
3275 // Nothing special needs to be done for these.
3276 Result = getDerived().TransformType(TLB, TL);
3277 }
3278
3279 if (Result.isNull())
3280 return TypeLoc();
3281
3282 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3283}
3284
Douglas Gregor579c15f2011-03-02 18:32:08 +00003285template<typename Derived>
3286TypeSourceInfo *
3287TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3288 QualType ObjectType,
3289 NamedDecl *UnqualLookup,
3290 CXXScopeSpec &SS) {
3291 // FIXME: Painfully copy-paste from the above!
3292
3293 QualType T = TSInfo->getType();
3294 if (getDerived().AlreadyTransformed(T))
3295 return TSInfo;
3296
3297 TypeLocBuilder TLB;
3298 QualType Result;
3299
3300 TypeLoc TL = TSInfo->getTypeLoc();
3301 if (isa<TemplateSpecializationType>(T)) {
3302 TemplateSpecializationTypeLoc SpecTL
3303 = cast<TemplateSpecializationTypeLoc>(TL);
3304
3305 TemplateName Template
3306 = getDerived().TransformTemplateName(SS,
3307 SpecTL.getTypePtr()->getTemplateName(),
3308 SpecTL.getTemplateNameLoc(),
3309 ObjectType, UnqualLookup);
3310 if (Template.isNull())
3311 return 0;
3312
3313 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3314 Template);
3315 } else if (isa<DependentTemplateSpecializationType>(T)) {
3316 DependentTemplateSpecializationTypeLoc SpecTL
3317 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3318
3319 TemplateName Template
3320 = getDerived().RebuildTemplateName(SS,
3321 *SpecTL.getTypePtr()->getIdentifier(),
3322 SpecTL.getNameLoc(),
3323 ObjectType, UnqualLookup);
3324 if (Template.isNull())
3325 return 0;
3326
3327 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3328 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003329 Template,
3330 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003331 } else {
3332 // Nothing special needs to be done for these.
3333 Result = getDerived().TransformType(TLB, TL);
3334 }
3335
3336 if (Result.isNull())
3337 return 0;
3338
3339 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3340}
3341
John McCall550e0c22009-10-21 00:40:46 +00003342template <class TyLoc> static inline
3343QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3344 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3345 NewT.setNameLoc(T.getNameLoc());
3346 return T.getType();
3347}
3348
John McCall550e0c22009-10-21 00:40:46 +00003349template<typename Derived>
3350QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003351 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003352 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3353 NewT.setBuiltinLoc(T.getBuiltinLoc());
3354 if (T.needsExtraLocalData())
3355 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3356 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003357}
Mike Stump11289f42009-09-09 15:08:12 +00003358
Douglas Gregord6ff3322009-08-04 16:50:30 +00003359template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003360QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003361 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003362 // FIXME: recurse?
3363 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003364}
Mike Stump11289f42009-09-09 15:08:12 +00003365
Douglas Gregord6ff3322009-08-04 16:50:30 +00003366template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003367QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003368 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003369 QualType PointeeType
3370 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003371 if (PointeeType.isNull())
3372 return QualType();
3373
3374 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003375 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003376 // A dependent pointer type 'T *' has is being transformed such
3377 // that an Objective-C class type is being replaced for 'T'. The
3378 // resulting pointer type is an ObjCObjectPointerType, not a
3379 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003380 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003381
John McCall8b07ec22010-05-15 11:32:37 +00003382 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3383 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003384 return Result;
3385 }
John McCall31f82722010-11-12 08:19:04 +00003386
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003387 if (getDerived().AlwaysRebuild() ||
3388 PointeeType != TL.getPointeeLoc().getType()) {
3389 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3390 if (Result.isNull())
3391 return QualType();
3392 }
John McCall31168b02011-06-15 23:02:42 +00003393
3394 // Objective-C ARC can add lifetime qualifiers to the type that we're
3395 // pointing to.
3396 TLB.TypeWasModifiedSafely(Result->getPointeeType());
3397
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003398 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3399 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003400 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003401}
Mike Stump11289f42009-09-09 15:08:12 +00003402
3403template<typename Derived>
3404QualType
John McCall550e0c22009-10-21 00:40:46 +00003405TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003406 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003407 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003408 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3409 if (PointeeType.isNull())
3410 return QualType();
3411
3412 QualType Result = TL.getType();
3413 if (getDerived().AlwaysRebuild() ||
3414 PointeeType != TL.getPointeeLoc().getType()) {
3415 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003416 TL.getSigilLoc());
3417 if (Result.isNull())
3418 return QualType();
3419 }
3420
Douglas Gregor049211a2010-04-22 16:50:51 +00003421 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003422 NewT.setSigilLoc(TL.getSigilLoc());
3423 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003424}
3425
John McCall70dd5f62009-10-30 00:06:24 +00003426/// Transforms a reference type. Note that somewhat paradoxically we
3427/// don't care whether the type itself is an l-value type or an r-value
3428/// type; we only care if the type was *written* as an l-value type
3429/// or an r-value type.
3430template<typename Derived>
3431QualType
3432TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003433 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003434 const ReferenceType *T = TL.getTypePtr();
3435
3436 // Note that this works with the pointee-as-written.
3437 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3438 if (PointeeType.isNull())
3439 return QualType();
3440
3441 QualType Result = TL.getType();
3442 if (getDerived().AlwaysRebuild() ||
3443 PointeeType != T->getPointeeTypeAsWritten()) {
3444 Result = getDerived().RebuildReferenceType(PointeeType,
3445 T->isSpelledAsLValue(),
3446 TL.getSigilLoc());
3447 if (Result.isNull())
3448 return QualType();
3449 }
3450
John McCall31168b02011-06-15 23:02:42 +00003451 // Objective-C ARC can add lifetime qualifiers to the type that we're
3452 // referring to.
3453 TLB.TypeWasModifiedSafely(
3454 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
3455
John McCall70dd5f62009-10-30 00:06:24 +00003456 // r-value references can be rebuilt as l-value references.
3457 ReferenceTypeLoc NewTL;
3458 if (isa<LValueReferenceType>(Result))
3459 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3460 else
3461 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3462 NewTL.setSigilLoc(TL.getSigilLoc());
3463
3464 return Result;
3465}
3466
Mike Stump11289f42009-09-09 15:08:12 +00003467template<typename Derived>
3468QualType
John McCall550e0c22009-10-21 00:40:46 +00003469TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003470 LValueReferenceTypeLoc TL) {
3471 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003472}
3473
Mike Stump11289f42009-09-09 15:08:12 +00003474template<typename Derived>
3475QualType
John McCall550e0c22009-10-21 00:40:46 +00003476TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003477 RValueReferenceTypeLoc TL) {
3478 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003479}
Mike Stump11289f42009-09-09 15:08:12 +00003480
Douglas Gregord6ff3322009-08-04 16:50:30 +00003481template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003482QualType
John McCall550e0c22009-10-21 00:40:46 +00003483TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003484 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00003485 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003486 if (PointeeType.isNull())
3487 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003488
Abramo Bagnara509357842011-03-05 14:42:21 +00003489 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
3490 TypeSourceInfo* NewClsTInfo = 0;
3491 if (OldClsTInfo) {
3492 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
3493 if (!NewClsTInfo)
3494 return QualType();
3495 }
3496
3497 const MemberPointerType *T = TL.getTypePtr();
3498 QualType OldClsType = QualType(T->getClass(), 0);
3499 QualType NewClsType;
3500 if (NewClsTInfo)
3501 NewClsType = NewClsTInfo->getType();
3502 else {
3503 NewClsType = getDerived().TransformType(OldClsType);
3504 if (NewClsType.isNull())
3505 return QualType();
3506 }
Mike Stump11289f42009-09-09 15:08:12 +00003507
John McCall550e0c22009-10-21 00:40:46 +00003508 QualType Result = TL.getType();
3509 if (getDerived().AlwaysRebuild() ||
3510 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00003511 NewClsType != OldClsType) {
3512 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00003513 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003514 if (Result.isNull())
3515 return QualType();
3516 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003517
John McCall550e0c22009-10-21 00:40:46 +00003518 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3519 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00003520 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00003521
3522 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003523}
3524
Mike Stump11289f42009-09-09 15:08:12 +00003525template<typename Derived>
3526QualType
John McCall550e0c22009-10-21 00:40:46 +00003527TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003528 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003529 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003530 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003531 if (ElementType.isNull())
3532 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003533
John McCall550e0c22009-10-21 00:40:46 +00003534 QualType Result = TL.getType();
3535 if (getDerived().AlwaysRebuild() ||
3536 ElementType != T->getElementType()) {
3537 Result = getDerived().RebuildConstantArrayType(ElementType,
3538 T->getSizeModifier(),
3539 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003540 T->getIndexTypeCVRQualifiers(),
3541 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003542 if (Result.isNull())
3543 return QualType();
3544 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003545
John McCall550e0c22009-10-21 00:40:46 +00003546 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3547 NewTL.setLBracketLoc(TL.getLBracketLoc());
3548 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003549
John McCall550e0c22009-10-21 00:40:46 +00003550 Expr *Size = TL.getSizeExpr();
3551 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003552 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003553 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3554 }
3555 NewTL.setSizeExpr(Size);
3556
3557 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003558}
Mike Stump11289f42009-09-09 15:08:12 +00003559
Douglas Gregord6ff3322009-08-04 16:50:30 +00003560template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003561QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003562 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003563 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003564 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003565 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003566 if (ElementType.isNull())
3567 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003568
John McCall550e0c22009-10-21 00:40:46 +00003569 QualType Result = TL.getType();
3570 if (getDerived().AlwaysRebuild() ||
3571 ElementType != T->getElementType()) {
3572 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003573 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003574 T->getIndexTypeCVRQualifiers(),
3575 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003576 if (Result.isNull())
3577 return QualType();
3578 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003579
John McCall550e0c22009-10-21 00:40:46 +00003580 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3581 NewTL.setLBracketLoc(TL.getLBracketLoc());
3582 NewTL.setRBracketLoc(TL.getRBracketLoc());
3583 NewTL.setSizeExpr(0);
3584
3585 return Result;
3586}
3587
3588template<typename Derived>
3589QualType
3590TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003591 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003592 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003593 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3594 if (ElementType.isNull())
3595 return QualType();
3596
3597 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003598 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003599
John McCalldadc5752010-08-24 06:29:42 +00003600 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003601 = getDerived().TransformExpr(T->getSizeExpr());
3602 if (SizeResult.isInvalid())
3603 return QualType();
3604
John McCallb268a282010-08-23 23:25:46 +00003605 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003606
3607 QualType Result = TL.getType();
3608 if (getDerived().AlwaysRebuild() ||
3609 ElementType != T->getElementType() ||
3610 Size != T->getSizeExpr()) {
3611 Result = getDerived().RebuildVariableArrayType(ElementType,
3612 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003613 Size,
John McCall550e0c22009-10-21 00:40:46 +00003614 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003615 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003616 if (Result.isNull())
3617 return QualType();
3618 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003619
John McCall550e0c22009-10-21 00:40:46 +00003620 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3621 NewTL.setLBracketLoc(TL.getLBracketLoc());
3622 NewTL.setRBracketLoc(TL.getRBracketLoc());
3623 NewTL.setSizeExpr(Size);
3624
3625 return Result;
3626}
3627
3628template<typename Derived>
3629QualType
3630TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003631 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003632 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003633 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3634 if (ElementType.isNull())
3635 return QualType();
3636
3637 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003638 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003639
John McCall33ddac02011-01-19 10:06:00 +00003640 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3641 Expr *origSize = TL.getSizeExpr();
3642 if (!origSize) origSize = T->getSizeExpr();
3643
3644 ExprResult sizeResult
3645 = getDerived().TransformExpr(origSize);
3646 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003647 return QualType();
3648
John McCall33ddac02011-01-19 10:06:00 +00003649 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003650
3651 QualType Result = TL.getType();
3652 if (getDerived().AlwaysRebuild() ||
3653 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003654 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003655 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3656 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003657 size,
John McCall550e0c22009-10-21 00:40:46 +00003658 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003659 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003660 if (Result.isNull())
3661 return QualType();
3662 }
John McCall550e0c22009-10-21 00:40:46 +00003663
3664 // We might have any sort of array type now, but fortunately they
3665 // all have the same location layout.
3666 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3667 NewTL.setLBracketLoc(TL.getLBracketLoc());
3668 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003669 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003670
3671 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003672}
Mike Stump11289f42009-09-09 15:08:12 +00003673
3674template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003675QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003676 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003677 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003678 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003679
3680 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003681 QualType ElementType = getDerived().TransformType(T->getElementType());
3682 if (ElementType.isNull())
3683 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003684
Douglas Gregore922c772009-08-04 22:27:00 +00003685 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003686 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003687
John McCalldadc5752010-08-24 06:29:42 +00003688 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003689 if (Size.isInvalid())
3690 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003691
John McCall550e0c22009-10-21 00:40:46 +00003692 QualType Result = TL.getType();
3693 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003694 ElementType != T->getElementType() ||
3695 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003696 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003697 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003698 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003699 if (Result.isNull())
3700 return QualType();
3701 }
John McCall550e0c22009-10-21 00:40:46 +00003702
3703 // Result might be dependent or not.
3704 if (isa<DependentSizedExtVectorType>(Result)) {
3705 DependentSizedExtVectorTypeLoc NewTL
3706 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3707 NewTL.setNameLoc(TL.getNameLoc());
3708 } else {
3709 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3710 NewTL.setNameLoc(TL.getNameLoc());
3711 }
3712
3713 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003714}
Mike Stump11289f42009-09-09 15:08:12 +00003715
3716template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003717QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003718 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003719 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003720 QualType ElementType = getDerived().TransformType(T->getElementType());
3721 if (ElementType.isNull())
3722 return QualType();
3723
John McCall550e0c22009-10-21 00:40:46 +00003724 QualType Result = TL.getType();
3725 if (getDerived().AlwaysRebuild() ||
3726 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003727 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003728 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003729 if (Result.isNull())
3730 return QualType();
3731 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003732
John McCall550e0c22009-10-21 00:40:46 +00003733 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3734 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003735
John McCall550e0c22009-10-21 00:40:46 +00003736 return Result;
3737}
3738
3739template<typename Derived>
3740QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003741 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003742 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003743 QualType ElementType = getDerived().TransformType(T->getElementType());
3744 if (ElementType.isNull())
3745 return QualType();
3746
3747 QualType Result = TL.getType();
3748 if (getDerived().AlwaysRebuild() ||
3749 ElementType != T->getElementType()) {
3750 Result = getDerived().RebuildExtVectorType(ElementType,
3751 T->getNumElements(),
3752 /*FIXME*/ SourceLocation());
3753 if (Result.isNull())
3754 return QualType();
3755 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003756
John McCall550e0c22009-10-21 00:40:46 +00003757 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3758 NewTL.setNameLoc(TL.getNameLoc());
3759
3760 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003761}
Mike Stump11289f42009-09-09 15:08:12 +00003762
3763template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003764ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003765TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003766 int indexAdjustment,
Douglas Gregor715e4612011-01-14 22:40:04 +00003767 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003768 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003769 TypeSourceInfo *NewDI = 0;
3770
3771 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3772 // If we're substituting into a pack expansion type and we know the
3773 TypeLoc OldTL = OldDI->getTypeLoc();
3774 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3775
3776 TypeLocBuilder TLB;
3777 TypeLoc NewTL = OldDI->getTypeLoc();
3778 TLB.reserve(NewTL.getFullDataSize());
3779
3780 QualType Result = getDerived().TransformType(TLB,
3781 OldExpansionTL.getPatternLoc());
3782 if (Result.isNull())
3783 return 0;
3784
3785 Result = RebuildPackExpansionType(Result,
3786 OldExpansionTL.getPatternLoc().getSourceRange(),
3787 OldExpansionTL.getEllipsisLoc(),
3788 NumExpansions);
3789 if (Result.isNull())
3790 return 0;
3791
3792 PackExpansionTypeLoc NewExpansionTL
3793 = TLB.push<PackExpansionTypeLoc>(Result);
3794 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3795 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3796 } else
3797 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003798 if (!NewDI)
3799 return 0;
3800
John McCall8fb0d9d2011-05-01 22:35:37 +00003801 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00003802 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00003803
3804 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
3805 OldParm->getDeclContext(),
3806 OldParm->getInnerLocStart(),
3807 OldParm->getLocation(),
3808 OldParm->getIdentifier(),
3809 NewDI->getType(),
3810 NewDI,
3811 OldParm->getStorageClass(),
3812 OldParm->getStorageClassAsWritten(),
3813 /* DefArg */ NULL);
3814 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
3815 OldParm->getFunctionScopeIndex() + indexAdjustment);
3816 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00003817}
3818
3819template<typename Derived>
3820bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003821 TransformFunctionTypeParams(SourceLocation Loc,
3822 ParmVarDecl **Params, unsigned NumParams,
3823 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003824 SmallVectorImpl<QualType> &OutParamTypes,
3825 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003826 int indexAdjustment = 0;
3827
Douglas Gregordd472162011-01-07 00:20:55 +00003828 for (unsigned i = 0; i != NumParams; ++i) {
3829 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00003830 assert(OldParm->getFunctionScopeIndex() == i);
3831
Douglas Gregor715e4612011-01-14 22:40:04 +00003832 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003833 ParmVarDecl *NewParm = 0;
Douglas Gregor5499af42011-01-05 23:12:31 +00003834 if (OldParm->isParameterPack()) {
3835 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00003836 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003837
Douglas Gregor5499af42011-01-05 23:12:31 +00003838 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003839 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3840 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3841 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3842 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00003843 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
3844
Douglas Gregor5499af42011-01-05 23:12:31 +00003845 // Determine whether we should expand the parameter packs.
3846 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003847 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003848 llvm::Optional<unsigned> OrigNumExpansions
3849 = ExpansionTL.getTypePtr()->getNumExpansions();
3850 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003851 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3852 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003853 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003854 ShouldExpand,
3855 RetainExpansion,
3856 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003857 return true;
3858 }
3859
3860 if (ShouldExpand) {
3861 // Expand the function parameter pack into multiple, separate
3862 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003863 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003864 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003865 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3866 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003867 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003868 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003869 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003870 if (!NewParm)
3871 return true;
3872
Douglas Gregordd472162011-01-07 00:20:55 +00003873 OutParamTypes.push_back(NewParm->getType());
3874 if (PVars)
3875 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003876 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003877
3878 // If we're supposed to retain a pack expansion, do so by temporarily
3879 // forgetting the partially-substituted parameter pack.
3880 if (RetainExpansion) {
3881 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3882 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003883 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003884 indexAdjustment++,
Douglas Gregor715e4612011-01-14 22:40:04 +00003885 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003886 if (!NewParm)
3887 return true;
3888
3889 OutParamTypes.push_back(NewParm->getType());
3890 if (PVars)
3891 PVars->push_back(NewParm);
3892 }
3893
John McCall8fb0d9d2011-05-01 22:35:37 +00003894 // The next parameter should have the same adjustment as the
3895 // last thing we pushed, but we post-incremented indexAdjustment
3896 // on every push. Also, if we push nothing, the adjustment should
3897 // go down by one.
3898 indexAdjustment--;
3899
Douglas Gregor5499af42011-01-05 23:12:31 +00003900 // We're done with the pack expansion.
3901 continue;
3902 }
3903
3904 // We'll substitute the parameter now without expanding the pack
3905 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00003906 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3907 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003908 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003909 NumExpansions);
3910 } else {
3911 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00003912 indexAdjustment,
Douglas Gregorc52264e2011-03-02 02:04:06 +00003913 llvm::Optional<unsigned>());
Douglas Gregor5499af42011-01-05 23:12:31 +00003914 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00003915
John McCall58f10c32010-03-11 09:03:00 +00003916 if (!NewParm)
3917 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003918
Douglas Gregordd472162011-01-07 00:20:55 +00003919 OutParamTypes.push_back(NewParm->getType());
3920 if (PVars)
3921 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003922 continue;
3923 }
John McCall58f10c32010-03-11 09:03:00 +00003924
3925 // Deal with the possibility that we don't have a parameter
3926 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003927 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003928 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003929 llvm::Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003930 QualType NewType;
Douglas Gregor5499af42011-01-05 23:12:31 +00003931 if (const PackExpansionType *Expansion
3932 = dyn_cast<PackExpansionType>(OldType)) {
3933 // We have a function parameter pack that may need to be expanded.
3934 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00003935 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00003936 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3937
3938 // Determine whether we should expand the parameter packs.
3939 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003940 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003941 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003942 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003943 ShouldExpand,
3944 RetainExpansion,
3945 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003946 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003947 }
3948
3949 if (ShouldExpand) {
3950 // Expand the function parameter pack into multiple, separate
3951 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003952 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003953 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3954 QualType NewType = getDerived().TransformType(Pattern);
3955 if (NewType.isNull())
3956 return true;
John McCall58f10c32010-03-11 09:03:00 +00003957
Douglas Gregordd472162011-01-07 00:20:55 +00003958 OutParamTypes.push_back(NewType);
3959 if (PVars)
3960 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003961 }
3962
3963 // We're done with the pack expansion.
3964 continue;
3965 }
3966
Douglas Gregor48d24112011-01-10 20:53:55 +00003967 // If we're supposed to retain a pack expansion, do so by temporarily
3968 // forgetting the partially-substituted parameter pack.
3969 if (RetainExpansion) {
3970 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3971 QualType NewType = getDerived().TransformType(Pattern);
3972 if (NewType.isNull())
3973 return true;
3974
3975 OutParamTypes.push_back(NewType);
3976 if (PVars)
3977 PVars->push_back(0);
3978 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003979
Douglas Gregor5499af42011-01-05 23:12:31 +00003980 // We'll substitute the parameter now without expanding the pack
3981 // expansion.
3982 OldType = Expansion->getPattern();
3983 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00003984 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3985 NewType = getDerived().TransformType(OldType);
3986 } else {
3987 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00003988 }
3989
Douglas Gregor5499af42011-01-05 23:12:31 +00003990 if (NewType.isNull())
3991 return true;
3992
3993 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003994 NewType = getSema().Context.getPackExpansionType(NewType,
3995 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003996
Douglas Gregordd472162011-01-07 00:20:55 +00003997 OutParamTypes.push_back(NewType);
3998 if (PVars)
3999 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00004000 }
4001
John McCall8fb0d9d2011-05-01 22:35:37 +00004002#ifndef NDEBUG
4003 if (PVars) {
4004 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4005 if (ParmVarDecl *parm = (*PVars)[i])
4006 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004007 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004008#endif
4009
4010 return false;
4011}
John McCall58f10c32010-03-11 09:03:00 +00004012
4013template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004014QualType
John McCall550e0c22009-10-21 00:40:46 +00004015TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004016 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004017 // Transform the parameters and return type.
4018 //
4019 // We instantiate in source order, with the return type first followed by
4020 // the parameters, because users tend to expect this (even if they shouldn't
4021 // rely on it!).
4022 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00004023 // When the function has a trailing return type, we instantiate the
4024 // parameters before the return type, since the return type can then refer
4025 // to the parameters themselves (via decltype, sizeof, etc.).
4026 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004027 SmallVector<QualType, 4> ParamTypes;
4028 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004029 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004030
Douglas Gregor7fb25412010-10-01 18:44:50 +00004031 QualType ResultType;
4032
4033 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00004034 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4035 TL.getParmArray(),
4036 TL.getNumArgs(),
4037 TL.getTypePtr()->arg_type_begin(),
4038 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004039 return QualType();
4040
4041 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4042 if (ResultType.isNull())
4043 return QualType();
4044 }
4045 else {
4046 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4047 if (ResultType.isNull())
4048 return QualType();
4049
Douglas Gregordd472162011-01-07 00:20:55 +00004050 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
4051 TL.getParmArray(),
4052 TL.getNumArgs(),
4053 TL.getTypePtr()->arg_type_begin(),
4054 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004055 return QualType();
4056 }
4057
John McCall550e0c22009-10-21 00:40:46 +00004058 QualType Result = TL.getType();
4059 if (getDerived().AlwaysRebuild() ||
4060 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00004061 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00004062 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
4063 Result = getDerived().RebuildFunctionProtoType(ResultType,
4064 ParamTypes.data(),
4065 ParamTypes.size(),
4066 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004067 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00004068 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00004069 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00004070 if (Result.isNull())
4071 return QualType();
4072 }
Mike Stump11289f42009-09-09 15:08:12 +00004073
John McCall550e0c22009-10-21 00:40:46 +00004074 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004075 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4076 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004077 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00004078 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
4079 NewTL.setArg(i, ParamDecls[i]);
4080
4081 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004082}
Mike Stump11289f42009-09-09 15:08:12 +00004083
Douglas Gregord6ff3322009-08-04 16:50:30 +00004084template<typename Derived>
4085QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004086 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004087 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004088 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004089 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4090 if (ResultType.isNull())
4091 return QualType();
4092
4093 QualType Result = TL.getType();
4094 if (getDerived().AlwaysRebuild() ||
4095 ResultType != T->getResultType())
4096 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4097
4098 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004099 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
4100 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004101 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004102
4103 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004104}
Mike Stump11289f42009-09-09 15:08:12 +00004105
John McCallb96ec562009-12-04 22:46:56 +00004106template<typename Derived> QualType
4107TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004108 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004109 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004110 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004111 if (!D)
4112 return QualType();
4113
4114 QualType Result = TL.getType();
4115 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4116 Result = getDerived().RebuildUnresolvedUsingType(D);
4117 if (Result.isNull())
4118 return QualType();
4119 }
4120
4121 // We might get an arbitrary type spec type back. We should at
4122 // least always get a type spec type, though.
4123 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4124 NewTL.setNameLoc(TL.getNameLoc());
4125
4126 return Result;
4127}
4128
Douglas Gregord6ff3322009-08-04 16:50:30 +00004129template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004130QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004131 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004132 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004133 TypedefNameDecl *Typedef
4134 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4135 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004136 if (!Typedef)
4137 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004138
John McCall550e0c22009-10-21 00:40:46 +00004139 QualType Result = TL.getType();
4140 if (getDerived().AlwaysRebuild() ||
4141 Typedef != T->getDecl()) {
4142 Result = getDerived().RebuildTypedefType(Typedef);
4143 if (Result.isNull())
4144 return QualType();
4145 }
Mike Stump11289f42009-09-09 15:08:12 +00004146
John McCall550e0c22009-10-21 00:40:46 +00004147 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4148 NewTL.setNameLoc(TL.getNameLoc());
4149
4150 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004151}
Mike Stump11289f42009-09-09 15:08:12 +00004152
Douglas Gregord6ff3322009-08-04 16:50:30 +00004153template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004154QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004155 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004156 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004157 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004158
John McCalldadc5752010-08-24 06:29:42 +00004159 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004160 if (E.isInvalid())
4161 return QualType();
4162
John McCall550e0c22009-10-21 00:40:46 +00004163 QualType Result = TL.getType();
4164 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004165 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004166 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004167 if (Result.isNull())
4168 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004169 }
John McCall550e0c22009-10-21 00:40:46 +00004170 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004171
John McCall550e0c22009-10-21 00:40:46 +00004172 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004173 NewTL.setTypeofLoc(TL.getTypeofLoc());
4174 NewTL.setLParenLoc(TL.getLParenLoc());
4175 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004176
4177 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004178}
Mike Stump11289f42009-09-09 15:08:12 +00004179
4180template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004181QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004182 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004183 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4184 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4185 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004186 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004187
John McCall550e0c22009-10-21 00:40:46 +00004188 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004189 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4190 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004191 if (Result.isNull())
4192 return QualType();
4193 }
Mike Stump11289f42009-09-09 15:08:12 +00004194
John McCall550e0c22009-10-21 00:40:46 +00004195 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004196 NewTL.setTypeofLoc(TL.getTypeofLoc());
4197 NewTL.setLParenLoc(TL.getLParenLoc());
4198 NewTL.setRParenLoc(TL.getRParenLoc());
4199 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004200
4201 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004202}
Mike Stump11289f42009-09-09 15:08:12 +00004203
4204template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004205QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004206 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004207 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004208
Douglas Gregore922c772009-08-04 22:27:00 +00004209 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004210 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004211
John McCalldadc5752010-08-24 06:29:42 +00004212 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004213 if (E.isInvalid())
4214 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004215
John McCall550e0c22009-10-21 00:40:46 +00004216 QualType Result = TL.getType();
4217 if (getDerived().AlwaysRebuild() ||
4218 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004219 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004220 if (Result.isNull())
4221 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004222 }
John McCall550e0c22009-10-21 00:40:46 +00004223 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004224
John McCall550e0c22009-10-21 00:40:46 +00004225 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4226 NewTL.setNameLoc(TL.getNameLoc());
4227
4228 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004229}
4230
4231template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00004232QualType TreeTransform<Derived>::TransformUnaryTransformType(
4233 TypeLocBuilder &TLB,
4234 UnaryTransformTypeLoc TL) {
4235 QualType Result = TL.getType();
4236 if (Result->isDependentType()) {
4237 const UnaryTransformType *T = TL.getTypePtr();
4238 QualType NewBase =
4239 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
4240 Result = getDerived().RebuildUnaryTransformType(NewBase,
4241 T->getUTTKind(),
4242 TL.getKWLoc());
4243 if (Result.isNull())
4244 return QualType();
4245 }
4246
4247 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
4248 NewTL.setKWLoc(TL.getKWLoc());
4249 NewTL.setParensRange(TL.getParensRange());
4250 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
4251 return Result;
4252}
4253
4254template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004255QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4256 AutoTypeLoc TL) {
4257 const AutoType *T = TL.getTypePtr();
4258 QualType OldDeduced = T->getDeducedType();
4259 QualType NewDeduced;
4260 if (!OldDeduced.isNull()) {
4261 NewDeduced = getDerived().TransformType(OldDeduced);
4262 if (NewDeduced.isNull())
4263 return QualType();
4264 }
4265
4266 QualType Result = TL.getType();
4267 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4268 Result = getDerived().RebuildAutoType(NewDeduced);
4269 if (Result.isNull())
4270 return QualType();
4271 }
4272
4273 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4274 NewTL.setNameLoc(TL.getNameLoc());
4275
4276 return Result;
4277}
4278
4279template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004280QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004281 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004282 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004283 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004284 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4285 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004286 if (!Record)
4287 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004288
John McCall550e0c22009-10-21 00:40:46 +00004289 QualType Result = TL.getType();
4290 if (getDerived().AlwaysRebuild() ||
4291 Record != T->getDecl()) {
4292 Result = getDerived().RebuildRecordType(Record);
4293 if (Result.isNull())
4294 return QualType();
4295 }
Mike Stump11289f42009-09-09 15:08:12 +00004296
John McCall550e0c22009-10-21 00:40:46 +00004297 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4298 NewTL.setNameLoc(TL.getNameLoc());
4299
4300 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004301}
Mike Stump11289f42009-09-09 15:08:12 +00004302
4303template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004304QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004305 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004306 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004307 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004308 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4309 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004310 if (!Enum)
4311 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004312
John McCall550e0c22009-10-21 00:40:46 +00004313 QualType Result = TL.getType();
4314 if (getDerived().AlwaysRebuild() ||
4315 Enum != T->getDecl()) {
4316 Result = getDerived().RebuildEnumType(Enum);
4317 if (Result.isNull())
4318 return QualType();
4319 }
Mike Stump11289f42009-09-09 15:08:12 +00004320
John McCall550e0c22009-10-21 00:40:46 +00004321 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4322 NewTL.setNameLoc(TL.getNameLoc());
4323
4324 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004325}
John McCallfcc33b02009-09-05 00:15:47 +00004326
John McCalle78aac42010-03-10 03:28:59 +00004327template<typename Derived>
4328QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4329 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004330 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004331 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4332 TL.getTypePtr()->getDecl());
4333 if (!D) return QualType();
4334
4335 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4336 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4337 return T;
4338}
4339
Douglas Gregord6ff3322009-08-04 16:50:30 +00004340template<typename Derived>
4341QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004342 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004343 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004344 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004345}
4346
Mike Stump11289f42009-09-09 15:08:12 +00004347template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004348QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004349 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004350 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00004351 const SubstTemplateTypeParmType *T = TL.getTypePtr();
4352
4353 // Substitute into the replacement type, which itself might involve something
4354 // that needs to be transformed. This only tends to occur with default
4355 // template arguments of template template parameters.
4356 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
4357 QualType Replacement = getDerived().TransformType(T->getReplacementType());
4358 if (Replacement.isNull())
4359 return QualType();
4360
4361 // Always canonicalize the replacement type.
4362 Replacement = SemaRef.Context.getCanonicalType(Replacement);
4363 QualType Result
4364 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
4365 Replacement);
4366
4367 // Propagate type-source information.
4368 SubstTemplateTypeParmTypeLoc NewTL
4369 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
4370 NewTL.setNameLoc(TL.getNameLoc());
4371 return Result;
4372
John McCallcebee162009-10-18 09:09:24 +00004373}
4374
4375template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004376QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4377 TypeLocBuilder &TLB,
4378 SubstTemplateTypeParmPackTypeLoc TL) {
4379 return TransformTypeSpecType(TLB, TL);
4380}
4381
4382template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004383QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004384 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004385 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004386 const TemplateSpecializationType *T = TL.getTypePtr();
4387
Douglas Gregordf846d12011-03-02 18:46:51 +00004388 // The nested-name-specifier never matters in a TemplateSpecializationType,
4389 // because we can't have a dependent nested-name-specifier anyway.
4390 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00004391 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00004392 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
4393 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004394 if (Template.isNull())
4395 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004396
John McCall31f82722010-11-12 08:19:04 +00004397 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4398}
4399
Douglas Gregorfe921a72010-12-20 23:36:19 +00004400namespace {
4401 /// \brief Simple iterator that traverses the template arguments in a
4402 /// container that provides a \c getArgLoc() member function.
4403 ///
4404 /// This iterator is intended to be used with the iterator form of
4405 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4406 template<typename ArgLocContainer>
4407 class TemplateArgumentLocContainerIterator {
4408 ArgLocContainer *Container;
4409 unsigned Index;
4410
4411 public:
4412 typedef TemplateArgumentLoc value_type;
4413 typedef TemplateArgumentLoc reference;
4414 typedef int difference_type;
4415 typedef std::input_iterator_tag iterator_category;
4416
4417 class pointer {
4418 TemplateArgumentLoc Arg;
4419
4420 public:
4421 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4422
4423 const TemplateArgumentLoc *operator->() const {
4424 return &Arg;
4425 }
4426 };
4427
4428
4429 TemplateArgumentLocContainerIterator() {}
4430
4431 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4432 unsigned Index)
4433 : Container(&Container), Index(Index) { }
4434
4435 TemplateArgumentLocContainerIterator &operator++() {
4436 ++Index;
4437 return *this;
4438 }
4439
4440 TemplateArgumentLocContainerIterator operator++(int) {
4441 TemplateArgumentLocContainerIterator Old(*this);
4442 ++(*this);
4443 return Old;
4444 }
4445
4446 TemplateArgumentLoc operator*() const {
4447 return Container->getArgLoc(Index);
4448 }
4449
4450 pointer operator->() const {
4451 return pointer(Container->getArgLoc(Index));
4452 }
4453
4454 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004455 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004456 return X.Container == Y.Container && X.Index == Y.Index;
4457 }
4458
4459 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004460 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004461 return !(X == Y);
4462 }
4463 };
4464}
4465
4466
John McCall31f82722010-11-12 08:19:04 +00004467template <typename Derived>
4468QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4469 TypeLocBuilder &TLB,
4470 TemplateSpecializationTypeLoc TL,
4471 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004472 TemplateArgumentListInfo NewTemplateArgs;
4473 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4474 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004475 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4476 ArgIterator;
4477 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4478 ArgIterator(TL, TL.getNumArgs()),
4479 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004480 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004481
John McCall0ad16662009-10-29 08:12:44 +00004482 // FIXME: maybe don't rebuild if all the template arguments are the same.
4483
4484 QualType Result =
4485 getDerived().RebuildTemplateSpecializationType(Template,
4486 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004487 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004488
4489 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00004490 // Specializations of template template parameters are represented as
4491 // TemplateSpecializationTypes, and substitution of type alias templates
4492 // within a dependent context can transform them into
4493 // DependentTemplateSpecializationTypes.
4494 if (isa<DependentTemplateSpecializationType>(Result)) {
4495 DependentTemplateSpecializationTypeLoc NewTL
4496 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4497 NewTL.setKeywordLoc(TL.getTemplateNameLoc());
4498 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
4499 NewTL.setNameLoc(TL.getTemplateNameLoc());
4500 NewTL.setLAngleLoc(TL.getLAngleLoc());
4501 NewTL.setRAngleLoc(TL.getRAngleLoc());
4502 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4503 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4504 return Result;
4505 }
4506
John McCall0ad16662009-10-29 08:12:44 +00004507 TemplateSpecializationTypeLoc NewTL
4508 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4509 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4510 NewTL.setLAngleLoc(TL.getLAngleLoc());
4511 NewTL.setRAngleLoc(TL.getRAngleLoc());
4512 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4513 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004514 }
Mike Stump11289f42009-09-09 15:08:12 +00004515
John McCall0ad16662009-10-29 08:12:44 +00004516 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004517}
Mike Stump11289f42009-09-09 15:08:12 +00004518
Douglas Gregor5a064722011-02-28 17:23:35 +00004519template <typename Derived>
4520QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
4521 TypeLocBuilder &TLB,
4522 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00004523 TemplateName Template,
4524 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00004525 TemplateArgumentListInfo NewTemplateArgs;
4526 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4527 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4528 typedef TemplateArgumentLocContainerIterator<
4529 DependentTemplateSpecializationTypeLoc> ArgIterator;
4530 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4531 ArgIterator(TL, TL.getNumArgs()),
4532 NewTemplateArgs))
4533 return QualType();
4534
4535 // FIXME: maybe don't rebuild if all the template arguments are the same.
4536
4537 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
4538 QualType Result
4539 = getSema().Context.getDependentTemplateSpecializationType(
4540 TL.getTypePtr()->getKeyword(),
4541 DTN->getQualifier(),
4542 DTN->getIdentifier(),
4543 NewTemplateArgs);
4544
4545 DependentTemplateSpecializationTypeLoc NewTL
4546 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
4547 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004548
Douglas Gregora7a795b2011-03-01 20:11:18 +00004549 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Douglas Gregor5a064722011-02-28 17:23:35 +00004550 NewTL.setNameLoc(TL.getNameLoc());
4551 NewTL.setLAngleLoc(TL.getLAngleLoc());
4552 NewTL.setRAngleLoc(TL.getRAngleLoc());
4553 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4554 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4555 return Result;
4556 }
4557
4558 QualType Result
4559 = getDerived().RebuildTemplateSpecializationType(Template,
4560 TL.getNameLoc(),
4561 NewTemplateArgs);
4562
4563 if (!Result.isNull()) {
4564 /// FIXME: Wrap this in an elaborated-type-specifier?
4565 TemplateSpecializationTypeLoc NewTL
4566 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4567 NewTL.setTemplateNameLoc(TL.getNameLoc());
4568 NewTL.setLAngleLoc(TL.getLAngleLoc());
4569 NewTL.setRAngleLoc(TL.getRAngleLoc());
4570 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4571 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
4572 }
4573
4574 return Result;
4575}
4576
Mike Stump11289f42009-09-09 15:08:12 +00004577template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004578QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004579TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004580 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004581 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004582
Douglas Gregor844cb502011-03-01 18:12:44 +00004583 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00004584 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00004585 if (TL.getQualifierLoc()) {
4586 QualifierLoc
4587 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4588 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00004589 return QualType();
4590 }
Mike Stump11289f42009-09-09 15:08:12 +00004591
John McCall31f82722010-11-12 08:19:04 +00004592 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4593 if (NamedT.isNull())
4594 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004595
Richard Smith3f1b5d02011-05-05 21:57:07 +00004596 // C++0x [dcl.type.elab]p2:
4597 // If the identifier resolves to a typedef-name or the simple-template-id
4598 // resolves to an alias template specialization, the
4599 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00004600 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
4601 if (const TemplateSpecializationType *TST =
4602 NamedT->getAs<TemplateSpecializationType>()) {
4603 TemplateName Template = TST->getTemplateName();
4604 if (TypeAliasTemplateDecl *TAT =
4605 dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) {
4606 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
4607 diag::err_tag_reference_non_tag) << 4;
4608 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
4609 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00004610 }
4611 }
4612
John McCall550e0c22009-10-21 00:40:46 +00004613 QualType Result = TL.getType();
4614 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00004615 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004616 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004617 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
Douglas Gregor844cb502011-03-01 18:12:44 +00004618 T->getKeyword(),
4619 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004620 if (Result.isNull())
4621 return QualType();
4622 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004623
Abramo Bagnara6150c882010-05-11 21:36:43 +00004624 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004625 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004626 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00004627 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004628}
Mike Stump11289f42009-09-09 15:08:12 +00004629
4630template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004631QualType TreeTransform<Derived>::TransformAttributedType(
4632 TypeLocBuilder &TLB,
4633 AttributedTypeLoc TL) {
4634 const AttributedType *oldType = TL.getTypePtr();
4635 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4636 if (modifiedType.isNull())
4637 return QualType();
4638
4639 QualType result = TL.getType();
4640
4641 // FIXME: dependent operand expressions?
4642 if (getDerived().AlwaysRebuild() ||
4643 modifiedType != oldType->getModifiedType()) {
4644 // TODO: this is really lame; we should really be rebuilding the
4645 // equivalent type from first principles.
4646 QualType equivalentType
4647 = getDerived().TransformType(oldType->getEquivalentType());
4648 if (equivalentType.isNull())
4649 return QualType();
4650 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4651 modifiedType,
4652 equivalentType);
4653 }
4654
4655 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4656 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4657 if (TL.hasAttrOperand())
4658 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4659 if (TL.hasAttrExprOperand())
4660 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4661 else if (TL.hasAttrEnumOperand())
4662 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4663
4664 return result;
4665}
4666
4667template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004668QualType
4669TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4670 ParenTypeLoc TL) {
4671 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4672 if (Inner.isNull())
4673 return QualType();
4674
4675 QualType Result = TL.getType();
4676 if (getDerived().AlwaysRebuild() ||
4677 Inner != TL.getInnerLoc().getType()) {
4678 Result = getDerived().RebuildParenType(Inner);
4679 if (Result.isNull())
4680 return QualType();
4681 }
4682
4683 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4684 NewTL.setLParenLoc(TL.getLParenLoc());
4685 NewTL.setRParenLoc(TL.getRParenLoc());
4686 return Result;
4687}
4688
4689template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004690QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004691 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004692 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004693
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004694 NestedNameSpecifierLoc QualifierLoc
4695 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4696 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004697 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004698
John McCallc392f372010-06-11 00:33:02 +00004699 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004700 = getDerived().RebuildDependentNameType(T->getKeyword(),
John McCallc392f372010-06-11 00:33:02 +00004701 TL.getKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004702 QualifierLoc,
4703 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00004704 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004705 if (Result.isNull())
4706 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004707
Abramo Bagnarad7548482010-05-19 21:37:53 +00004708 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4709 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004710 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4711
Abramo Bagnarad7548482010-05-19 21:37:53 +00004712 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4713 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00004714 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00004715 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004716 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4717 NewTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00004718 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004719 NewTL.setNameLoc(TL.getNameLoc());
4720 }
John McCall550e0c22009-10-21 00:40:46 +00004721 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004722}
Mike Stump11289f42009-09-09 15:08:12 +00004723
Douglas Gregord6ff3322009-08-04 16:50:30 +00004724template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004725QualType TreeTransform<Derived>::
4726 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004727 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00004728 NestedNameSpecifierLoc QualifierLoc;
4729 if (TL.getQualifierLoc()) {
4730 QualifierLoc
4731 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
4732 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00004733 return QualType();
4734 }
4735
John McCall31f82722010-11-12 08:19:04 +00004736 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00004737 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00004738}
4739
4740template<typename Derived>
4741QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00004742TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4743 DependentTemplateSpecializationTypeLoc TL,
4744 NestedNameSpecifierLoc QualifierLoc) {
4745 const DependentTemplateSpecializationType *T = TL.getTypePtr();
4746
4747 TemplateArgumentListInfo NewTemplateArgs;
4748 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4749 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
4750
4751 typedef TemplateArgumentLocContainerIterator<
4752 DependentTemplateSpecializationTypeLoc> ArgIterator;
4753 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4754 ArgIterator(TL, TL.getNumArgs()),
4755 NewTemplateArgs))
4756 return QualType();
4757
4758 QualType Result
4759 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4760 QualifierLoc,
4761 T->getIdentifier(),
4762 TL.getNameLoc(),
4763 NewTemplateArgs);
4764 if (Result.isNull())
4765 return QualType();
4766
4767 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4768 QualType NamedT = ElabT->getNamedType();
4769
4770 // Copy information relevant to the template specialization.
4771 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00004772 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004773 NamedTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004774 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4775 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004776 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004777 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004778
4779 // Copy information relevant to the elaborated type.
4780 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4781 NewTL.setKeywordLoc(TL.getKeywordLoc());
4782 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00004783 } else if (isa<DependentTemplateSpecializationType>(Result)) {
4784 DependentTemplateSpecializationTypeLoc SpecTL
4785 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Douglas Gregor11ddf132011-03-07 15:13:34 +00004786 SpecTL.setKeywordLoc(TL.getKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004787 SpecTL.setQualifierLoc(QualifierLoc);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004788 SpecTL.setNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004789 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4790 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004791 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004792 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004793 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00004794 TemplateSpecializationTypeLoc SpecTL
4795 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Chandler Carruth3d7e3da2011-04-01 02:03:23 +00004796 SpecTL.setTemplateNameLoc(TL.getNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00004797 SpecTL.setLAngleLoc(TL.getLAngleLoc());
4798 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00004799 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00004800 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00004801 }
4802 return Result;
4803}
4804
4805template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004806QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4807 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004808 QualType Pattern
4809 = getDerived().TransformType(TLB, TL.getPatternLoc());
4810 if (Pattern.isNull())
4811 return QualType();
4812
4813 QualType Result = TL.getType();
4814 if (getDerived().AlwaysRebuild() ||
4815 Pattern != TL.getPatternLoc().getType()) {
4816 Result = getDerived().RebuildPackExpansionType(Pattern,
4817 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004818 TL.getEllipsisLoc(),
4819 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004820 if (Result.isNull())
4821 return QualType();
4822 }
4823
4824 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4825 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4826 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004827}
4828
4829template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004830QualType
4831TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004832 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004833 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004834 TLB.pushFullCopy(TL);
4835 return TL.getType();
4836}
4837
4838template<typename Derived>
4839QualType
4840TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004841 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004842 // ObjCObjectType is never dependent.
4843 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004844 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004845}
Mike Stump11289f42009-09-09 15:08:12 +00004846
4847template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004848QualType
4849TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004850 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004851 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004852 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004853 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004854}
4855
Douglas Gregord6ff3322009-08-04 16:50:30 +00004856//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004857// Statement transformation
4858//===----------------------------------------------------------------------===//
4859template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004860StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004861TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004862 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004863}
4864
4865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004866StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004867TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4868 return getDerived().TransformCompoundStmt(S, false);
4869}
4870
4871template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004872StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004873TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004874 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004875 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004876 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004877 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004878 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4879 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004880 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004881 if (Result.isInvalid()) {
4882 // Immediately fail if this was a DeclStmt, since it's very
4883 // likely that this will cause problems for future statements.
4884 if (isa<DeclStmt>(*B))
4885 return StmtError();
4886
4887 // Otherwise, just keep processing substatements and fail later.
4888 SubStmtInvalid = true;
4889 continue;
4890 }
Mike Stump11289f42009-09-09 15:08:12 +00004891
Douglas Gregorebe10102009-08-20 07:17:43 +00004892 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4893 Statements.push_back(Result.takeAs<Stmt>());
4894 }
Mike Stump11289f42009-09-09 15:08:12 +00004895
John McCall1ababa62010-08-27 19:56:05 +00004896 if (SubStmtInvalid)
4897 return StmtError();
4898
Douglas Gregorebe10102009-08-20 07:17:43 +00004899 if (!getDerived().AlwaysRebuild() &&
4900 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004901 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004902
4903 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4904 move_arg(Statements),
4905 S->getRBracLoc(),
4906 IsStmtExpr);
4907}
Mike Stump11289f42009-09-09 15:08:12 +00004908
Douglas Gregorebe10102009-08-20 07:17:43 +00004909template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004910StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004911TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004912 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004913 {
4914 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004915 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004916
Eli Friedman06577382009-11-19 03:14:00 +00004917 // Transform the left-hand case value.
4918 LHS = getDerived().TransformExpr(S->getLHS());
4919 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004920 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004921
Eli Friedman06577382009-11-19 03:14:00 +00004922 // Transform the right-hand case value (for the GNU case-range extension).
4923 RHS = getDerived().TransformExpr(S->getRHS());
4924 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004925 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004926 }
Mike Stump11289f42009-09-09 15:08:12 +00004927
Douglas Gregorebe10102009-08-20 07:17:43 +00004928 // Build the case statement.
4929 // Case statements are always rebuilt so that they will attached to their
4930 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004931 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004932 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004933 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004934 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004935 S->getColonLoc());
4936 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004937 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004938
Douglas Gregorebe10102009-08-20 07:17:43 +00004939 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004940 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004941 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004942 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004943
Douglas Gregorebe10102009-08-20 07:17:43 +00004944 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004945 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004946}
4947
4948template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004949StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004950TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004951 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004952 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004953 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004954 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004955
Douglas Gregorebe10102009-08-20 07:17:43 +00004956 // Default statements are always rebuilt
4957 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004958 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004959}
Mike Stump11289f42009-09-09 15:08:12 +00004960
Douglas Gregorebe10102009-08-20 07:17:43 +00004961template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004962StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004963TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004964 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004965 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004966 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004967
Chris Lattnercab02a62011-02-17 20:34:02 +00004968 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4969 S->getDecl());
4970 if (!LD)
4971 return StmtError();
4972
4973
Douglas Gregorebe10102009-08-20 07:17:43 +00004974 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004975 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004976 cast<LabelDecl>(LD), SourceLocation(),
4977 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004978}
Mike Stump11289f42009-09-09 15:08:12 +00004979
Douglas Gregorebe10102009-08-20 07:17:43 +00004980template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004981StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004982TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004983 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004984 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004985 VarDecl *ConditionVar = 0;
4986 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004987 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004988 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004989 getDerived().TransformDefinition(
4990 S->getConditionVariable()->getLocation(),
4991 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004992 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004993 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004994 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004995 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004996
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004997 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004998 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004999
5000 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00005001 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005002 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
5003 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005004 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005005 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005006
John McCallb268a282010-08-23 23:25:46 +00005007 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005008 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005009 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005010
John McCallb268a282010-08-23 23:25:46 +00005011 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5012 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005013 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005014
Douglas Gregorebe10102009-08-20 07:17:43 +00005015 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00005016 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00005017 if (Then.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 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00005021 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00005022 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005023 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005024
Douglas Gregorebe10102009-08-20 07:17:43 +00005025 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005026 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005027 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005028 Then.get() == S->getThen() &&
5029 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00005030 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005031
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005032 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00005033 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00005034 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005035}
5036
5037template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005038StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005039TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005040 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00005041 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00005042 VarDecl *ConditionVar = 0;
5043 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005044 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00005045 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005046 getDerived().TransformDefinition(
5047 S->getConditionVariable()->getLocation(),
5048 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00005049 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005050 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005051 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00005052 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005053
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005054 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005055 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005056 }
Mike Stump11289f42009-09-09 15:08:12 +00005057
Douglas Gregorebe10102009-08-20 07:17:43 +00005058 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005059 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00005060 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00005061 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00005062 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005063 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005064
Douglas Gregorebe10102009-08-20 07:17:43 +00005065 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005066 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005067 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005068 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005069
Douglas Gregorebe10102009-08-20 07:17:43 +00005070 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00005071 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
5072 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005073}
Mike Stump11289f42009-09-09 15:08:12 +00005074
Douglas Gregorebe10102009-08-20 07:17:43 +00005075template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005076StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005077TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005078 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005079 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00005080 VarDecl *ConditionVar = 0;
5081 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005082 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00005083 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005084 getDerived().TransformDefinition(
5085 S->getConditionVariable()->getLocation(),
5086 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00005087 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005088 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005089 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00005090 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005091
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005092 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005093 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005094
5095 if (S->getCond()) {
5096 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005097 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
5098 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005099 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005100 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00005101 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00005102 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005103 }
Mike Stump11289f42009-09-09 15:08:12 +00005104
John McCallb268a282010-08-23 23:25:46 +00005105 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5106 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005107 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005108
Douglas Gregorebe10102009-08-20 07:17:43 +00005109 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005110 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005111 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005112 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005113
Douglas Gregorebe10102009-08-20 07:17:43 +00005114 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00005115 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005116 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005117 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00005118 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005119
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005120 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00005121 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005122}
Mike Stump11289f42009-09-09 15:08:12 +00005123
Douglas Gregorebe10102009-08-20 07:17:43 +00005124template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005125StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005126TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005127 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005128 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005129 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005130 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005131
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005132 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005133 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005134 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005135 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005136
Douglas Gregorebe10102009-08-20 07:17:43 +00005137 if (!getDerived().AlwaysRebuild() &&
5138 Cond.get() == S->getCond() &&
5139 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005140 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005141
John McCallb268a282010-08-23 23:25:46 +00005142 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
5143 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005144 S->getRParenLoc());
5145}
Mike Stump11289f42009-09-09 15:08:12 +00005146
Douglas Gregorebe10102009-08-20 07:17:43 +00005147template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005148StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005149TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005150 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00005151 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00005152 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005153 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005154
Douglas Gregorebe10102009-08-20 07:17:43 +00005155 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005156 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005157 VarDecl *ConditionVar = 0;
5158 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005159 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005160 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005161 getDerived().TransformDefinition(
5162 S->getConditionVariable()->getLocation(),
5163 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005164 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00005165 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005166 } else {
5167 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005168
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005169 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005170 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005171
5172 if (S->getCond()) {
5173 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00005174 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
5175 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00005176 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005177 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005178
John McCallb268a282010-08-23 23:25:46 +00005179 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00005180 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00005181 }
Mike Stump11289f42009-09-09 15:08:12 +00005182
John McCallb268a282010-08-23 23:25:46 +00005183 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
5184 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005185 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005186
Douglas Gregorebe10102009-08-20 07:17:43 +00005187 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00005188 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00005189 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005190 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005191
John McCallb268a282010-08-23 23:25:46 +00005192 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
5193 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00005194 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00005195
Douglas Gregorebe10102009-08-20 07:17:43 +00005196 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00005197 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00005198 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005199 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005200
Douglas Gregorebe10102009-08-20 07:17:43 +00005201 if (!getDerived().AlwaysRebuild() &&
5202 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00005203 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00005204 Inc.get() == S->getInc() &&
5205 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005206 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005207
Douglas Gregorebe10102009-08-20 07:17:43 +00005208 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005209 Init.get(), FullCond, ConditionVar,
5210 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005211}
5212
5213template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005214StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005215TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00005216 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
5217 S->getLabel());
5218 if (!LD)
5219 return StmtError();
5220
Douglas Gregorebe10102009-08-20 07:17:43 +00005221 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00005222 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005223 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00005224}
5225
5226template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005227StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005228TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005229 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00005230 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005231 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005232
Douglas Gregorebe10102009-08-20 07:17:43 +00005233 if (!getDerived().AlwaysRebuild() &&
5234 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00005235 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005236
5237 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00005238 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005239}
5240
5241template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005242StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005243TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005244 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005245}
Mike Stump11289f42009-09-09 15:08:12 +00005246
Douglas Gregorebe10102009-08-20 07:17:43 +00005247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005248StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005249TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005250 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005251}
Mike Stump11289f42009-09-09 15:08:12 +00005252
Douglas Gregorebe10102009-08-20 07:17:43 +00005253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005254StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005255TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005256 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005257 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005258 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005259
Mike Stump11289f42009-09-09 15:08:12 +00005260 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005261 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005262 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005263}
Mike Stump11289f42009-09-09 15:08:12 +00005264
Douglas Gregorebe10102009-08-20 07:17:43 +00005265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005266StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005267TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005268 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005269 SmallVector<Decl *, 4> Decls;
Douglas Gregorebe10102009-08-20 07:17:43 +00005270 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5271 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005272 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5273 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005274 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005275 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005276
Douglas Gregorebe10102009-08-20 07:17:43 +00005277 if (Transformed != *D)
5278 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005279
Douglas Gregorebe10102009-08-20 07:17:43 +00005280 Decls.push_back(Transformed);
5281 }
Mike Stump11289f42009-09-09 15:08:12 +00005282
Douglas Gregorebe10102009-08-20 07:17:43 +00005283 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005284 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005285
5286 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005287 S->getStartLoc(), S->getEndLoc());
5288}
Mike Stump11289f42009-09-09 15:08:12 +00005289
Douglas Gregorebe10102009-08-20 07:17:43 +00005290template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005291StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005292TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005293
John McCall37ad5512010-08-23 06:44:23 +00005294 ASTOwningVector<Expr*> Constraints(getSema());
5295 ASTOwningVector<Expr*> Exprs(getSema());
Chris Lattner01cf8db2011-07-20 06:58:45 +00005296 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005297
John McCalldadc5752010-08-24 06:29:42 +00005298 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005299 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005300
5301 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005302
Anders Carlssonaaeef072010-01-24 05:50:09 +00005303 // Go through the outputs.
5304 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005305 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005306
Anders Carlssonaaeef072010-01-24 05:50:09 +00005307 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005308 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005309
Anders Carlssonaaeef072010-01-24 05:50:09 +00005310 // Transform the output expr.
5311 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005312 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005313 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005314 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005315
Anders Carlssonaaeef072010-01-24 05:50:09 +00005316 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005317
John McCallb268a282010-08-23 23:25:46 +00005318 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005319 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005320
Anders Carlssonaaeef072010-01-24 05:50:09 +00005321 // Go through the inputs.
5322 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005323 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005324
Anders Carlssonaaeef072010-01-24 05:50:09 +00005325 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005326 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005327
Anders Carlssonaaeef072010-01-24 05:50:09 +00005328 // Transform the input expr.
5329 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005330 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005331 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005332 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005333
Anders Carlssonaaeef072010-01-24 05:50:09 +00005334 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005335
John McCallb268a282010-08-23 23:25:46 +00005336 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005337 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005338
Anders Carlssonaaeef072010-01-24 05:50:09 +00005339 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005340 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005341
5342 // Go through the clobbers.
5343 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005344 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005345
5346 // No need to transform the asm string literal.
5347 AsmString = SemaRef.Owned(S->getAsmString());
5348
5349 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5350 S->isSimple(),
5351 S->isVolatile(),
5352 S->getNumOutputs(),
5353 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005354 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005355 move_arg(Constraints),
5356 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005357 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005358 move_arg(Clobbers),
5359 S->getRParenLoc(),
5360 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005361}
5362
5363
5364template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005365StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005366TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005367 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005368 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005369 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005370 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005371
Douglas Gregor96c79492010-04-23 22:50:49 +00005372 // Transform the @catch statements (if present).
5373 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005374 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005375 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005376 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005377 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005378 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005379 if (Catch.get() != S->getCatchStmt(I))
5380 AnyCatchChanged = true;
5381 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005382 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005383
Douglas Gregor306de2f2010-04-22 23:59:56 +00005384 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005385 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005386 if (S->getFinallyStmt()) {
5387 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5388 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005389 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005390 }
5391
5392 // If nothing changed, just retain this statement.
5393 if (!getDerived().AlwaysRebuild() &&
5394 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005395 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005396 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005397 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005398
Douglas Gregor306de2f2010-04-22 23:59:56 +00005399 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005400 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5401 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005402}
Mike Stump11289f42009-09-09 15:08:12 +00005403
Douglas Gregorebe10102009-08-20 07:17:43 +00005404template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005405StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005406TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005407 // Transform the @catch parameter, if there is one.
5408 VarDecl *Var = 0;
5409 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5410 TypeSourceInfo *TSInfo = 0;
5411 if (FromVar->getTypeSourceInfo()) {
5412 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5413 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005414 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005415 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005416
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005417 QualType T;
5418 if (TSInfo)
5419 T = TSInfo->getType();
5420 else {
5421 T = getDerived().TransformType(FromVar->getType());
5422 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005423 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005424 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005425
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005426 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5427 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005428 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005429 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005430
John McCalldadc5752010-08-24 06:29:42 +00005431 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005432 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005433 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005434
5435 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005436 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005437 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005438}
Mike Stump11289f42009-09-09 15:08:12 +00005439
Douglas Gregorebe10102009-08-20 07:17:43 +00005440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005441StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005442TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005443 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005444 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005445 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005446 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005447
Douglas Gregor306de2f2010-04-22 23:59:56 +00005448 // If nothing changed, just retain this statement.
5449 if (!getDerived().AlwaysRebuild() &&
5450 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005451 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005452
5453 // Build a new statement.
5454 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005455 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005456}
Mike Stump11289f42009-09-09 15:08:12 +00005457
Douglas Gregorebe10102009-08-20 07:17:43 +00005458template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005459StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005460TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005461 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005462 if (S->getThrowExpr()) {
5463 Operand = getDerived().TransformExpr(S->getThrowExpr());
5464 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005465 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005466 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005467
Douglas Gregor2900c162010-04-22 21:44:01 +00005468 if (!getDerived().AlwaysRebuild() &&
5469 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005470 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005471
John McCallb268a282010-08-23 23:25:46 +00005472 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005473}
Mike Stump11289f42009-09-09 15:08:12 +00005474
Douglas Gregorebe10102009-08-20 07:17:43 +00005475template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005476StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005477TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005478 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005479 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005480 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005481 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005482 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00005483 Object =
5484 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
5485 Object.get());
5486 if (Object.isInvalid())
5487 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005488
Douglas Gregor6148de72010-04-22 22:01:21 +00005489 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005490 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005491 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005492 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005493
Douglas Gregor6148de72010-04-22 22:01:21 +00005494 // If nothing change, just retain the current statement.
5495 if (!getDerived().AlwaysRebuild() &&
5496 Object.get() == S->getSynchExpr() &&
5497 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005498 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005499
5500 // Build a new statement.
5501 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005502 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005503}
5504
5505template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005506StmtResult
John McCall31168b02011-06-15 23:02:42 +00005507TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
5508 ObjCAutoreleasePoolStmt *S) {
5509 // Transform the body.
5510 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
5511 if (Body.isInvalid())
5512 return StmtError();
5513
5514 // If nothing changed, just retain this statement.
5515 if (!getDerived().AlwaysRebuild() &&
5516 Body.get() == S->getSubStmt())
5517 return SemaRef.Owned(S);
5518
5519 // Build a new statement.
5520 return getDerived().RebuildObjCAutoreleasePoolStmt(
5521 S->getAtLoc(), Body.get());
5522}
5523
5524template<typename Derived>
5525StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005526TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005527 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005528 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005529 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005530 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005531 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005532
Douglas Gregorf68a5082010-04-22 23:10:45 +00005533 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005534 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005535 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005536 return StmtError();
John McCall53848232011-07-27 01:07:15 +00005537 Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(),
5538 Collection.take());
5539 if (Collection.isInvalid())
5540 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005541
Douglas Gregorf68a5082010-04-22 23:10:45 +00005542 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005543 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005544 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005545 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005546
Douglas Gregorf68a5082010-04-22 23:10:45 +00005547 // If nothing changed, just retain this statement.
5548 if (!getDerived().AlwaysRebuild() &&
5549 Element.get() == S->getElement() &&
5550 Collection.get() == S->getCollection() &&
5551 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005552 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005553
Douglas Gregorf68a5082010-04-22 23:10:45 +00005554 // Build a new statement.
5555 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5556 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005557 Element.get(),
5558 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005559 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005560 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005561}
5562
5563
5564template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005565StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005566TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5567 // Transform the exception declaration, if any.
5568 VarDecl *Var = 0;
5569 if (S->getExceptionDecl()) {
5570 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005571 TypeSourceInfo *T = getDerived().TransformType(
5572 ExceptionDecl->getTypeSourceInfo());
5573 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005574 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005575
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005576 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Abramo Bagnaradff19302011-03-08 08:55:46 +00005577 ExceptionDecl->getInnerLocStart(),
5578 ExceptionDecl->getLocation(),
5579 ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00005580 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005581 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005582 }
Mike Stump11289f42009-09-09 15:08:12 +00005583
Douglas Gregorebe10102009-08-20 07:17:43 +00005584 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005585 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005586 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005587 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005588
Douglas Gregorebe10102009-08-20 07:17:43 +00005589 if (!getDerived().AlwaysRebuild() &&
5590 !Var &&
5591 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005592 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005593
5594 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5595 Var,
John McCallb268a282010-08-23 23:25:46 +00005596 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005597}
Mike Stump11289f42009-09-09 15:08:12 +00005598
Douglas Gregorebe10102009-08-20 07:17:43 +00005599template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005600StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005601TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5602 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005603 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005604 = getDerived().TransformCompoundStmt(S->getTryBlock());
5605 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005606 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005607
Douglas Gregorebe10102009-08-20 07:17:43 +00005608 // Transform the handlers.
5609 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005610 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005611 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005612 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005613 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5614 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005615 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005616
Douglas Gregorebe10102009-08-20 07:17:43 +00005617 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5618 Handlers.push_back(Handler.takeAs<Stmt>());
5619 }
Mike Stump11289f42009-09-09 15:08:12 +00005620
Douglas Gregorebe10102009-08-20 07:17:43 +00005621 if (!getDerived().AlwaysRebuild() &&
5622 TryBlock.get() == S->getTryBlock() &&
5623 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005624 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005625
John McCallb268a282010-08-23 23:25:46 +00005626 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005627 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005628}
Mike Stump11289f42009-09-09 15:08:12 +00005629
Richard Smith02e85f32011-04-14 22:09:26 +00005630template<typename Derived>
5631StmtResult
5632TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
5633 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
5634 if (Range.isInvalid())
5635 return StmtError();
5636
5637 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
5638 if (BeginEnd.isInvalid())
5639 return StmtError();
5640
5641 ExprResult Cond = getDerived().TransformExpr(S->getCond());
5642 if (Cond.isInvalid())
5643 return StmtError();
5644
5645 ExprResult Inc = getDerived().TransformExpr(S->getInc());
5646 if (Inc.isInvalid())
5647 return StmtError();
5648
5649 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
5650 if (LoopVar.isInvalid())
5651 return StmtError();
5652
5653 StmtResult NewStmt = S;
5654 if (getDerived().AlwaysRebuild() ||
5655 Range.get() != S->getRangeStmt() ||
5656 BeginEnd.get() != S->getBeginEndStmt() ||
5657 Cond.get() != S->getCond() ||
5658 Inc.get() != S->getInc() ||
5659 LoopVar.get() != S->getLoopVarStmt())
5660 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5661 S->getColonLoc(), Range.get(),
5662 BeginEnd.get(), Cond.get(),
5663 Inc.get(), LoopVar.get(),
5664 S->getRParenLoc());
5665
5666 StmtResult Body = getDerived().TransformStmt(S->getBody());
5667 if (Body.isInvalid())
5668 return StmtError();
5669
5670 // Body has changed but we didn't rebuild the for-range statement. Rebuild
5671 // it now so we have a new statement to attach the body to.
5672 if (Body.get() != S->getBody() && NewStmt.get() == S)
5673 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
5674 S->getColonLoc(), Range.get(),
5675 BeginEnd.get(), Cond.get(),
5676 Inc.get(), LoopVar.get(),
5677 S->getRParenLoc());
5678
5679 if (NewStmt.get() == S)
5680 return SemaRef.Owned(S);
5681
5682 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
5683}
5684
John Wiegley1c0675e2011-04-28 01:08:34 +00005685template<typename Derived>
5686StmtResult
5687TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
5688 StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock());
5689 if(TryBlock.isInvalid()) return StmtError();
5690
5691 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
5692 if(!getDerived().AlwaysRebuild() &&
5693 TryBlock.get() == S->getTryBlock() &&
5694 Handler.get() == S->getHandler())
5695 return SemaRef.Owned(S);
5696
5697 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(),
5698 S->getTryLoc(),
5699 TryBlock.take(),
5700 Handler.take());
5701}
5702
5703template<typename Derived>
5704StmtResult
5705TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
5706 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5707 if(Block.isInvalid()) return StmtError();
5708
5709 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(),
5710 Block.take());
5711}
5712
5713template<typename Derived>
5714StmtResult
5715TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
5716 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
5717 if(FilterExpr.isInvalid()) return StmtError();
5718
5719 StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock());
5720 if(Block.isInvalid()) return StmtError();
5721
5722 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(),
5723 FilterExpr.take(),
5724 Block.take());
5725}
5726
5727template<typename Derived>
5728StmtResult
5729TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
5730 if(isa<SEHFinallyStmt>(Handler))
5731 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
5732 else
5733 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
5734}
5735
Douglas Gregorebe10102009-08-20 07:17:43 +00005736//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005737// Expression transformation
5738//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005739template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005740ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005741TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005742 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005743}
Mike Stump11289f42009-09-09 15:08:12 +00005744
5745template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005746ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005747TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00005748 NestedNameSpecifierLoc QualifierLoc;
5749 if (E->getQualifierLoc()) {
5750 QualifierLoc
5751 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
5752 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00005753 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005754 }
John McCallce546572009-12-08 09:08:17 +00005755
5756 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005757 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5758 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005759 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005760 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005761
John McCall815039a2010-08-17 21:27:17 +00005762 DeclarationNameInfo NameInfo = E->getNameInfo();
5763 if (NameInfo.getName()) {
5764 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5765 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005766 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005767 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005768
5769 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00005770 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005771 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005772 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005773 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005774
5775 // Mark it referenced in the new context regardless.
5776 // FIXME: this is a bit instantiation-specific.
5777 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5778
John McCallc3007a22010-10-26 07:05:15 +00005779 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005780 }
John McCallce546572009-12-08 09:08:17 +00005781
5782 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005783 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005784 TemplateArgs = &TransArgs;
5785 TransArgs.setLAngleLoc(E->getLAngleLoc());
5786 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005787 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5788 E->getNumTemplateArgs(),
5789 TransArgs))
5790 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005791 }
5792
Douglas Gregorea972d32011-02-28 21:54:11 +00005793 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
5794 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005795}
Mike Stump11289f42009-09-09 15:08:12 +00005796
Douglas Gregora16548e2009-08-11 05:31:07 +00005797template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005798ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005799TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005800 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005801}
Mike Stump11289f42009-09-09 15:08:12 +00005802
Douglas Gregora16548e2009-08-11 05:31:07 +00005803template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005804ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005805TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005806 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005807}
Mike Stump11289f42009-09-09 15:08:12 +00005808
Douglas Gregora16548e2009-08-11 05:31:07 +00005809template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005810ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005811TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005812 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005813}
Mike Stump11289f42009-09-09 15:08:12 +00005814
Douglas Gregora16548e2009-08-11 05:31:07 +00005815template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005816ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005817TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005818 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005819}
Mike Stump11289f42009-09-09 15:08:12 +00005820
Douglas Gregora16548e2009-08-11 05:31:07 +00005821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005822ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005823TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005824 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005825}
5826
5827template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005828ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00005829TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
5830 ExprResult ControllingExpr =
5831 getDerived().TransformExpr(E->getControllingExpr());
5832 if (ControllingExpr.isInvalid())
5833 return ExprError();
5834
Chris Lattner01cf8db2011-07-20 06:58:45 +00005835 SmallVector<Expr *, 4> AssocExprs;
5836 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00005837 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
5838 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
5839 if (TS) {
5840 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
5841 if (!AssocType)
5842 return ExprError();
5843 AssocTypes.push_back(AssocType);
5844 } else {
5845 AssocTypes.push_back(0);
5846 }
5847
5848 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
5849 if (AssocExpr.isInvalid())
5850 return ExprError();
5851 AssocExprs.push_back(AssocExpr.release());
5852 }
5853
5854 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
5855 E->getDefaultLoc(),
5856 E->getRParenLoc(),
5857 ControllingExpr.release(),
5858 AssocTypes.data(),
5859 AssocExprs.data(),
5860 E->getNumAssocs());
5861}
5862
5863template<typename Derived>
5864ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005865TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005866 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005867 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005868 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005869
Douglas Gregora16548e2009-08-11 05:31:07 +00005870 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005871 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005872
John McCallb268a282010-08-23 23:25:46 +00005873 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005874 E->getRParen());
5875}
5876
Mike Stump11289f42009-09-09 15:08:12 +00005877template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005878ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005879TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005880 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005881 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005882 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005883
Douglas Gregora16548e2009-08-11 05:31:07 +00005884 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005885 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005886
Douglas Gregora16548e2009-08-11 05:31:07 +00005887 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5888 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005889 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005890}
Mike Stump11289f42009-09-09 15:08:12 +00005891
Douglas Gregora16548e2009-08-11 05:31:07 +00005892template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005893ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005894TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5895 // Transform the type.
5896 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5897 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005898 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005899
Douglas Gregor882211c2010-04-28 22:16:22 +00005900 // Transform all of the components into components similar to what the
5901 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005902 // FIXME: It would be slightly more efficient in the non-dependent case to
5903 // just map FieldDecls, rather than requiring the rebuilder to look for
5904 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005905 // template code that we don't care.
5906 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005907 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005908 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00005909 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00005910 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5911 const Node &ON = E->getComponent(I);
5912 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005913 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00005914 Comp.LocStart = ON.getSourceRange().getBegin();
5915 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00005916 switch (ON.getKind()) {
5917 case Node::Array: {
5918 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005919 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005920 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005921 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005922
Douglas Gregor882211c2010-04-28 22:16:22 +00005923 ExprChanged = ExprChanged || Index.get() != FromIndex;
5924 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005925 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005926 break;
5927 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005928
Douglas Gregor882211c2010-04-28 22:16:22 +00005929 case Node::Field:
5930 case Node::Identifier:
5931 Comp.isBrackets = false;
5932 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005933 if (!Comp.U.IdentInfo)
5934 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005935
Douglas Gregor882211c2010-04-28 22:16:22 +00005936 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005937
Douglas Gregord1702062010-04-29 00:18:15 +00005938 case Node::Base:
5939 // Will be recomputed during the rebuild.
5940 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005941 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005942
Douglas Gregor882211c2010-04-28 22:16:22 +00005943 Components.push_back(Comp);
5944 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005945
Douglas Gregor882211c2010-04-28 22:16:22 +00005946 // If nothing changed, retain the existing expression.
5947 if (!getDerived().AlwaysRebuild() &&
5948 Type == E->getTypeSourceInfo() &&
5949 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005950 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005951
Douglas Gregor882211c2010-04-28 22:16:22 +00005952 // Build a new offsetof expression.
5953 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5954 Components.data(), Components.size(),
5955 E->getRParenLoc());
5956}
5957
5958template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005959ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005960TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5961 assert(getDerived().AlreadyTransformed(E->getType()) &&
5962 "opaque value expression requires transformation");
5963 return SemaRef.Owned(E);
5964}
5965
5966template<typename Derived>
5967ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00005968TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
5969 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005970 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005971 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005972
John McCallbcd03502009-12-07 02:54:59 +00005973 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005974 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005975 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005976
John McCall4c98fd82009-11-04 07:28:41 +00005977 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005978 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005979
Peter Collingbournee190dee2011-03-11 19:24:49 +00005980 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
5981 E->getKind(),
5982 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00005983 }
Mike Stump11289f42009-09-09 15:08:12 +00005984
John McCalldadc5752010-08-24 06:29:42 +00005985 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005986 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005987 // C++0x [expr.sizeof]p1:
5988 // The operand is either an expression, which is an unevaluated operand
5989 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005990 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005991
Douglas Gregora16548e2009-08-11 05:31:07 +00005992 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5993 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005994 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005995
Douglas Gregora16548e2009-08-11 05:31:07 +00005996 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005997 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005998 }
Mike Stump11289f42009-09-09 15:08:12 +00005999
Peter Collingbournee190dee2011-03-11 19:24:49 +00006000 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
6001 E->getOperatorLoc(),
6002 E->getKind(),
6003 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006004}
Mike Stump11289f42009-09-09 15:08:12 +00006005
Douglas Gregora16548e2009-08-11 05:31:07 +00006006template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006007ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006008TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006009 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006010 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006011 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006012
John McCalldadc5752010-08-24 06:29:42 +00006013 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006014 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006015 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006016
6017
Douglas Gregora16548e2009-08-11 05:31:07 +00006018 if (!getDerived().AlwaysRebuild() &&
6019 LHS.get() == E->getLHS() &&
6020 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006021 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006022
John McCallb268a282010-08-23 23:25:46 +00006023 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006024 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006025 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006026 E->getRBracketLoc());
6027}
Mike Stump11289f42009-09-09 15:08:12 +00006028
6029template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006030ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006031TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006032 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00006033 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006034 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006035 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006036
6037 // Transform arguments.
6038 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006039 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006040 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6041 &ArgChanged))
6042 return ExprError();
6043
Douglas Gregora16548e2009-08-11 05:31:07 +00006044 if (!getDerived().AlwaysRebuild() &&
6045 Callee.get() == E->getCallee() &&
6046 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00006047 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006048
Douglas Gregora16548e2009-08-11 05:31:07 +00006049 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00006050 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006051 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00006052 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006053 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006054 E->getRParenLoc());
6055}
Mike Stump11289f42009-09-09 15:08:12 +00006056
6057template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006058ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006059TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006060 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006061 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006062 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006063
Douglas Gregorea972d32011-02-28 21:54:11 +00006064 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006065 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00006066 QualifierLoc
6067 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6068
6069 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00006070 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00006071 }
Mike Stump11289f42009-09-09 15:08:12 +00006072
Eli Friedman2cfcef62009-12-04 06:40:45 +00006073 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006074 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
6075 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006076 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00006077 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006078
John McCall16df1e52010-03-30 21:47:33 +00006079 NamedDecl *FoundDecl = E->getFoundDecl();
6080 if (FoundDecl == E->getMemberDecl()) {
6081 FoundDecl = Member;
6082 } else {
6083 FoundDecl = cast_or_null<NamedDecl>(
6084 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
6085 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00006086 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00006087 }
6088
Douglas Gregora16548e2009-08-11 05:31:07 +00006089 if (!getDerived().AlwaysRebuild() &&
6090 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00006091 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006092 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00006093 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00006094 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006095
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006096 // Mark it referenced in the new context regardless.
6097 // FIXME: this is a bit instantiation-specific.
6098 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00006099 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00006100 }
Douglas Gregora16548e2009-08-11 05:31:07 +00006101
John McCall6b51f282009-11-23 01:53:49 +00006102 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00006103 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00006104 TransArgs.setLAngleLoc(E->getLAngleLoc());
6105 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006106 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6107 E->getNumTemplateArgs(),
6108 TransArgs))
6109 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006110 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006111
Douglas Gregora16548e2009-08-11 05:31:07 +00006112 // FIXME: Bogus source location for the operator
6113 SourceLocation FakeOperatorLoc
6114 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
6115
John McCall38836f02010-01-15 08:34:02 +00006116 // FIXME: to do this check properly, we will need to preserve the
6117 // first-qualifier-in-scope here, just in case we had a dependent
6118 // base (and therefore couldn't do the check) and a
6119 // nested-name-qualifier (and therefore could do the lookup).
6120 NamedDecl *FirstQualifierInScope = 0;
6121
John McCallb268a282010-08-23 23:25:46 +00006122 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006123 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00006124 QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006125 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00006126 Member,
John McCall16df1e52010-03-30 21:47:33 +00006127 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00006128 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00006129 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00006130 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00006131}
Mike Stump11289f42009-09-09 15:08:12 +00006132
Douglas Gregora16548e2009-08-11 05:31:07 +00006133template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006134ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006135TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006136 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006137 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006138 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006139
John McCalldadc5752010-08-24 06:29:42 +00006140 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006141 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006142 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006143
Douglas Gregora16548e2009-08-11 05:31:07 +00006144 if (!getDerived().AlwaysRebuild() &&
6145 LHS.get() == E->getLHS() &&
6146 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006147 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006148
Douglas Gregora16548e2009-08-11 05:31:07 +00006149 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00006150 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006151}
6152
Mike Stump11289f42009-09-09 15:08:12 +00006153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006154ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006155TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00006156 CompoundAssignOperator *E) {
6157 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006158}
Mike Stump11289f42009-09-09 15:08:12 +00006159
Douglas Gregora16548e2009-08-11 05:31:07 +00006160template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00006161ExprResult TreeTransform<Derived>::
6162TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
6163 // Just rebuild the common and RHS expressions and see whether we
6164 // get any changes.
6165
6166 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
6167 if (commonExpr.isInvalid())
6168 return ExprError();
6169
6170 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
6171 if (rhs.isInvalid())
6172 return ExprError();
6173
6174 if (!getDerived().AlwaysRebuild() &&
6175 commonExpr.get() == e->getCommon() &&
6176 rhs.get() == e->getFalseExpr())
6177 return SemaRef.Owned(e);
6178
6179 return getDerived().RebuildConditionalOperator(commonExpr.take(),
6180 e->getQuestionLoc(),
6181 0,
6182 e->getColonLoc(),
6183 rhs.get());
6184}
6185
6186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006187ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006188TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00006189 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006190 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006191 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006192
John McCalldadc5752010-08-24 06:29:42 +00006193 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006194 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006195 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006196
John McCalldadc5752010-08-24 06:29:42 +00006197 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006198 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006199 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006200
Douglas Gregora16548e2009-08-11 05:31:07 +00006201 if (!getDerived().AlwaysRebuild() &&
6202 Cond.get() == E->getCond() &&
6203 LHS.get() == E->getLHS() &&
6204 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006205 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006206
John McCallb268a282010-08-23 23:25:46 +00006207 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006208 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00006209 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00006210 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006211 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006212}
Mike Stump11289f42009-09-09 15:08:12 +00006213
6214template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006215ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006216TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00006217 // Implicit casts are eliminated during transformation, since they
6218 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00006219 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006220}
Mike Stump11289f42009-09-09 15:08:12 +00006221
Douglas Gregora16548e2009-08-11 05:31:07 +00006222template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006223ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006224TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006225 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6226 if (!Type)
6227 return ExprError();
6228
John McCalldadc5752010-08-24 06:29:42 +00006229 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006230 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006231 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006232 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006233
Douglas Gregora16548e2009-08-11 05:31:07 +00006234 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006235 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006236 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006237 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006238
John McCall97513962010-01-15 18:39:57 +00006239 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006240 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006241 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006242 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006243}
Mike Stump11289f42009-09-09 15:08:12 +00006244
Douglas Gregora16548e2009-08-11 05:31:07 +00006245template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006246ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006247TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00006248 TypeSourceInfo *OldT = E->getTypeSourceInfo();
6249 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
6250 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00006251 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006252
John McCalldadc5752010-08-24 06:29:42 +00006253 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00006254 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006255 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006256
Douglas Gregora16548e2009-08-11 05:31:07 +00006257 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00006258 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006259 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00006260 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006261
John McCall5d7aa7f2010-01-19 22:33:45 +00006262 // Note: the expression type doesn't necessarily match the
6263 // type-as-written, but that's okay, because it should always be
6264 // derivable from the initializer.
6265
John McCalle15bbff2010-01-18 19:35:47 +00006266 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00006267 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00006268 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006269}
Mike Stump11289f42009-09-09 15:08:12 +00006270
Douglas Gregora16548e2009-08-11 05:31:07 +00006271template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006272ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006273TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006274 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00006275 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006276 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006277
Douglas Gregora16548e2009-08-11 05:31:07 +00006278 if (!getDerived().AlwaysRebuild() &&
6279 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00006280 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006281
Douglas Gregora16548e2009-08-11 05:31:07 +00006282 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00006283 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006284 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00006285 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00006286 E->getAccessorLoc(),
6287 E->getAccessor());
6288}
Mike Stump11289f42009-09-09 15:08:12 +00006289
Douglas Gregora16548e2009-08-11 05:31:07 +00006290template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006291ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006292TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006293 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00006294
John McCall37ad5512010-08-23 06:44:23 +00006295 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006296 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
6297 Inits, &InitChanged))
6298 return ExprError();
6299
Douglas Gregora16548e2009-08-11 05:31:07 +00006300 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00006301 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006302
Douglas Gregora16548e2009-08-11 05:31:07 +00006303 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00006304 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00006305}
Mike Stump11289f42009-09-09 15:08:12 +00006306
Douglas Gregora16548e2009-08-11 05:31:07 +00006307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006308ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006309TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006310 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00006311
Douglas Gregorebe10102009-08-20 07:17:43 +00006312 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00006313 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006314 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006315 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006316
Douglas Gregorebe10102009-08-20 07:17:43 +00006317 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00006318 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006319 bool ExprChanged = false;
6320 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
6321 DEnd = E->designators_end();
6322 D != DEnd; ++D) {
6323 if (D->isFieldDesignator()) {
6324 Desig.AddDesignator(Designator::getField(D->getFieldName(),
6325 D->getDotLoc(),
6326 D->getFieldLoc()));
6327 continue;
6328 }
Mike Stump11289f42009-09-09 15:08:12 +00006329
Douglas Gregora16548e2009-08-11 05:31:07 +00006330 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00006331 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006332 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006333 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006334
6335 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006336 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006337
Douglas Gregora16548e2009-08-11 05:31:07 +00006338 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
6339 ArrayExprs.push_back(Index.release());
6340 continue;
6341 }
Mike Stump11289f42009-09-09 15:08:12 +00006342
Douglas Gregora16548e2009-08-11 05:31:07 +00006343 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00006344 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00006345 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
6346 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006347 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006348
John McCalldadc5752010-08-24 06:29:42 +00006349 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00006350 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006351 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006352
6353 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006354 End.get(),
6355 D->getLBracketLoc(),
6356 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00006357
Douglas Gregora16548e2009-08-11 05:31:07 +00006358 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
6359 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00006360
Douglas Gregora16548e2009-08-11 05:31:07 +00006361 ArrayExprs.push_back(Start.release());
6362 ArrayExprs.push_back(End.release());
6363 }
Mike Stump11289f42009-09-09 15:08:12 +00006364
Douglas Gregora16548e2009-08-11 05:31:07 +00006365 if (!getDerived().AlwaysRebuild() &&
6366 Init.get() == E->getInit() &&
6367 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00006368 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006369
Douglas Gregora16548e2009-08-11 05:31:07 +00006370 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
6371 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00006372 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006373}
Mike Stump11289f42009-09-09 15:08:12 +00006374
Douglas Gregora16548e2009-08-11 05:31:07 +00006375template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006376ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006377TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006378 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00006379 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006380
Douglas Gregor3da3c062009-10-28 00:29:27 +00006381 // FIXME: Will we ever have proper type location here? Will we actually
6382 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00006383 QualType T = getDerived().TransformType(E->getType());
6384 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006385 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006386
Douglas Gregora16548e2009-08-11 05:31:07 +00006387 if (!getDerived().AlwaysRebuild() &&
6388 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006389 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006390
Douglas Gregora16548e2009-08-11 05:31:07 +00006391 return getDerived().RebuildImplicitValueInitExpr(T);
6392}
Mike Stump11289f42009-09-09 15:08:12 +00006393
Douglas Gregora16548e2009-08-11 05:31:07 +00006394template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006395ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006396TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00006397 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
6398 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006399 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006400
John McCalldadc5752010-08-24 06:29:42 +00006401 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006402 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006403 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006404
Douglas Gregora16548e2009-08-11 05:31:07 +00006405 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00006406 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006407 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006408 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006409
John McCallb268a282010-08-23 23:25:46 +00006410 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00006411 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006412}
6413
6414template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006415ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006416TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006417 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006418 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006419 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6420 &ArgumentChanged))
6421 return ExprError();
6422
Douglas Gregora16548e2009-08-11 05:31:07 +00006423 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6424 move_arg(Inits),
6425 E->getRParenLoc());
6426}
Mike Stump11289f42009-09-09 15:08:12 +00006427
Douglas Gregora16548e2009-08-11 05:31:07 +00006428/// \brief Transform an address-of-label expression.
6429///
6430/// By default, the transformation of an address-of-label expression always
6431/// rebuilds the expression, so that the label identifier can be resolved to
6432/// the corresponding label statement by semantic analysis.
6433template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006434ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006435TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006436 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6437 E->getLabel());
6438 if (!LD)
6439 return ExprError();
6440
Douglas Gregora16548e2009-08-11 05:31:07 +00006441 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006442 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006443}
Mike Stump11289f42009-09-09 15:08:12 +00006444
6445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006446ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006447TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006448 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006449 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6450 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006452
Douglas Gregora16548e2009-08-11 05:31:07 +00006453 if (!getDerived().AlwaysRebuild() &&
6454 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006455 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006456
6457 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006458 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006459 E->getRParenLoc());
6460}
Mike Stump11289f42009-09-09 15:08:12 +00006461
Douglas Gregora16548e2009-08-11 05:31:07 +00006462template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006463ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006464TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006465 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006466 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006467 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006468
John McCalldadc5752010-08-24 06:29:42 +00006469 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006470 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006471 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006472
John McCalldadc5752010-08-24 06:29:42 +00006473 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006474 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006475 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006476
Douglas Gregora16548e2009-08-11 05:31:07 +00006477 if (!getDerived().AlwaysRebuild() &&
6478 Cond.get() == E->getCond() &&
6479 LHS.get() == E->getLHS() &&
6480 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006481 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006482
Douglas Gregora16548e2009-08-11 05:31:07 +00006483 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006484 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006485 E->getRParenLoc());
6486}
Mike Stump11289f42009-09-09 15:08:12 +00006487
Douglas Gregora16548e2009-08-11 05:31:07 +00006488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006489ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006490TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006491 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006492}
6493
6494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006495ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006496TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006497 switch (E->getOperator()) {
6498 case OO_New:
6499 case OO_Delete:
6500 case OO_Array_New:
6501 case OO_Array_Delete:
6502 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006503 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006504
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006505 case OO_Call: {
6506 // This is a call to an object's operator().
6507 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6508
6509 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006510 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006511 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006512 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006513
6514 // FIXME: Poor location information
6515 SourceLocation FakeLParenLoc
6516 = SemaRef.PP.getLocForEndOfToken(
6517 static_cast<Expr *>(Object.get())->getLocEnd());
6518
6519 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006520 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006521 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6522 Args))
6523 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006524
John McCallb268a282010-08-23 23:25:46 +00006525 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006526 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006527 E->getLocEnd());
6528 }
6529
6530#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6531 case OO_##Name:
6532#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6533#include "clang/Basic/OperatorKinds.def"
6534 case OO_Subscript:
6535 // Handled below.
6536 break;
6537
6538 case OO_Conditional:
6539 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006540 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006541
6542 case OO_None:
6543 case NUM_OVERLOADED_OPERATORS:
6544 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006545 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006546 }
6547
John McCalldadc5752010-08-24 06:29:42 +00006548 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006549 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006550 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006551
John McCalldadc5752010-08-24 06:29:42 +00006552 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006553 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006554 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006555
John McCalldadc5752010-08-24 06:29:42 +00006556 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006557 if (E->getNumArgs() == 2) {
6558 Second = getDerived().TransformExpr(E->getArg(1));
6559 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006560 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006561 }
Mike Stump11289f42009-09-09 15:08:12 +00006562
Douglas Gregora16548e2009-08-11 05:31:07 +00006563 if (!getDerived().AlwaysRebuild() &&
6564 Callee.get() == E->getCallee() &&
6565 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006566 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006567 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006568
Douglas Gregora16548e2009-08-11 05:31:07 +00006569 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6570 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006571 Callee.get(),
6572 First.get(),
6573 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006574}
Mike Stump11289f42009-09-09 15:08:12 +00006575
Douglas Gregora16548e2009-08-11 05:31:07 +00006576template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006577ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006578TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6579 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006580}
Mike Stump11289f42009-09-09 15:08:12 +00006581
Douglas Gregora16548e2009-08-11 05:31:07 +00006582template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006583ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006584TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6585 // Transform the callee.
6586 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6587 if (Callee.isInvalid())
6588 return ExprError();
6589
6590 // Transform exec config.
6591 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6592 if (EC.isInvalid())
6593 return ExprError();
6594
6595 // Transform arguments.
6596 bool ArgChanged = false;
6597 ASTOwningVector<Expr*> Args(SemaRef);
6598 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6599 &ArgChanged))
6600 return ExprError();
6601
6602 if (!getDerived().AlwaysRebuild() &&
6603 Callee.get() == E->getCallee() &&
6604 !ArgChanged)
6605 return SemaRef.Owned(E);
6606
6607 // FIXME: Wrong source location information for the '('.
6608 SourceLocation FakeLParenLoc
6609 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6610 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6611 move_arg(Args),
6612 E->getRParenLoc(), EC.get());
6613}
6614
6615template<typename Derived>
6616ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006617TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006618 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6619 if (!Type)
6620 return ExprError();
6621
John McCalldadc5752010-08-24 06:29:42 +00006622 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006623 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006624 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006625 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006626
Douglas Gregora16548e2009-08-11 05:31:07 +00006627 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006628 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006629 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006630 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006631
Douglas Gregora16548e2009-08-11 05:31:07 +00006632 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006633 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006634 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6635 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6636 SourceLocation FakeRParenLoc
6637 = SemaRef.PP.getLocForEndOfToken(
6638 E->getSubExpr()->getSourceRange().getEnd());
6639 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006640 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006641 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006642 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006643 FakeRAngleLoc,
6644 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006645 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006646 FakeRParenLoc);
6647}
Mike Stump11289f42009-09-09 15:08:12 +00006648
Douglas Gregora16548e2009-08-11 05:31:07 +00006649template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006650ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006651TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6652 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006653}
Mike Stump11289f42009-09-09 15:08:12 +00006654
6655template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006656ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006657TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6658 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006659}
6660
Douglas Gregora16548e2009-08-11 05:31:07 +00006661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006662ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006663TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006664 CXXReinterpretCastExpr *E) {
6665 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006666}
Mike Stump11289f42009-09-09 15:08:12 +00006667
Douglas Gregora16548e2009-08-11 05:31:07 +00006668template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006669ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006670TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6671 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006672}
Mike Stump11289f42009-09-09 15:08:12 +00006673
Douglas Gregora16548e2009-08-11 05:31:07 +00006674template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006675ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006676TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006677 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006678 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6679 if (!Type)
6680 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006681
John McCalldadc5752010-08-24 06:29:42 +00006682 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006683 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006684 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006685 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006686
Douglas Gregora16548e2009-08-11 05:31:07 +00006687 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006688 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006689 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006690 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006691
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006692 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006693 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006694 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006695 E->getRParenLoc());
6696}
Mike Stump11289f42009-09-09 15:08:12 +00006697
Douglas Gregora16548e2009-08-11 05:31:07 +00006698template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006699ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006700TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006701 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006702 TypeSourceInfo *TInfo
6703 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6704 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006705 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006706
Douglas Gregora16548e2009-08-11 05:31:07 +00006707 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006708 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006709 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006710
Douglas Gregor9da64192010-04-26 22:37:10 +00006711 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6712 E->getLocStart(),
6713 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006714 E->getLocEnd());
6715 }
Mike Stump11289f42009-09-09 15:08:12 +00006716
Douglas Gregora16548e2009-08-11 05:31:07 +00006717 // We don't know whether the expression is potentially evaluated until
6718 // after we perform semantic analysis, so the expression is potentially
6719 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006720 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006721 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006722
John McCalldadc5752010-08-24 06:29:42 +00006723 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006724 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006725 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006726
Douglas Gregora16548e2009-08-11 05:31:07 +00006727 if (!getDerived().AlwaysRebuild() &&
6728 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006729 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006730
Douglas Gregor9da64192010-04-26 22:37:10 +00006731 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6732 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006733 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006734 E->getLocEnd());
6735}
6736
6737template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006738ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006739TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6740 if (E->isTypeOperand()) {
6741 TypeSourceInfo *TInfo
6742 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6743 if (!TInfo)
6744 return ExprError();
6745
6746 if (!getDerived().AlwaysRebuild() &&
6747 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006748 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006749
Douglas Gregor69735112011-03-06 17:40:41 +00006750 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00006751 E->getLocStart(),
6752 TInfo,
6753 E->getLocEnd());
6754 }
6755
6756 // We don't know whether the expression is potentially evaluated until
6757 // after we perform semantic analysis, so the expression is potentially
6758 // potentially evaluated.
6759 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6760
6761 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6762 if (SubExpr.isInvalid())
6763 return ExprError();
6764
6765 if (!getDerived().AlwaysRebuild() &&
6766 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006767 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006768
6769 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6770 E->getLocStart(),
6771 SubExpr.get(),
6772 E->getLocEnd());
6773}
6774
6775template<typename Derived>
6776ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006777TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006778 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006779}
Mike Stump11289f42009-09-09 15:08:12 +00006780
Douglas Gregora16548e2009-08-11 05:31:07 +00006781template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006782ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006783TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006784 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006785 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006786}
Mike Stump11289f42009-09-09 15:08:12 +00006787
Douglas Gregora16548e2009-08-11 05:31:07 +00006788template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006789ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006790TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006791 DeclContext *DC = getSema().getFunctionLevelDeclContext();
Richard Smith938f40b2011-06-11 17:19:42 +00006792 QualType T;
6793 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC))
6794 T = MD->getThisType(getSema().Context);
6795 else
6796 T = getSema().Context.getPointerType(
6797 getSema().Context.getRecordType(cast<CXXRecordDecl>(DC)));
Mike Stump11289f42009-09-09 15:08:12 +00006798
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006799 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006800 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006801
Douglas Gregorb15af892010-01-07 23:12:05 +00006802 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006803}
Mike Stump11289f42009-09-09 15:08:12 +00006804
Douglas Gregora16548e2009-08-11 05:31:07 +00006805template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006806ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006807TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006808 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006809 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006810 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006811
Douglas Gregora16548e2009-08-11 05:31:07 +00006812 if (!getDerived().AlwaysRebuild() &&
6813 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006814 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006815
Douglas Gregor53e191ed2011-07-06 22:04:06 +00006816 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
6817 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00006818}
Mike Stump11289f42009-09-09 15:08:12 +00006819
Douglas Gregora16548e2009-08-11 05:31:07 +00006820template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006821ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006822TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006823 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006824 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6825 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006826 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006827 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006828
Chandler Carruth794da4c2010-02-08 06:42:49 +00006829 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006830 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006831 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006832
Douglas Gregor033f6752009-12-23 23:03:06 +00006833 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006834}
Mike Stump11289f42009-09-09 15:08:12 +00006835
Douglas Gregora16548e2009-08-11 05:31:07 +00006836template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006837ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006838TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6839 CXXScalarValueInitExpr *E) {
6840 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6841 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006842 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006843
Douglas Gregora16548e2009-08-11 05:31:07 +00006844 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006845 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006846 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006847
Douglas Gregor2b88c112010-09-08 00:15:04 +00006848 return getDerived().RebuildCXXScalarValueInitExpr(T,
6849 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006850 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006851}
Mike Stump11289f42009-09-09 15:08:12 +00006852
Douglas Gregora16548e2009-08-11 05:31:07 +00006853template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006854ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006855TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006856 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006857 TypeSourceInfo *AllocTypeInfo
6858 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6859 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006860 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006861
Douglas Gregora16548e2009-08-11 05:31:07 +00006862 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006863 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006864 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006865 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006866
Douglas Gregora16548e2009-08-11 05:31:07 +00006867 // Transform the placement arguments (if any).
6868 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006869 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006870 if (getDerived().TransformExprs(E->getPlacementArgs(),
6871 E->getNumPlacementArgs(), true,
6872 PlacementArgs, &ArgumentChanged))
6873 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006874
Douglas Gregorebe10102009-08-20 07:17:43 +00006875 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006876 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006877 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6878 ConstructorArgs, &ArgumentChanged))
6879 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006880
Douglas Gregord2d9da02010-02-26 00:38:10 +00006881 // Transform constructor, new operator, and delete operator.
6882 CXXConstructorDecl *Constructor = 0;
6883 if (E->getConstructor()) {
6884 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006885 getDerived().TransformDecl(E->getLocStart(),
6886 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006887 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006888 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006889 }
6890
6891 FunctionDecl *OperatorNew = 0;
6892 if (E->getOperatorNew()) {
6893 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006894 getDerived().TransformDecl(E->getLocStart(),
6895 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006896 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006897 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006898 }
6899
6900 FunctionDecl *OperatorDelete = 0;
6901 if (E->getOperatorDelete()) {
6902 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006903 getDerived().TransformDecl(E->getLocStart(),
6904 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006905 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006906 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006907 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006908
Douglas Gregora16548e2009-08-11 05:31:07 +00006909 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006910 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006911 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006912 Constructor == E->getConstructor() &&
6913 OperatorNew == E->getOperatorNew() &&
6914 OperatorDelete == E->getOperatorDelete() &&
6915 !ArgumentChanged) {
6916 // Mark any declarations we need as referenced.
6917 // FIXME: instantiation-specific.
6918 if (Constructor)
6919 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6920 if (OperatorNew)
6921 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6922 if (OperatorDelete)
6923 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor72912fb2011-07-26 15:11:03 +00006924
6925 if (E->isArray() && Constructor &&
6926 !E->getAllocatedType()->isDependentType()) {
6927 QualType ElementType
6928 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
6929 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
6930 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
6931 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
6932 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor);
6933 }
6934 }
6935 }
6936
John McCallc3007a22010-10-26 07:05:15 +00006937 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006938 }
Mike Stump11289f42009-09-09 15:08:12 +00006939
Douglas Gregor0744ef62010-09-07 21:49:58 +00006940 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006941 if (!ArraySize.get()) {
6942 // If no array size was specified, but the new expression was
6943 // instantiated with an array type (e.g., "new T" where T is
6944 // instantiated with "int[4]"), extract the outer bound from the
6945 // array type as our array size. We do this with constant and
6946 // dependently-sized array types.
6947 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6948 if (!ArrayT) {
6949 // Do nothing
6950 } else if (const ConstantArrayType *ConsArrayT
6951 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006952 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006953 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6954 ConsArrayT->getSize(),
6955 SemaRef.Context.getSizeType(),
6956 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006957 AllocType = ConsArrayT->getElementType();
6958 } else if (const DependentSizedArrayType *DepArrayT
6959 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6960 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006961 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006962 AllocType = DepArrayT->getElementType();
6963 }
6964 }
6965 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006966
Douglas Gregora16548e2009-08-11 05:31:07 +00006967 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6968 E->isGlobalNew(),
6969 /*FIXME:*/E->getLocStart(),
6970 move_arg(PlacementArgs),
6971 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006972 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006973 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006974 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006975 ArraySize.get(),
Douglas Gregor3bdcff52011-06-27 16:55:54 +00006976 /*FIXME:*/E->hasInitializer()
6977 ? E->getLocStart()
6978 : SourceLocation(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006979 move_arg(ConstructorArgs),
Douglas Gregor3bdcff52011-06-27 16:55:54 +00006980 /*FIXME:*/E->hasInitializer()
6981 ? E->getLocEnd()
6982 : SourceLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00006983}
Mike Stump11289f42009-09-09 15:08:12 +00006984
Douglas Gregora16548e2009-08-11 05:31:07 +00006985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006986ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006987TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006988 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006989 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006990 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006991
Douglas Gregord2d9da02010-02-26 00:38:10 +00006992 // Transform the delete operator, if known.
6993 FunctionDecl *OperatorDelete = 0;
6994 if (E->getOperatorDelete()) {
6995 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006996 getDerived().TransformDecl(E->getLocStart(),
6997 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006998 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006999 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00007000 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007001
Douglas Gregora16548e2009-08-11 05:31:07 +00007002 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00007003 Operand.get() == E->getArgument() &&
7004 OperatorDelete == E->getOperatorDelete()) {
7005 // Mark any declarations we need as referenced.
7006 // FIXME: instantiation-specific.
7007 if (OperatorDelete)
7008 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00007009
7010 if (!E->getArgument()->isTypeDependent()) {
7011 QualType Destroyed = SemaRef.Context.getBaseElementType(
7012 E->getDestroyedType());
7013 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
7014 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
7015 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
7016 SemaRef.LookupDestructor(Record));
7017 }
7018 }
7019
John McCallc3007a22010-10-26 07:05:15 +00007020 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00007021 }
Mike Stump11289f42009-09-09 15:08:12 +00007022
Douglas Gregora16548e2009-08-11 05:31:07 +00007023 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
7024 E->isGlobalDelete(),
7025 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00007026 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007027}
Mike Stump11289f42009-09-09 15:08:12 +00007028
Douglas Gregora16548e2009-08-11 05:31:07 +00007029template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007030ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00007031TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007032 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007033 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00007034 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007035 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007036
John McCallba7bf592010-08-24 05:47:05 +00007037 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00007038 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007039 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007040 E->getOperatorLoc(),
7041 E->isArrow()? tok::arrow : tok::period,
7042 ObjectTypePtr,
7043 MayBePseudoDestructor);
7044 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007045 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007046
John McCallba7bf592010-08-24 05:47:05 +00007047 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00007048 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
7049 if (QualifierLoc) {
7050 QualifierLoc
7051 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
7052 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00007053 return ExprError();
7054 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00007055 CXXScopeSpec SS;
7056 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00007057
Douglas Gregor678f90d2010-02-25 01:56:36 +00007058 PseudoDestructorTypeStorage Destroyed;
7059 if (E->getDestroyedTypeInfo()) {
7060 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00007061 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00007062 ObjectType, 0, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00007063 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007064 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00007065 Destroyed = DestroyedTypeInfo;
7066 } else if (ObjectType->isDependentType()) {
7067 // We aren't likely to be able to resolve the identifier down to a type
7068 // now anyway, so just retain the identifier.
7069 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
7070 E->getDestroyedTypeLoc());
7071 } else {
7072 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00007073 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007074 *E->getDestroyedTypeIdentifier(),
7075 E->getDestroyedTypeLoc(),
7076 /*Scope=*/0,
7077 SS, ObjectTypePtr,
7078 false);
7079 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007080 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007081
Douglas Gregor678f90d2010-02-25 01:56:36 +00007082 Destroyed
7083 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
7084 E->getDestroyedTypeLoc());
7085 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007086
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007087 TypeSourceInfo *ScopeTypeInfo = 0;
7088 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00007089 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007090 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007091 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00007092 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007093
John McCallb268a282010-08-23 23:25:46 +00007094 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00007095 E->getOperatorLoc(),
7096 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00007097 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007098 ScopeTypeInfo,
7099 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007100 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00007101 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00007102}
Mike Stump11289f42009-09-09 15:08:12 +00007103
Douglas Gregorad8a3362009-09-04 17:36:40 +00007104template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007105ExprResult
John McCalld14a8642009-11-21 08:51:07 +00007106TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007107 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00007108 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
7109 Sema::LookupOrdinaryName);
7110
7111 // Transform all the decls.
7112 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
7113 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007114 NamedDecl *InstD = static_cast<NamedDecl*>(
7115 getDerived().TransformDecl(Old->getNameLoc(),
7116 *I));
John McCall84d87672009-12-10 09:41:52 +00007117 if (!InstD) {
7118 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7119 // This can happen because of dependent hiding.
7120 if (isa<UsingShadowDecl>(*I))
7121 continue;
7122 else
John McCallfaf5fb42010-08-26 23:41:50 +00007123 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007124 }
John McCalle66edc12009-11-24 19:00:30 +00007125
7126 // Expand using declarations.
7127 if (isa<UsingDecl>(InstD)) {
7128 UsingDecl *UD = cast<UsingDecl>(InstD);
7129 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7130 E = UD->shadow_end(); I != E; ++I)
7131 R.addDecl(*I);
7132 continue;
7133 }
7134
7135 R.addDecl(InstD);
7136 }
7137
7138 // Resolve a kind, but don't do any further analysis. If it's
7139 // ambiguous, the callee needs to deal with it.
7140 R.resolveKind();
7141
7142 // Rebuild the nested-name qualifier, if present.
7143 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00007144 if (Old->getQualifierLoc()) {
7145 NestedNameSpecifierLoc QualifierLoc
7146 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7147 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007148 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007149
Douglas Gregor0da1d432011-02-28 20:01:57 +00007150 SS.Adopt(QualifierLoc);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007151 }
7152
Douglas Gregor9262f472010-04-27 18:19:34 +00007153 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00007154 CXXRecordDecl *NamingClass
7155 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
7156 Old->getNameLoc(),
7157 Old->getNamingClass()));
7158 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007159 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007160
Douglas Gregorda7be082010-04-27 16:10:10 +00007161 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00007162 }
7163
7164 // If we have no template arguments, it's a normal declaration name.
7165 if (!Old->hasExplicitTemplateArgs())
7166 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
7167
7168 // If we have template arguments, rebuild them, then rebuild the
7169 // templateid expression.
7170 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007171 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7172 Old->getNumTemplateArgs(),
7173 TransArgs))
7174 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00007175
7176 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
7177 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007178}
Mike Stump11289f42009-09-09 15:08:12 +00007179
Douglas Gregora16548e2009-08-11 05:31:07 +00007180template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007181ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007182TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00007183 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7184 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007185 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007186
Douglas Gregora16548e2009-08-11 05:31:07 +00007187 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00007188 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007189 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007190
Mike Stump11289f42009-09-09 15:08:12 +00007191 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007192 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007193 T,
7194 E->getLocEnd());
7195}
Mike Stump11289f42009-09-09 15:08:12 +00007196
Douglas Gregora16548e2009-08-11 05:31:07 +00007197template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007198ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00007199TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
7200 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
7201 if (!LhsT)
7202 return ExprError();
7203
7204 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
7205 if (!RhsT)
7206 return ExprError();
7207
7208 if (!getDerived().AlwaysRebuild() &&
7209 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
7210 return SemaRef.Owned(E);
7211
7212 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
7213 E->getLocStart(),
7214 LhsT, RhsT,
7215 E->getLocEnd());
7216}
7217
7218template<typename Derived>
7219ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00007220TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
7221 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
7222 if (!T)
7223 return ExprError();
7224
7225 if (!getDerived().AlwaysRebuild() &&
7226 T == E->getQueriedTypeSourceInfo())
7227 return SemaRef.Owned(E);
7228
7229 ExprResult SubExpr;
7230 {
7231 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7232 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
7233 if (SubExpr.isInvalid())
7234 return ExprError();
7235
7236 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
7237 return SemaRef.Owned(E);
7238 }
7239
7240 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
7241 E->getLocStart(),
7242 T,
7243 SubExpr.get(),
7244 E->getLocEnd());
7245}
7246
7247template<typename Derived>
7248ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00007249TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
7250 ExprResult SubExpr;
7251 {
7252 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
7253 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
7254 if (SubExpr.isInvalid())
7255 return ExprError();
7256
7257 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
7258 return SemaRef.Owned(E);
7259 }
7260
7261 return getDerived().RebuildExpressionTrait(
7262 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
7263}
7264
7265template<typename Derived>
7266ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007267TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007268 DependentScopeDeclRefExpr *E) {
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007269 NestedNameSpecifierLoc QualifierLoc
7270 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7271 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007272 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007273
John McCall31f82722010-11-12 08:19:04 +00007274 // TODO: If this is a conversion-function-id, verify that the
7275 // destination type name (if present) resolves the same way after
7276 // instantiation as it did in the local scope.
7277
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007278 DeclarationNameInfo NameInfo
7279 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
7280 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007281 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007282
John McCalle66edc12009-11-24 19:00:30 +00007283 if (!E->hasExplicitTemplateArgs()) {
7284 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007285 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007286 // Note: it is sufficient to compare the Name component of NameInfo:
7287 // if name has not changed, DNLoc has not changed either.
7288 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00007289 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007290
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007291 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007292 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007293 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00007294 }
John McCall6b51f282009-11-23 01:53:49 +00007295
7296 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007297 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7298 E->getNumTemplateArgs(),
7299 TransArgs))
7300 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007301
Douglas Gregor3a43fd62011-02-25 20:49:16 +00007302 return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007303 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00007304 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007305}
7306
7307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007308ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007309TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00007310 // CXXConstructExprs are always implicit, so when we have a
7311 // 1-argument construction we just transform that argument.
7312 if (E->getNumArgs() == 1 ||
7313 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
7314 return getDerived().TransformExpr(E->getArg(0));
7315
Douglas Gregora16548e2009-08-11 05:31:07 +00007316 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
7317
7318 QualType T = getDerived().TransformType(E->getType());
7319 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00007320 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007321
7322 CXXConstructorDecl *Constructor
7323 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007324 getDerived().TransformDecl(E->getLocStart(),
7325 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007326 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007327 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007328
Douglas Gregora16548e2009-08-11 05:31:07 +00007329 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007330 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007331 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7332 &ArgumentChanged))
7333 return ExprError();
7334
Douglas Gregora16548e2009-08-11 05:31:07 +00007335 if (!getDerived().AlwaysRebuild() &&
7336 T == E->getType() &&
7337 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00007338 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00007339 // Mark the constructor as referenced.
7340 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00007341 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007342 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00007343 }
Mike Stump11289f42009-09-09 15:08:12 +00007344
Douglas Gregordb121ba2009-12-14 16:27:04 +00007345 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
7346 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00007347 move_arg(Args),
7348 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00007349 E->getConstructionKind(),
7350 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007351}
Mike Stump11289f42009-09-09 15:08:12 +00007352
Douglas Gregora16548e2009-08-11 05:31:07 +00007353/// \brief Transform a C++ temporary-binding expression.
7354///
Douglas Gregor363b1512009-12-24 18:51:59 +00007355/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
7356/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007357template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007358ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007359TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007360 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007361}
Mike Stump11289f42009-09-09 15:08:12 +00007362
John McCall5d413782010-12-06 08:20:24 +00007363/// \brief Transform a C++ expression that contains cleanups that should
7364/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00007365///
John McCall5d413782010-12-06 08:20:24 +00007366/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00007367/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00007368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007369ExprResult
John McCall5d413782010-12-06 08:20:24 +00007370TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00007371 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007372}
Mike Stump11289f42009-09-09 15:08:12 +00007373
Douglas Gregora16548e2009-08-11 05:31:07 +00007374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007375ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007376TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00007377 CXXTemporaryObjectExpr *E) {
7378 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7379 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007380 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007381
Douglas Gregora16548e2009-08-11 05:31:07 +00007382 CXXConstructorDecl *Constructor
7383 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00007384 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007385 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007386 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00007387 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007388
Douglas Gregora16548e2009-08-11 05:31:07 +00007389 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007390 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00007391 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00007392 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
7393 &ArgumentChanged))
7394 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007395
Douglas Gregora16548e2009-08-11 05:31:07 +00007396 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007397 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007398 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007399 !ArgumentChanged) {
7400 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00007401 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00007402 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00007403 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00007404
7405 return getDerived().RebuildCXXTemporaryObjectExpr(T,
7406 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007407 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007408 E->getLocEnd());
7409}
Mike Stump11289f42009-09-09 15:08:12 +00007410
Douglas Gregora16548e2009-08-11 05:31:07 +00007411template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007412ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007413TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00007414 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00007415 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
7416 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00007417 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007418
Douglas Gregora16548e2009-08-11 05:31:07 +00007419 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007420 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007421 Args.reserve(E->arg_size());
7422 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
7423 &ArgumentChanged))
7424 return ExprError();
7425
Douglas Gregora16548e2009-08-11 05:31:07 +00007426 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00007427 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00007428 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007429 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007430
Douglas Gregora16548e2009-08-11 05:31:07 +00007431 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00007432 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00007433 E->getLParenLoc(),
7434 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00007435 E->getRParenLoc());
7436}
Mike Stump11289f42009-09-09 15:08:12 +00007437
Douglas Gregora16548e2009-08-11 05:31:07 +00007438template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007439ExprResult
John McCall8cd78132009-11-19 22:55:06 +00007440TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007441 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007442 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007443 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007444 Expr *OldBase;
7445 QualType BaseType;
7446 QualType ObjectType;
7447 if (!E->isImplicitAccess()) {
7448 OldBase = E->getBase();
7449 Base = getDerived().TransformExpr(OldBase);
7450 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007451 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007452
John McCall2d74de92009-12-01 22:10:20 +00007453 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00007454 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00007455 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00007456 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007457 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007458 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00007459 ObjectTy,
7460 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00007461 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007462 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007463
John McCallba7bf592010-08-24 05:47:05 +00007464 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00007465 BaseType = ((Expr*) Base.get())->getType();
7466 } else {
7467 OldBase = 0;
7468 BaseType = getDerived().TransformType(E->getBaseType());
7469 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
7470 }
Mike Stump11289f42009-09-09 15:08:12 +00007471
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007472 // Transform the first part of the nested-name-specifier that qualifies
7473 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007474 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00007475 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00007476 E->getFirstQualifierFoundInScope(),
7477 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00007478
Douglas Gregore16af532011-02-28 18:50:33 +00007479 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007480 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00007481 QualifierLoc
7482 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
7483 ObjectType,
7484 FirstQualifierInScope);
7485 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007486 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007487 }
Mike Stump11289f42009-09-09 15:08:12 +00007488
John McCall31f82722010-11-12 08:19:04 +00007489 // TODO: If this is a conversion-function-id, verify that the
7490 // destination type name (if present) resolves the same way after
7491 // instantiation as it did in the local scope.
7492
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007493 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007494 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007495 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007496 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007497
John McCall2d74de92009-12-01 22:10:20 +00007498 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007499 // This is a reference to a member without an explicitly-specified
7500 // template argument list. Optimize for this common case.
7501 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007502 Base.get() == OldBase &&
7503 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00007504 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007505 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007506 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007507 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007508
John McCallb268a282010-08-23 23:25:46 +00007509 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007510 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007511 E->isArrow(),
7512 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007513 QualifierLoc,
John McCall10eae182009-11-30 22:42:35 +00007514 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007515 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007516 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007517 }
7518
John McCall6b51f282009-11-23 01:53:49 +00007519 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007520 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7521 E->getNumTemplateArgs(),
7522 TransArgs))
7523 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007524
John McCallb268a282010-08-23 23:25:46 +00007525 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007526 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007527 E->isArrow(),
7528 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00007529 QualifierLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00007530 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007531 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007532 &TransArgs);
7533}
7534
7535template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007536ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007537TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007538 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007539 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007540 QualType BaseType;
7541 if (!Old->isImplicitAccess()) {
7542 Base = getDerived().TransformExpr(Old->getBase());
7543 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007544 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007545 BaseType = ((Expr*) Base.get())->getType();
7546 } else {
7547 BaseType = getDerived().TransformType(Old->getBaseType());
7548 }
John McCall10eae182009-11-30 22:42:35 +00007549
Douglas Gregor0da1d432011-02-28 20:01:57 +00007550 NestedNameSpecifierLoc QualifierLoc;
7551 if (Old->getQualifierLoc()) {
7552 QualifierLoc
7553 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
7554 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007555 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007556 }
7557
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007558 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007559 Sema::LookupOrdinaryName);
7560
7561 // Transform all the decls.
7562 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7563 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007564 NamedDecl *InstD = static_cast<NamedDecl*>(
7565 getDerived().TransformDecl(Old->getMemberLoc(),
7566 *I));
John McCall84d87672009-12-10 09:41:52 +00007567 if (!InstD) {
7568 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7569 // This can happen because of dependent hiding.
7570 if (isa<UsingShadowDecl>(*I))
7571 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007572 else {
7573 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00007574 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00007575 }
John McCall84d87672009-12-10 09:41:52 +00007576 }
John McCall10eae182009-11-30 22:42:35 +00007577
7578 // Expand using declarations.
7579 if (isa<UsingDecl>(InstD)) {
7580 UsingDecl *UD = cast<UsingDecl>(InstD);
7581 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7582 E = UD->shadow_end(); I != E; ++I)
7583 R.addDecl(*I);
7584 continue;
7585 }
7586
7587 R.addDecl(InstD);
7588 }
7589
7590 R.resolveKind();
7591
Douglas Gregor9262f472010-04-27 18:19:34 +00007592 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007593 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007594 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007595 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007596 Old->getMemberLoc(),
7597 Old->getNamingClass()));
7598 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007599 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007600
Douglas Gregorda7be082010-04-27 16:10:10 +00007601 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007602 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007603
John McCall10eae182009-11-30 22:42:35 +00007604 TemplateArgumentListInfo TransArgs;
7605 if (Old->hasExplicitTemplateArgs()) {
7606 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7607 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007608 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7609 Old->getNumTemplateArgs(),
7610 TransArgs))
7611 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007612 }
John McCall38836f02010-01-15 08:34:02 +00007613
7614 // FIXME: to do this check properly, we will need to preserve the
7615 // first-qualifier-in-scope here, just in case we had a dependent
7616 // base (and therefore couldn't do the check) and a
7617 // nested-name-qualifier (and therefore could do the lookup).
7618 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007619
John McCallb268a282010-08-23 23:25:46 +00007620 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007621 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007622 Old->getOperatorLoc(),
7623 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00007624 QualifierLoc,
John McCall38836f02010-01-15 08:34:02 +00007625 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007626 R,
7627 (Old->hasExplicitTemplateArgs()
7628 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007629}
7630
7631template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007632ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007633TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00007634 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007635 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7636 if (SubExpr.isInvalid())
7637 return ExprError();
7638
7639 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007640 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007641
7642 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7643}
7644
7645template<typename Derived>
7646ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007647TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007648 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7649 if (Pattern.isInvalid())
7650 return ExprError();
7651
7652 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7653 return SemaRef.Owned(E);
7654
Douglas Gregorb8840002011-01-14 21:20:45 +00007655 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7656 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007657}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007658
7659template<typename Derived>
7660ExprResult
7661TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7662 // If E is not value-dependent, then nothing will change when we transform it.
7663 // Note: This is an instantiation-centric view.
7664 if (!E->isValueDependent())
7665 return SemaRef.Owned(E);
7666
7667 // Note: None of the implementations of TryExpandParameterPacks can ever
7668 // produce a diagnostic when given only a single unexpanded parameter pack,
7669 // so
7670 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7671 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007672 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007673 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007674 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +00007675 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007676 ShouldExpand, RetainExpansion,
7677 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007678 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007679
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007680 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007681 return SemaRef.Owned(E);
7682
7683 // We now know the length of the parameter pack, so build a new expression
7684 // that stores that length.
7685 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7686 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007687 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007688}
7689
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007690template<typename Derived>
7691ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007692TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7693 SubstNonTypeTemplateParmPackExpr *E) {
7694 // Default behavior is to do nothing with this transformation.
7695 return SemaRef.Owned(E);
7696}
7697
7698template<typename Derived>
7699ExprResult
John McCall7c454bb2011-07-15 05:09:51 +00007700TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
7701 SubstNonTypeTemplateParmExpr *E) {
7702 // Default behavior is to do nothing with this transformation.
7703 return SemaRef.Owned(E);
7704}
7705
7706template<typename Derived>
7707ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +00007708TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
7709 MaterializeTemporaryExpr *E) {
7710 return getDerived().TransformExpr(E->GetTemporaryExpr());
7711}
7712
7713template<typename Derived>
7714ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007715TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007716 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007717}
7718
Mike Stump11289f42009-09-09 15:08:12 +00007719template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007720ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007721TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007722 TypeSourceInfo *EncodedTypeInfo
7723 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7724 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007725 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007726
Douglas Gregora16548e2009-08-11 05:31:07 +00007727 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007728 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007729 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007730
7731 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007732 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007733 E->getRParenLoc());
7734}
Mike Stump11289f42009-09-09 15:08:12 +00007735
Douglas Gregora16548e2009-08-11 05:31:07 +00007736template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +00007737ExprResult TreeTransform<Derived>::
7738TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
7739 ExprResult result = getDerived().TransformExpr(E->getSubExpr());
7740 if (result.isInvalid()) return ExprError();
7741 Expr *subExpr = result.take();
7742
7743 if (!getDerived().AlwaysRebuild() &&
7744 subExpr == E->getSubExpr())
7745 return SemaRef.Owned(E);
7746
7747 return SemaRef.Owned(new(SemaRef.Context)
7748 ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy()));
7749}
7750
7751template<typename Derived>
7752ExprResult TreeTransform<Derived>::
7753TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
7754 TypeSourceInfo *TSInfo
7755 = getDerived().TransformType(E->getTypeInfoAsWritten());
7756 if (!TSInfo)
7757 return ExprError();
7758
7759 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
7760 if (Result.isInvalid())
7761 return ExprError();
7762
7763 if (!getDerived().AlwaysRebuild() &&
7764 TSInfo == E->getTypeInfoAsWritten() &&
7765 Result.get() == E->getSubExpr())
7766 return SemaRef.Owned(E);
7767
7768 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
7769 E->getBridgeKeywordLoc(), TSInfo,
7770 Result.get());
7771}
7772
7773template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007774ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007775TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007776 // Transform arguments.
7777 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007778 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007779 Args.reserve(E->getNumArgs());
7780 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7781 &ArgChanged))
7782 return ExprError();
7783
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007784 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7785 // Class message: transform the receiver type.
7786 TypeSourceInfo *ReceiverTypeInfo
7787 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7788 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007789 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007790
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007791 // If nothing changed, just retain the existing message send.
7792 if (!getDerived().AlwaysRebuild() &&
7793 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007794 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007795
7796 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007797 SmallVector<SourceLocation, 16> SelLocs;
7798 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007799 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7800 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007801 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007802 E->getMethodDecl(),
7803 E->getLeftLoc(),
7804 move_arg(Args),
7805 E->getRightLoc());
7806 }
7807
7808 // Instance message: transform the receiver
7809 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7810 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007811 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007812 = getDerived().TransformExpr(E->getInstanceReceiver());
7813 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007814 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007815
7816 // If nothing changed, just retain the existing message send.
7817 if (!getDerived().AlwaysRebuild() &&
7818 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007819 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007820
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007821 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007822 SmallVector<SourceLocation, 16> SelLocs;
7823 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +00007824 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007825 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00007826 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007827 E->getMethodDecl(),
7828 E->getLeftLoc(),
7829 move_arg(Args),
7830 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007831}
7832
Mike Stump11289f42009-09-09 15:08:12 +00007833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007834ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007835TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007836 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007837}
7838
Mike Stump11289f42009-09-09 15:08:12 +00007839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007840ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007841TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007842 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007843}
7844
Mike Stump11289f42009-09-09 15:08:12 +00007845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007846ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007847TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007848 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007849 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007850 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007851 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007852
7853 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007854
Douglas Gregord51d90d2010-04-26 20:11:03 +00007855 // If nothing changed, just retain the existing expression.
7856 if (!getDerived().AlwaysRebuild() &&
7857 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007858 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007859
John McCallb268a282010-08-23 23:25:46 +00007860 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007861 E->getLocation(),
7862 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007863}
7864
Mike Stump11289f42009-09-09 15:08:12 +00007865template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007866ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007867TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007868 // 'super' and types never change. Property never changes. Just
7869 // retain the existing expression.
7870 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007871 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007872
Douglas Gregor9faee212010-04-26 20:47:02 +00007873 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007874 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007875 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007876 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007877
Douglas Gregor9faee212010-04-26 20:47:02 +00007878 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007879
Douglas Gregor9faee212010-04-26 20:47:02 +00007880 // If nothing changed, just retain the existing expression.
7881 if (!getDerived().AlwaysRebuild() &&
7882 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007883 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007884
John McCallb7bd14f2010-12-02 01:19:52 +00007885 if (E->isExplicitProperty())
7886 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7887 E->getExplicitProperty(),
7888 E->getLocation());
7889
7890 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7891 E->getType(),
7892 E->getImplicitPropertyGetter(),
7893 E->getImplicitPropertySetter(),
7894 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007895}
7896
Mike Stump11289f42009-09-09 15:08:12 +00007897template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007898ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007899TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007900 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007901 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007902 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007903 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007904
Douglas Gregord51d90d2010-04-26 20:11:03 +00007905 // If nothing changed, just retain the existing expression.
7906 if (!getDerived().AlwaysRebuild() &&
7907 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007908 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007909
John McCallb268a282010-08-23 23:25:46 +00007910 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007911 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007912}
7913
Mike Stump11289f42009-09-09 15:08:12 +00007914template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007915ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007916TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007917 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007918 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007919 SubExprs.reserve(E->getNumSubExprs());
7920 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7921 SubExprs, &ArgumentChanged))
7922 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007923
Douglas Gregora16548e2009-08-11 05:31:07 +00007924 if (!getDerived().AlwaysRebuild() &&
7925 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007926 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007927
Douglas Gregora16548e2009-08-11 05:31:07 +00007928 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7929 move_arg(SubExprs),
7930 E->getRParenLoc());
7931}
7932
Mike Stump11289f42009-09-09 15:08:12 +00007933template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007934ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007935TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007936 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007937
John McCall490112f2011-02-04 18:33:18 +00007938 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7939 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7940
7941 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahanian4cc5df72011-05-05 17:18:12 +00007942 // We built a new blockScopeInfo in call to ActOnBlockStart
7943 // in above, CapturesCXXThis need be set here from the block
7944 // expression.
7945 blockScope->CapturesCXXThis = oldBlock->capturesCXXThis();
7946
Chris Lattner01cf8db2011-07-20 06:58:45 +00007947 SmallVector<ParmVarDecl*, 4> params;
7948 SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007949
7950 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007951 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7952 oldBlock->param_begin(),
7953 oldBlock->param_size(),
7954 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007955 return true;
John McCall490112f2011-02-04 18:33:18 +00007956
7957 const FunctionType *exprFunctionType = E->getFunctionType();
7958 QualType exprResultType = exprFunctionType->getResultType();
7959 if (!exprResultType.isNull()) {
7960 if (!exprResultType->isDependentType())
7961 blockScope->ReturnType = exprResultType;
7962 else if (exprResultType != getSema().Context.DependentTy)
7963 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007964 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007965
7966 // If the return type has not been determined yet, leave it as a dependent
7967 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007968 if (blockScope->ReturnType.isNull())
7969 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007970
7971 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007972 if (blockScope->ReturnType->isObjCObjectType()) {
7973 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007974 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007975 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007976 return ExprError();
7977 }
John McCall3882ace2011-01-05 12:14:39 +00007978
John McCall490112f2011-02-04 18:33:18 +00007979 QualType functionType = getDerived().RebuildFunctionProtoType(
7980 blockScope->ReturnType,
7981 paramTypes.data(),
7982 paramTypes.size(),
7983 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007984 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007985 exprFunctionType->getExtInfo());
7986 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007987
7988 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007989 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +00007990 blockScope->TheDecl->setParams(params);
Douglas Gregor476e3022011-01-19 21:32:01 +00007991
7992 // If the return type wasn't explicitly set, it will have been marked as a
7993 // dependent type (DependentTy); clear out the return type setting so
7994 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007995 if (blockScope->ReturnType == getSema().Context.DependentTy)
7996 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007997
John McCall3882ace2011-01-05 12:14:39 +00007998 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007999 StmtResult body = getDerived().TransformStmt(E->getBody());
8000 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00008001 return ExprError();
8002
John McCall490112f2011-02-04 18:33:18 +00008003#ifndef NDEBUG
8004 // In builds with assertions, make sure that we captured everything we
8005 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008006 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
8007 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
8008 e = oldBlock->capture_end(); i != e; ++i) {
8009 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00008010
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008011 // Ignore parameter packs.
8012 if (isa<ParmVarDecl>(oldCapture) &&
8013 cast<ParmVarDecl>(oldCapture)->isParameterPack())
8014 continue;
John McCall490112f2011-02-04 18:33:18 +00008015
Douglas Gregor4385d8b2011-05-20 15:32:55 +00008016 VarDecl *newCapture =
8017 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
8018 oldCapture));
8019 assert(blockScope->CaptureMap.count(newCapture));
8020 }
John McCall490112f2011-02-04 18:33:18 +00008021 }
8022#endif
8023
8024 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
8025 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00008026}
8027
Mike Stump11289f42009-09-09 15:08:12 +00008028template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008029ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008030TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008031 ValueDecl *ND
8032 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
8033 E->getDecl()));
8034 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00008035 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008036
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008037 if (!getDerived().AlwaysRebuild() &&
8038 ND == E->getDecl()) {
8039 // Mark it referenced in the new context regardless.
8040 // FIXME: this is a bit instantiation-specific.
8041 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
8042
John McCallc3007a22010-10-26 07:05:15 +00008043 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00008044 }
8045
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008046 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Douglas Gregorea972d32011-02-28 21:54:11 +00008047 return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008048 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00008049}
Mike Stump11289f42009-09-09 15:08:12 +00008050
Tanya Lattner55808c12011-06-04 00:47:47 +00008051template<typename Derived>
8052ExprResult
8053TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +00008054 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +00008055}
8056
Douglas Gregora16548e2009-08-11 05:31:07 +00008057//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008058// Type reconstruction
8059//===----------------------------------------------------------------------===//
8060
Mike Stump11289f42009-09-09 15:08:12 +00008061template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008062QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
8063 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008064 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008065 getDerived().getBaseEntity());
8066}
8067
Mike Stump11289f42009-09-09 15:08:12 +00008068template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00008069QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
8070 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00008071 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008072 getDerived().getBaseEntity());
8073}
8074
Mike Stump11289f42009-09-09 15:08:12 +00008075template<typename Derived>
8076QualType
John McCall70dd5f62009-10-30 00:06:24 +00008077TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
8078 bool WrittenAsLValue,
8079 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008080 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00008081 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008082}
8083
8084template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008085QualType
John McCall70dd5f62009-10-30 00:06:24 +00008086TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
8087 QualType ClassType,
8088 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00008089 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00008090 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008091}
8092
8093template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008094QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00008095TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
8096 ArrayType::ArraySizeModifier SizeMod,
8097 const llvm::APInt *Size,
8098 Expr *SizeExpr,
8099 unsigned IndexTypeQuals,
8100 SourceRange BracketsRange) {
8101 if (SizeExpr || !Size)
8102 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
8103 IndexTypeQuals, BracketsRange,
8104 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00008105
8106 QualType Types[] = {
8107 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
8108 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
8109 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00008110 };
8111 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
8112 QualType SizeType;
8113 for (unsigned I = 0; I != NumTypes; ++I)
8114 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
8115 SizeType = Types[I];
8116 break;
8117 }
Mike Stump11289f42009-09-09 15:08:12 +00008118
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008119 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
8120 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00008121 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008122 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00008123 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00008124}
Mike Stump11289f42009-09-09 15:08:12 +00008125
Douglas Gregord6ff3322009-08-04 16:50:30 +00008126template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008127QualType
8128TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008129 ArrayType::ArraySizeModifier SizeMod,
8130 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00008131 unsigned IndexTypeQuals,
8132 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008133 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008134 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008135}
8136
8137template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008138QualType
Mike Stump11289f42009-09-09 15:08:12 +00008139TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008140 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00008141 unsigned IndexTypeQuals,
8142 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008143 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00008144 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008145}
Mike Stump11289f42009-09-09 15:08:12 +00008146
Douglas Gregord6ff3322009-08-04 16:50:30 +00008147template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008148QualType
8149TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008150 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008151 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008152 unsigned IndexTypeQuals,
8153 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008154 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008155 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008156 IndexTypeQuals, BracketsRange);
8157}
8158
8159template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008160QualType
8161TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008162 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00008163 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008164 unsigned IndexTypeQuals,
8165 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00008166 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00008167 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008168 IndexTypeQuals, BracketsRange);
8169}
8170
8171template<typename Derived>
8172QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00008173 unsigned NumElements,
8174 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00008175 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00008176 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008177}
Mike Stump11289f42009-09-09 15:08:12 +00008178
Douglas Gregord6ff3322009-08-04 16:50:30 +00008179template<typename Derived>
8180QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
8181 unsigned NumElements,
8182 SourceLocation AttributeLoc) {
8183 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
8184 NumElements, true);
8185 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00008186 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
8187 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00008188 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008189}
Mike Stump11289f42009-09-09 15:08:12 +00008190
Douglas Gregord6ff3322009-08-04 16:50:30 +00008191template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008192QualType
8193TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00008194 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008195 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00008196 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008197}
Mike Stump11289f42009-09-09 15:08:12 +00008198
Douglas Gregord6ff3322009-08-04 16:50:30 +00008199template<typename Derived>
8200QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00008201 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008202 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00008203 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00008204 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008205 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00008206 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00008207 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00008208 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00008209 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00008210 getDerived().getBaseEntity(),
8211 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008212}
Mike Stump11289f42009-09-09 15:08:12 +00008213
Douglas Gregord6ff3322009-08-04 16:50:30 +00008214template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00008215QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
8216 return SemaRef.Context.getFunctionNoProtoType(T);
8217}
8218
8219template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00008220QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
8221 assert(D && "no decl found");
8222 if (D->isInvalidDecl()) return QualType();
8223
Douglas Gregorc298ffc2010-04-22 16:44:27 +00008224 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00008225 TypeDecl *Ty;
8226 if (isa<UsingDecl>(D)) {
8227 UsingDecl *Using = cast<UsingDecl>(D);
8228 assert(Using->isTypeName() &&
8229 "UnresolvedUsingTypenameDecl transformed to non-typename using");
8230
8231 // A valid resolved using typename decl points to exactly one type decl.
8232 assert(++Using->shadow_begin() == Using->shadow_end());
8233 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00008234
John McCallb96ec562009-12-04 22:46:56 +00008235 } else {
8236 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
8237 "UnresolvedUsingTypenameDecl transformed to non-using decl");
8238 Ty = cast<UnresolvedUsingTypenameDecl>(D);
8239 }
8240
8241 return SemaRef.Context.getTypeDeclType(Ty);
8242}
8243
8244template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008245QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
8246 SourceLocation Loc) {
8247 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008248}
8249
8250template<typename Derived>
8251QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
8252 return SemaRef.Context.getTypeOfType(Underlying);
8253}
8254
8255template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00008256QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
8257 SourceLocation Loc) {
8258 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008259}
8260
8261template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00008262QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
8263 UnaryTransformType::UTTKind UKind,
8264 SourceLocation Loc) {
8265 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
8266}
8267
8268template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00008269QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00008270 TemplateName Template,
8271 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +00008272 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +00008273 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00008274}
Mike Stump11289f42009-09-09 15:08:12 +00008275
Douglas Gregor1135c352009-08-06 05:28:30 +00008276template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008277TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008278TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008279 bool TemplateKW,
8280 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008281 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00008282 Template);
8283}
8284
8285template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00008286TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008287TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
8288 const IdentifierInfo &Name,
8289 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00008290 QualType ObjectType,
8291 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +00008292 UnqualifiedId TemplateName;
8293 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +00008294 Sema::TemplateTy Template;
8295 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008296 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008297 SS,
Douglas Gregor9db53502011-03-02 18:07:45 +00008298 TemplateName,
John McCallba7bf592010-08-24 05:47:05 +00008299 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008300 /*EnteringContext=*/false,
8301 Template);
John McCall31f82722010-11-12 08:19:04 +00008302 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00008303}
Mike Stump11289f42009-09-09 15:08:12 +00008304
Douglas Gregora16548e2009-08-11 05:31:07 +00008305template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00008306TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00008307TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008308 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00008309 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00008310 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +00008311 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +00008312 // FIXME: Bogus location information.
8313 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
8314 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00008315 Sema::TemplateTy Template;
8316 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor9db53502011-03-02 18:07:45 +00008317 /*FIXME:*/SourceLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00008318 SS,
8319 Name,
John McCallba7bf592010-08-24 05:47:05 +00008320 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00008321 /*EnteringContext=*/false,
8322 Template);
8323 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00008324}
Alexis Hunta8136cc2010-05-05 15:23:54 +00008325
Douglas Gregor71395fa2009-11-04 00:56:37 +00008326template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008327ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008328TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
8329 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00008330 Expr *OrigCallee,
8331 Expr *First,
8332 Expr *Second) {
8333 Expr *Callee = OrigCallee->IgnoreParenCasts();
8334 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00008335
Douglas Gregora16548e2009-08-11 05:31:07 +00008336 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00008337 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00008338 if (!First->getType()->isOverloadableType() &&
8339 !Second->getType()->isOverloadableType())
8340 return getSema().CreateBuiltinArraySubscriptExpr(First,
8341 Callee->getLocStart(),
8342 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00008343 } else if (Op == OO_Arrow) {
8344 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00008345 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
8346 } else if (Second == 0 || isPostIncDec) {
8347 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008348 // The argument is not of overloadable type, so try to create a
8349 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00008350 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008351 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00008352
John McCallb268a282010-08-23 23:25:46 +00008353 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008354 }
8355 } else {
John McCallb268a282010-08-23 23:25:46 +00008356 if (!First->getType()->isOverloadableType() &&
8357 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008358 // Neither of the arguments is an overloadable type, so try to
8359 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00008360 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008361 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00008362 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00008363 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008364 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008365
Douglas Gregora16548e2009-08-11 05:31:07 +00008366 return move(Result);
8367 }
8368 }
Mike Stump11289f42009-09-09 15:08:12 +00008369
8370 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00008371 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00008372 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00008373
John McCallb268a282010-08-23 23:25:46 +00008374 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00008375 assert(ULE->requiresADL());
8376
8377 // FIXME: Do we have to check
8378 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00008379 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00008380 } else {
John McCallb268a282010-08-23 23:25:46 +00008381 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00008382 }
Mike Stump11289f42009-09-09 15:08:12 +00008383
Douglas Gregora16548e2009-08-11 05:31:07 +00008384 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00008385 Expr *Args[2] = { First, Second };
8386 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00008387
Douglas Gregora16548e2009-08-11 05:31:07 +00008388 // Create the overloaded operator invocation for unary operators.
8389 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00008390 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00008391 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00008392 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00008393 }
Mike Stump11289f42009-09-09 15:08:12 +00008394
Douglas Gregore9d62932011-07-15 16:25:15 +00008395 if (Op == OO_Subscript) {
8396 SourceLocation LBrace;
8397 SourceLocation RBrace;
8398
8399 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
8400 DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo();
8401 LBrace = SourceLocation::getFromRawEncoding(
8402 NameLoc.CXXOperatorName.BeginOpNameLoc);
8403 RBrace = SourceLocation::getFromRawEncoding(
8404 NameLoc.CXXOperatorName.EndOpNameLoc);
8405 } else {
8406 LBrace = Callee->getLocStart();
8407 RBrace = OpLoc;
8408 }
8409
8410 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
8411 First, Second);
8412 }
Sebastian Redladba46e2009-10-29 20:17:01 +00008413
Douglas Gregora16548e2009-08-11 05:31:07 +00008414 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00008415 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00008416 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00008417 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
8418 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008419 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008420
Mike Stump11289f42009-09-09 15:08:12 +00008421 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00008422}
Mike Stump11289f42009-09-09 15:08:12 +00008423
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008424template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008425ExprResult
John McCallb268a282010-08-23 23:25:46 +00008426TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008427 SourceLocation OperatorLoc,
8428 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00008429 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008430 TypeSourceInfo *ScopeType,
8431 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008432 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008433 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00008434 QualType BaseType = Base->getType();
8435 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008436 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00008437 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00008438 !BaseType->getAs<PointerType>()->getPointeeType()
8439 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008440 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00008441 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008442 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00008443 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00008444 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008445 /*FIXME?*/true);
8446 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008447
Douglas Gregor678f90d2010-02-25 01:56:36 +00008448 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008449 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
8450 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
8451 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
8452 NameInfo.setNamedTypeInfo(DestroyedType);
8453
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008454 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008455
John McCallb268a282010-08-23 23:25:46 +00008456 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008457 OperatorLoc, isArrow,
8458 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008459 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00008460 /*TemplateArgs*/ 0);
8461}
8462
Douglas Gregord6ff3322009-08-04 16:50:30 +00008463} // end namespace clang
8464
8465#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H