blob: 4869ce6db68a23568c4c17af738b925b39e42d00 [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"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000024#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000025#include "clang/AST/ExprCXX.h"
26#include "clang/AST/ExprObjC.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000027#include "clang/AST/Stmt.h"
28#include "clang/AST/StmtCXX.h"
29#include "clang/AST/StmtObjC.h"
John McCall8b0666c2010-08-20 18:27:03 +000030#include "clang/Sema/Ownership.h"
31#include "clang/Sema/Designator.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000032#include "clang/Lex/Preprocessor.h"
John McCall550e0c22009-10-21 00:40:46 +000033#include "llvm/Support/ErrorHandling.h"
Douglas Gregor451d1b12010-12-02 00:05:49 +000034#include "TypeLocBuilder.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000035#include <algorithm>
36
37namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000038using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000039
Douglas Gregord6ff3322009-08-04 16:50:30 +000040/// \brief A semantic tree transformation that allows one to transform one
41/// abstract syntax tree into another.
42///
Mike Stump11289f42009-09-09 15:08:12 +000043/// A new tree transformation is defined by creating a new subclass \c X of
44/// \c TreeTransform<X> and then overriding certain operations to provide
45/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000046/// instantiation is implemented as a tree transformation where the
47/// transformation of TemplateTypeParmType nodes involves substituting the
48/// template arguments for their corresponding template parameters; a similar
49/// transformation is performed for non-type template parameters and
50/// template template parameters.
51///
52/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000053/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000054/// override any of the transformation or rebuild operators by providing an
55/// operation with the same signature as the default implementation. The
56/// overridding function should not be virtual.
57///
58/// Semantic tree transformations are split into two stages, either of which
59/// can be replaced by a subclass. The "transform" step transforms an AST node
60/// or the parts of an AST node using the various transformation functions,
61/// then passes the pieces on to the "rebuild" step, which constructs a new AST
62/// node of the appropriate kind from the pieces. The default transformation
63/// routines recursively transform the operands to composite AST nodes (e.g.,
64/// the pointee type of a PointerType node) and, if any of those operand nodes
65/// were changed by the transformation, invokes the rebuild operation to create
66/// a new AST node.
67///
Mike Stump11289f42009-09-09 15:08:12 +000068/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000069/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000070/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(),
71/// TransformTemplateName(), or TransformTemplateArgument() with entirely
72/// new implementations.
73///
74/// For more fine-grained transformations, subclasses can replace any of the
75/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000076/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000077/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000078/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000079/// parameters. Additionally, subclasses can override the \c RebuildXXX
80/// functions to control how AST nodes are rebuilt when their operands change.
81/// By default, \c TreeTransform will invoke semantic analysis to rebuild
82/// AST nodes. However, certain other tree transformations (e.g, cloning) may
83/// be able to use more efficient rebuild steps.
84///
85/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000086/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000087/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
88/// operands have not changed (\c AlwaysRebuild()), and customize the
89/// default locations and entity names used for type-checking
90/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000091template<typename Derived>
92class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000093 /// \brief Private RAII object that helps us forget and then re-remember
94 /// the template argument corresponding to a partially-substituted parameter
95 /// pack.
96 class ForgetPartiallySubstitutedPackRAII {
97 Derived &Self;
98 TemplateArgument Old;
99
100 public:
101 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
102 Old = Self.ForgetPartiallySubstitutedPack();
103 }
104
105 ~ForgetPartiallySubstitutedPackRAII() {
106 Self.RememberPartiallySubstitutedPack(Old);
107 }
108 };
109
Douglas Gregord6ff3322009-08-04 16:50:30 +0000110protected:
111 Sema &SemaRef;
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000112
Mike Stump11289f42009-09-09 15:08:12 +0000113public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000114 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000115 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000116
Douglas Gregord6ff3322009-08-04 16:50:30 +0000117 /// \brief Retrieves a reference to the derived class.
118 Derived &getDerived() { return static_cast<Derived&>(*this); }
119
120 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000121 const Derived &getDerived() const {
122 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000123 }
124
John McCalldadc5752010-08-24 06:29:42 +0000125 static inline ExprResult Owned(Expr *E) { return E; }
126 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000127
Douglas Gregord6ff3322009-08-04 16:50:30 +0000128 /// \brief Retrieves a reference to the semantic analysis object used for
129 /// this tree transform.
130 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000131
Douglas Gregord6ff3322009-08-04 16:50:30 +0000132 /// \brief Whether the transformation should always rebuild AST nodes, even
133 /// if none of the children have changed.
134 ///
135 /// Subclasses may override this function to specify when the transformation
136 /// should rebuild all AST nodes.
137 bool AlwaysRebuild() { return false; }
Mike Stump11289f42009-09-09 15:08:12 +0000138
Douglas Gregord6ff3322009-08-04 16:50:30 +0000139 /// \brief Returns the location of the entity being transformed, if that
140 /// information was not available elsewhere in the AST.
141 ///
Mike Stump11289f42009-09-09 15:08:12 +0000142 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000143 /// provide an alternative implementation that provides better location
144 /// information.
145 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000146
Douglas Gregord6ff3322009-08-04 16:50:30 +0000147 /// \brief Returns the name of the entity being transformed, if that
148 /// information was not available elsewhere in the AST.
149 ///
150 /// By default, returns an empty name. Subclasses can provide an alternative
151 /// implementation with a more precise name.
152 DeclarationName getBaseEntity() { return DeclarationName(); }
153
Douglas Gregora16548e2009-08-11 05:31:07 +0000154 /// \brief Sets the "base" location and entity when that
155 /// information is known based on another transformation.
156 ///
157 /// By default, the source location and entity are ignored. Subclasses can
158 /// override this function to provide a customized implementation.
159 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000160
Douglas Gregora16548e2009-08-11 05:31:07 +0000161 /// \brief RAII object that temporarily sets the base location and entity
162 /// used for reporting diagnostics in types.
163 class TemporaryBase {
164 TreeTransform &Self;
165 SourceLocation OldLocation;
166 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000167
Douglas Gregora16548e2009-08-11 05:31:07 +0000168 public:
169 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000170 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000171 OldLocation = Self.getDerived().getBaseLocation();
172 OldEntity = Self.getDerived().getBaseEntity();
Douglas Gregora518d5b2011-01-25 17:51:48 +0000173
174 if (Location.isValid())
175 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000176 }
Mike Stump11289f42009-09-09 15:08:12 +0000177
Douglas Gregora16548e2009-08-11 05:31:07 +0000178 ~TemporaryBase() {
179 Self.getDerived().setBase(OldLocation, OldEntity);
180 }
181 };
Mike Stump11289f42009-09-09 15:08:12 +0000182
183 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000184 /// transformed.
185 ///
186 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000187 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000188 /// not change. For example, template instantiation need not traverse
189 /// non-dependent types.
190 bool AlreadyTransformed(QualType T) {
191 return T.isNull();
192 }
193
Douglas Gregord196a582009-12-14 19:27:10 +0000194 /// \brief Determine whether the given call argument should be dropped, e.g.,
195 /// because it is a default argument.
196 ///
197 /// Subclasses can provide an alternative implementation of this routine to
198 /// determine which kinds of call arguments get dropped. By default,
199 /// CXXDefaultArgument nodes are dropped (prior to transformation).
200 bool DropCallArgument(Expr *E) {
201 return E->isDefaultArgument();
202 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000203
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000204 /// \brief Determine whether we should expand a pack expansion with the
205 /// given set of parameter packs into separate arguments by repeatedly
206 /// transforming the pattern.
207 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000208 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000209 /// Subclasses can override this routine to provide different behavior.
210 ///
211 /// \param EllipsisLoc The location of the ellipsis that identifies the
212 /// pack expansion.
213 ///
214 /// \param PatternRange The source range that covers the entire pattern of
215 /// the pack expansion.
216 ///
217 /// \param Unexpanded The set of unexpanded parameter packs within the
218 /// pattern.
219 ///
220 /// \param NumUnexpanded The number of unexpanded parameter packs in
221 /// \p Unexpanded.
222 ///
223 /// \param ShouldExpand Will be set to \c true if the transformer should
224 /// expand the corresponding pack expansions into separate arguments. When
225 /// set, \c NumExpansions must also be set.
226 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000227 /// \param RetainExpansion Whether the caller should add an unexpanded
228 /// pack expansion after all of the expanded arguments. This is used
229 /// when extending explicitly-specified template argument packs per
230 /// C++0x [temp.arg.explicit]p9.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000233 /// the expanded form of the corresponding pack expansion. This is both an
234 /// input and an output parameter, which can be set by the caller if the
235 /// number of expansions is known a priori (e.g., due to a prior substitution)
236 /// and will be set by the callee when the number of expansions is known.
237 /// The callee must set this value when \c ShouldExpand is \c true; it may
238 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000239 ///
240 /// \returns true if an error occurred (e.g., because the parameter packs
241 /// are to be instantiated with arguments of different lengths), false
242 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
243 /// must be set.
244 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
245 SourceRange PatternRange,
246 const UnexpandedParameterPack *Unexpanded,
247 unsigned NumUnexpanded,
248 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000249 bool &RetainExpansion,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000250 llvm::Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000251 ShouldExpand = false;
252 return false;
253 }
254
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000255 /// \brief "Forget" about the partially-substituted pack template argument,
256 /// when performing an instantiation that must preserve the parameter pack
257 /// use.
258 ///
259 /// This routine is meant to be overridden by the template instantiator.
260 TemplateArgument ForgetPartiallySubstitutedPack() {
261 return TemplateArgument();
262 }
263
264 /// \brief "Remember" the partially-substituted pack template argument
265 /// after performing an instantiation that must preserve the parameter pack
266 /// use.
267 ///
268 /// This routine is meant to be overridden by the template instantiator.
269 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
270
Douglas Gregorf3010112011-01-07 16:43:16 +0000271 /// \brief Note to the derived class when a function parameter pack is
272 /// being expanded.
273 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
274
Douglas Gregord6ff3322009-08-04 16:50:30 +0000275 /// \brief Transforms the given type into another type.
276 ///
John McCall550e0c22009-10-21 00:40:46 +0000277 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000278 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000279 /// function. This is expensive, but we don't mind, because
280 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000281 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000282 ///
283 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000284 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000285
John McCall550e0c22009-10-21 00:40:46 +0000286 /// \brief Transforms the given type-with-location into a new
287 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000288 ///
John McCall550e0c22009-10-21 00:40:46 +0000289 /// By default, this routine transforms a type by delegating to the
290 /// appropriate TransformXXXType to build a new type. Subclasses
291 /// may override this function (to take over all type
292 /// transformations) or some set of the TransformXXXType functions
293 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000294 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000295
296 /// \brief Transform the given type-with-location into a new
297 /// type, collecting location information in the given builder
298 /// as necessary.
299 ///
John McCall31f82722010-11-12 08:19:04 +0000300 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000301
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000302 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000303 ///
Mike Stump11289f42009-09-09 15:08:12 +0000304 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000305 /// appropriate TransformXXXStmt function to transform a specific kind of
306 /// statement or the TransformExpr() function to transform an expression.
307 /// Subclasses may override this function to transform statements using some
308 /// other mechanism.
309 ///
310 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000311 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000312
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000313 /// \brief Transform the given expression.
314 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000315 /// By default, this routine transforms an expression by delegating to the
316 /// appropriate TransformXXXExpr function to build a new expression.
317 /// Subclasses may override this function to transform expressions using some
318 /// other mechanism.
319 ///
320 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000321 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000322
Douglas Gregora3efea12011-01-03 19:04:46 +0000323 /// \brief Transform the given list of expressions.
324 ///
325 /// This routine transforms a list of expressions by invoking
326 /// \c TransformExpr() for each subexpression. However, it also provides
327 /// support for variadic templates by expanding any pack expansions (if the
328 /// derived class permits such expansion) along the way. When pack expansions
329 /// are present, the number of outputs may not equal the number of inputs.
330 ///
331 /// \param Inputs The set of expressions to be transformed.
332 ///
333 /// \param NumInputs The number of expressions in \c Inputs.
334 ///
335 /// \param IsCall If \c true, then this transform is being performed on
336 /// function-call arguments, and any arguments that should be dropped, will
337 /// be.
338 ///
339 /// \param Outputs The transformed input expressions will be added to this
340 /// vector.
341 ///
342 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
343 /// due to transformation.
344 ///
345 /// \returns true if an error occurred, false otherwise.
346 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
347 llvm::SmallVectorImpl<Expr *> &Outputs,
348 bool *ArgChanged = 0);
349
Douglas Gregord6ff3322009-08-04 16:50:30 +0000350 /// \brief Transform the given declaration, which is referenced from a type
351 /// or expression.
352 ///
Douglas Gregor1135c352009-08-06 05:28:30 +0000353 /// By default, acts as the identity function on declarations. Subclasses
354 /// may override this function to provide alternate behavior.
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000355 Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; }
Douglas Gregorebe10102009-08-20 07:17:43 +0000356
357 /// \brief Transform the definition of the given declaration.
358 ///
Mike Stump11289f42009-09-09 15:08:12 +0000359 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000360 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000361 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
362 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000363 }
Mike Stump11289f42009-09-09 15:08:12 +0000364
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000365 /// \brief Transform the given declaration, which was the first part of a
366 /// nested-name-specifier in a member access expression.
367 ///
Alexis Hunta8136cc2010-05-05 15:23:54 +0000368 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000369 /// identifier in a nested-name-specifier of a member access expression, e.g.,
370 /// the \c T in \c x->T::member
371 ///
372 /// By default, invokes TransformDecl() to transform the declaration.
373 /// Subclasses may override this function to provide alternate behavior.
Alexis Hunta8136cc2010-05-05 15:23:54 +0000374 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
375 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000376 }
Alexis Hunta8136cc2010-05-05 15:23:54 +0000377
Douglas Gregord6ff3322009-08-04 16:50:30 +0000378 /// \brief Transform the given nested-name-specifier.
379 ///
Mike Stump11289f42009-09-09 15:08:12 +0000380 /// By default, transforms all of the types and declarations within the
Douglas Gregor1135c352009-08-06 05:28:30 +0000381 /// nested-name-specifier. Subclasses may override this function to provide
382 /// alternate behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000383 NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000384 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000385 QualType ObjectType = QualType(),
386 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000387
Douglas Gregor14454802011-02-25 02:25:35 +0000388 /// \brief Transform the given nested-name-specifier with source-location
389 /// information.
390 ///
391 /// By default, transforms all of the types and declarations within the
392 /// nested-name-specifier. Subclasses may override this function to provide
393 /// alternate behavior.
394 NestedNameSpecifierLoc TransformNestedNameSpecifierLoc(
395 NestedNameSpecifierLoc NNS,
396 QualType ObjectType = QualType(),
397 NamedDecl *FirstQualifierInScope = 0);
398
Douglas Gregorf816bd72009-09-03 22:13:48 +0000399 /// \brief Transform the given declaration name.
400 ///
401 /// By default, transforms the types of conversion function, constructor,
402 /// and destructor names and then (if needed) rebuilds the declaration name.
403 /// Identifiers and selectors are returned unmodified. Sublcasses may
404 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000405 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000406 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000407
Douglas Gregord6ff3322009-08-04 16:50:30 +0000408 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000409 ///
Douglas Gregor71dc5092009-08-06 06:41:21 +0000410 /// By default, transforms the template name by transforming the declarations
Mike Stump11289f42009-09-09 15:08:12 +0000411 /// and nested-name-specifiers that occur within the template name.
Douglas Gregor71dc5092009-08-06 06:41:21 +0000412 /// Subclasses may override this function to provide alternate behavior.
Douglas Gregor308047d2009-09-09 00:23:06 +0000413 TemplateName TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +0000414 QualType ObjectType = QualType(),
415 NamedDecl *FirstQualifierInScope = 0);
Mike Stump11289f42009-09-09 15:08:12 +0000416
Douglas Gregord6ff3322009-08-04 16:50:30 +0000417 /// \brief Transform the given template argument.
418 ///
Mike Stump11289f42009-09-09 15:08:12 +0000419 /// By default, this operation transforms the type, expression, or
420 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000421 /// new template argument from the transformed result. Subclasses may
422 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000423 ///
424 /// Returns true if there was an error.
425 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
426 TemplateArgumentLoc &Output);
427
Douglas Gregor62e06f22010-12-20 17:31:10 +0000428 /// \brief Transform the given set of template arguments.
429 ///
430 /// By default, this operation transforms all of the template arguments
431 /// in the input set using \c TransformTemplateArgument(), and appends
432 /// the transformed arguments to the output list.
433 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000434 /// Note that this overload of \c TransformTemplateArguments() is merely
435 /// a convenience function. Subclasses that wish to override this behavior
436 /// should override the iterator-based member template version.
437 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000438 /// \param Inputs The set of template arguments to be transformed.
439 ///
440 /// \param NumInputs The number of template arguments in \p Inputs.
441 ///
442 /// \param Outputs The set of transformed template arguments output by this
443 /// routine.
444 ///
445 /// Returns true if an error occurred.
446 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
447 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000448 TemplateArgumentListInfo &Outputs) {
449 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
450 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000451
452 /// \brief Transform the given set of template arguments.
453 ///
454 /// By default, this operation transforms all of the template arguments
455 /// in the input set using \c TransformTemplateArgument(), and appends
456 /// the transformed arguments to the output list.
457 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000458 /// \param First An iterator to the first template argument.
459 ///
460 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000461 ///
462 /// \param Outputs The set of transformed template arguments output by this
463 /// routine.
464 ///
465 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000466 template<typename InputIterator>
467 bool TransformTemplateArguments(InputIterator First,
468 InputIterator Last,
469 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000470
John McCall0ad16662009-10-29 08:12:44 +0000471 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
472 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
473 TemplateArgumentLoc &ArgLoc);
474
John McCallbcd03502009-12-07 02:54:59 +0000475 /// \brief Fakes up a TypeSourceInfo for a type.
476 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
477 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000478 getDerived().getBaseLocation());
479 }
Mike Stump11289f42009-09-09 15:08:12 +0000480
John McCall550e0c22009-10-21 00:40:46 +0000481#define ABSTRACT_TYPELOC(CLASS, PARENT)
482#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000483 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000484#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000485
John McCall31f82722010-11-12 08:19:04 +0000486 QualType
487 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
488 TemplateSpecializationTypeLoc TL,
489 TemplateName Template);
490
491 QualType
492 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
493 DependentTemplateSpecializationTypeLoc TL,
494 NestedNameSpecifier *Prefix);
495
John McCall58f10c32010-03-11 09:03:00 +0000496 /// \brief Transforms the parameters of a function type into the
497 /// given vectors.
498 ///
499 /// The result vectors should be kept in sync; null entries in the
500 /// variables vector are acceptable.
501 ///
502 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000503 bool TransformFunctionTypeParams(SourceLocation Loc,
504 ParmVarDecl **Params, unsigned NumParams,
505 const QualType *ParamTypes,
John McCall58f10c32010-03-11 09:03:00 +0000506 llvm::SmallVectorImpl<QualType> &PTypes,
Douglas Gregordd472162011-01-07 00:20:55 +0000507 llvm::SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000508
509 /// \brief Transforms a single function-type parameter. Return null
510 /// on error.
Douglas Gregor715e4612011-01-14 22:40:04 +0000511 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
512 llvm::Optional<unsigned> NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +0000513
John McCall31f82722010-11-12 08:19:04 +0000514 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000515
John McCalldadc5752010-08-24 06:29:42 +0000516 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
517 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000518
Douglas Gregorebe10102009-08-20 07:17:43 +0000519#define STMT(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000520 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000521#define EXPR(Node, Parent) \
John McCalldadc5752010-08-24 06:29:42 +0000522 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000523#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000524#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000525
Douglas Gregord6ff3322009-08-04 16:50:30 +0000526 /// \brief Build a new pointer type given its pointee type.
527 ///
528 /// By default, performs semantic analysis when building the pointer type.
529 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000530 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000531
532 /// \brief Build a new block pointer type given its pointee type.
533 ///
Mike Stump11289f42009-09-09 15:08:12 +0000534 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000535 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000536 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000537
John McCall70dd5f62009-10-30 00:06:24 +0000538 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000539 ///
John McCall70dd5f62009-10-30 00:06:24 +0000540 /// By default, performs semantic analysis when building the
541 /// reference type. Subclasses may override this routine to provide
542 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000543 ///
John McCall70dd5f62009-10-30 00:06:24 +0000544 /// \param LValue whether the type was written with an lvalue sigil
545 /// or an rvalue sigil.
546 QualType RebuildReferenceType(QualType ReferentType,
547 bool LValue,
548 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000549
Douglas Gregord6ff3322009-08-04 16:50:30 +0000550 /// \brief Build a new member pointer type given the pointee type and the
551 /// class type it refers into.
552 ///
553 /// By default, performs semantic analysis when building the member pointer
554 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000555 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
556 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000557
Douglas Gregord6ff3322009-08-04 16:50:30 +0000558 /// \brief Build a new array type given the element type, size
559 /// modifier, size of the array (if known), size expression, and index type
560 /// qualifiers.
561 ///
562 /// By default, performs semantic analysis when building the array type.
563 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000564 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000565 QualType RebuildArrayType(QualType ElementType,
566 ArrayType::ArraySizeModifier SizeMod,
567 const llvm::APInt *Size,
568 Expr *SizeExpr,
569 unsigned IndexTypeQuals,
570 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000571
Douglas Gregord6ff3322009-08-04 16:50:30 +0000572 /// \brief Build a new constant array type given the element type, size
573 /// modifier, (known) size of the array, and index type qualifiers.
574 ///
575 /// By default, performs semantic analysis when building the array type.
576 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000577 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000578 ArrayType::ArraySizeModifier SizeMod,
579 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000580 unsigned IndexTypeQuals,
581 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000582
Douglas Gregord6ff3322009-08-04 16:50:30 +0000583 /// \brief Build a new incomplete array type given the element type, size
584 /// modifier, and index type qualifiers.
585 ///
586 /// By default, performs semantic analysis when building the array type.
587 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000588 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000589 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000590 unsigned IndexTypeQuals,
591 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000592
Mike Stump11289f42009-09-09 15:08:12 +0000593 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000594 /// size modifier, size expression, 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 RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000599 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000600 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000601 unsigned IndexTypeQuals,
602 SourceRange BracketsRange);
603
Mike Stump11289f42009-09-09 15:08:12 +0000604 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000605 /// size modifier, size expression, 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 RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000610 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000611 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000612 unsigned IndexTypeQuals,
613 SourceRange BracketsRange);
614
615 /// \brief Build a new vector type given the element type and
616 /// number of elements.
617 ///
618 /// By default, performs semantic analysis when building the vector type.
619 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000620 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000621 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000622
Douglas Gregord6ff3322009-08-04 16:50:30 +0000623 /// \brief Build a new extended vector type given the element type and
624 /// number of elements.
625 ///
626 /// By default, performs semantic analysis when building the vector type.
627 /// Subclasses may override this routine to provide different behavior.
628 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
629 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000630
631 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000632 /// given the element type and number of elements.
633 ///
634 /// By default, performs semantic analysis when building the vector type.
635 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000636 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000637 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000638 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000639
Douglas Gregord6ff3322009-08-04 16:50:30 +0000640 /// \brief Build a new function type.
641 ///
642 /// By default, performs semantic analysis when building the function type.
643 /// Subclasses may override this routine to provide different behavior.
644 QualType RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +0000645 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000646 unsigned NumParamTypes,
Eli Friedmand8725a92010-08-05 02:54:05 +0000647 bool Variadic, unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +0000648 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +0000649 const FunctionType::ExtInfo &Info);
Mike Stump11289f42009-09-09 15:08:12 +0000650
John McCall550e0c22009-10-21 00:40:46 +0000651 /// \brief Build a new unprototyped function type.
652 QualType RebuildFunctionNoProtoType(QualType ResultType);
653
John McCallb96ec562009-12-04 22:46:56 +0000654 /// \brief Rebuild an unresolved typename type, given the decl that
655 /// the UnresolvedUsingTypenameDecl was transformed to.
656 QualType RebuildUnresolvedUsingType(Decl *D);
657
Douglas Gregord6ff3322009-08-04 16:50:30 +0000658 /// \brief Build a new typedef type.
659 QualType RebuildTypedefType(TypedefDecl *Typedef) {
660 return SemaRef.Context.getTypeDeclType(Typedef);
661 }
662
663 /// \brief Build a new class/struct/union type.
664 QualType RebuildRecordType(RecordDecl *Record) {
665 return SemaRef.Context.getTypeDeclType(Record);
666 }
667
668 /// \brief Build a new Enum type.
669 QualType RebuildEnumType(EnumDecl *Enum) {
670 return SemaRef.Context.getTypeDeclType(Enum);
671 }
John McCallfcc33b02009-09-05 00:15:47 +0000672
Mike Stump11289f42009-09-09 15:08:12 +0000673 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 ///
675 /// By default, performs semantic analysis when building the typeof type.
676 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000677 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000678
Mike Stump11289f42009-09-09 15:08:12 +0000679 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000680 ///
681 /// By default, builds a new TypeOfType with the given underlying type.
682 QualType RebuildTypeOfType(QualType Underlying);
683
Mike Stump11289f42009-09-09 15:08:12 +0000684 /// \brief Build a new C++0x decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 ///
686 /// By default, performs semantic analysis when building the decltype type.
687 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000688 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000689
Richard Smith30482bc2011-02-20 03:19:35 +0000690 /// \brief Build a new C++0x auto type.
691 ///
692 /// By default, builds a new AutoType with the given deduced type.
693 QualType RebuildAutoType(QualType Deduced) {
694 return SemaRef.Context.getAutoType(Deduced);
695 }
696
Douglas Gregord6ff3322009-08-04 16:50:30 +0000697 /// \brief Build a new template specialization type.
698 ///
699 /// By default, performs semantic analysis when building the template
700 /// specialization type. Subclasses may override this routine to provide
701 /// different behavior.
702 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000703 SourceLocation TemplateLoc,
John McCall6b51f282009-11-23 01:53:49 +0000704 const TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000705
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000706 /// \brief Build a new parenthesized type.
707 ///
708 /// By default, builds a new ParenType type from the inner type.
709 /// Subclasses may override this routine to provide different behavior.
710 QualType RebuildParenType(QualType InnerType) {
711 return SemaRef.Context.getParenType(InnerType);
712 }
713
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 /// \brief Build a new qualified name type.
715 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000716 /// By default, builds a new ElaboratedType type from the keyword,
717 /// the nested-name-specifier and the named type.
718 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000719 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
720 ElaboratedTypeKeyword Keyword,
Abramo Bagnara6150c882010-05-11 21:36:43 +0000721 NestedNameSpecifier *NNS, QualType Named) {
722 return SemaRef.Context.getElaboratedType(Keyword, NNS, Named);
Mike Stump11289f42009-09-09 15:08:12 +0000723 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724
725 /// \brief Build a new typename type that refers to a template-id.
726 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000727 /// By default, builds a new DependentNameType type from the
728 /// nested-name-specifier and the given type. Subclasses may override
729 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000730 QualType RebuildDependentTemplateSpecializationType(
731 ElaboratedTypeKeyword Keyword,
Douglas Gregora5614c52010-09-08 23:56:00 +0000732 NestedNameSpecifier *Qualifier,
733 SourceRange QualifierRange,
John McCallc392f372010-06-11 00:33:02 +0000734 const IdentifierInfo *Name,
735 SourceLocation NameLoc,
736 const TemplateArgumentListInfo &Args) {
737 // Rebuild the template name.
738 // TODO: avoid TemplateName abstraction
739 TemplateName InstName =
Douglas Gregora5614c52010-09-08 23:56:00 +0000740 getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name,
John McCall31f82722010-11-12 08:19:04 +0000741 QualType(), 0);
John McCallc392f372010-06-11 00:33:02 +0000742
Douglas Gregor7ba0c3f2010-06-18 22:12:56 +0000743 if (InstName.isNull())
744 return QualType();
745
John McCallc392f372010-06-11 00:33:02 +0000746 // If it's still dependent, make a dependent specialization.
747 if (InstName.getAsDependentTemplateName())
748 return SemaRef.Context.getDependentTemplateSpecializationType(
Douglas Gregora5614c52010-09-08 23:56:00 +0000749 Keyword, Qualifier, Name, Args);
John McCallc392f372010-06-11 00:33:02 +0000750
751 // Otherwise, make an elaborated type wrapping a non-dependent
752 // specialization.
753 QualType T =
754 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
755 if (T.isNull()) return QualType();
Abramo Bagnara6150c882010-05-11 21:36:43 +0000756
Abramo Bagnaraf9985b42010-08-10 13:46:45 +0000757 // NOTE: NNS is already recorded in template specialization type T.
758 return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T);
Mike Stump11289f42009-09-09 15:08:12 +0000759 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000760
761 /// \brief Build a new typename type that refers to an identifier.
762 ///
763 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000764 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000765 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000766 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Douglas Gregor02085352010-03-31 20:19:30 +0000767 NestedNameSpecifier *NNS,
768 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000769 SourceLocation KeywordLoc,
770 SourceRange NNSRange,
771 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000772 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +0000773 SS.MakeTrivial(SemaRef.Context, NNS, NNSRange);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000774
Douglas Gregore677daf2010-03-31 22:19:08 +0000775 if (NNS->isDependent()) {
776 // If the name is still dependent, just build a new dependent name type.
777 if (!SemaRef.computeDeclContext(SS))
778 return SemaRef.Context.getDependentNameType(Keyword, NNS, Id);
779 }
780
Abramo Bagnara6150c882010-05-11 21:36:43 +0000781 if (Keyword == ETK_None || Keyword == ETK_Typename)
Abramo Bagnarad7548482010-05-19 21:37:53 +0000782 return SemaRef.CheckTypenameType(Keyword, NNS, *Id,
783 KeywordLoc, NNSRange, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000784
785 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
786
Abramo Bagnarad7548482010-05-19 21:37:53 +0000787 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000788 // into a non-dependent elaborated-type-specifier. Find the tag we're
789 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000790 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000791 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
792 if (!DC)
793 return QualType();
794
John McCallbf8c5192010-05-27 06:40:31 +0000795 if (SemaRef.RequireCompleteDeclContext(SS, DC))
796 return QualType();
797
Douglas Gregore677daf2010-03-31 22:19:08 +0000798 TagDecl *Tag = 0;
799 SemaRef.LookupQualifiedName(Result, DC);
800 switch (Result.getResultKind()) {
801 case LookupResult::NotFound:
802 case LookupResult::NotFoundInCurrentInstantiation:
803 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000804
Douglas Gregore677daf2010-03-31 22:19:08 +0000805 case LookupResult::Found:
806 Tag = Result.getAsSingle<TagDecl>();
807 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +0000808
Douglas Gregore677daf2010-03-31 22:19:08 +0000809 case LookupResult::FoundOverloaded:
810 case LookupResult::FoundUnresolvedValue:
811 llvm_unreachable("Tag lookup cannot find non-tags");
812 return QualType();
Alexis Hunta8136cc2010-05-05 15:23:54 +0000813
Douglas Gregore677daf2010-03-31 22:19:08 +0000814 case LookupResult::Ambiguous:
815 // Let the LookupResult structure handle ambiguities.
816 return QualType();
817 }
818
819 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000820 // Check where the name exists but isn't a tag type and use that to emit
821 // better diagnostics.
822 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
823 SemaRef.LookupQualifiedName(Result, DC);
824 switch (Result.getResultKind()) {
825 case LookupResult::Found:
826 case LookupResult::FoundOverloaded:
827 case LookupResult::FoundUnresolvedValue: {
828 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
829 unsigned Kind = 0;
830 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
831 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 2;
832 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
833 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
834 break;
835 }
836 default:
837 // FIXME: Would be nice to highlight just the source range.
838 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
839 << Kind << Id << DC;
840 break;
841 }
Douglas Gregore677daf2010-03-31 22:19:08 +0000842 return QualType();
843 }
Abramo Bagnara6150c882010-05-11 21:36:43 +0000844
Abramo Bagnarad7548482010-05-19 21:37:53 +0000845 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) {
846 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +0000847 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
848 return QualType();
849 }
850
851 // Build the elaborated-type-specifier type.
852 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000853 return SemaRef.Context.getElaboratedType(Keyword, NNS, T);
Douglas Gregor1135c352009-08-06 05:28:30 +0000854 }
Mike Stump11289f42009-09-09 15:08:12 +0000855
Douglas Gregor822d0302011-01-12 17:07:58 +0000856 /// \brief Build a new pack expansion type.
857 ///
858 /// By default, builds a new PackExpansionType type from the given pattern.
859 /// Subclasses may override this routine to provide different behavior.
860 QualType RebuildPackExpansionType(QualType Pattern,
861 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000862 SourceLocation EllipsisLoc,
863 llvm::Optional<unsigned> NumExpansions) {
864 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
865 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +0000866 }
867
Douglas Gregor1135c352009-08-06 05:28:30 +0000868 /// \brief Build a new nested-name-specifier given the prefix and an
869 /// identifier that names the next step in the nested-name-specifier.
870 ///
871 /// By default, performs semantic analysis when building the new
872 /// nested-name-specifier. Subclasses may override this routine to provide
873 /// different behavior.
874 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
875 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +0000876 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +0000877 QualType ObjectType,
878 NamedDecl *FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +0000879
880 /// \brief Build a new nested-name-specifier given the prefix and the
881 /// namespace named in the next step in the nested-name-specifier.
882 ///
883 /// By default, performs semantic analysis when building the new
884 /// nested-name-specifier. Subclasses may override this routine to provide
885 /// different behavior.
886 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
887 SourceRange Range,
888 NamespaceDecl *NS);
889
890 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor7b26ff92011-02-24 02:36:08 +0000891 /// namespace alias named in the next step in the nested-name-specifier.
892 ///
893 /// By default, performs semantic analysis when building the new
894 /// nested-name-specifier. Subclasses may override this routine to provide
895 /// different behavior.
896 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
897 SourceRange Range,
898 NamespaceAliasDecl *Alias);
899
900 /// \brief Build a new nested-name-specifier given the prefix and the
Douglas Gregor1135c352009-08-06 05:28:30 +0000901 /// type named in the next step in the nested-name-specifier.
902 ///
903 /// By default, performs semantic analysis when building the new
904 /// nested-name-specifier. Subclasses may override this routine to provide
905 /// different behavior.
906 NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
907 SourceRange Range,
908 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +0000909 QualType T);
Douglas Gregor71dc5092009-08-06 06:41:21 +0000910
911 /// \brief Build a new template name given a nested name specifier, a flag
912 /// indicating whether the "template" keyword was provided, and the template
913 /// that the template name refers to.
914 ///
915 /// By default, builds the new template name directly. Subclasses may override
916 /// this routine to provide different behavior.
917 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
918 bool TemplateKW,
919 TemplateDecl *Template);
920
Douglas Gregor71dc5092009-08-06 06:41:21 +0000921 /// \brief Build a new template name given a nested name specifier and the
922 /// name that is referred to as a template.
923 ///
924 /// By default, performs semantic analysis to determine whether the name can
925 /// be resolved to a specific template, then builds the appropriate kind of
926 /// template name. Subclasses may override this routine to provide different
927 /// behavior.
928 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +0000929 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +0000930 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +0000931 QualType ObjectType,
932 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +0000933
Douglas Gregor71395fa2009-11-04 00:56:37 +0000934 /// \brief Build a new template name given a nested name specifier and the
935 /// overloaded operator name that is referred to as a template.
936 ///
937 /// By default, performs semantic analysis to determine whether the name can
938 /// be resolved to a specific template, then builds the appropriate kind of
939 /// template name. Subclasses may override this routine to provide different
940 /// behavior.
941 TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier,
942 OverloadedOperatorKind Operator,
943 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +0000944
945 /// \brief Build a new template name given a template template parameter pack
946 /// and the
947 ///
948 /// By default, performs semantic analysis to determine whether the name can
949 /// be resolved to a specific template, then builds the appropriate kind of
950 /// template name. Subclasses may override this routine to provide different
951 /// behavior.
952 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
953 const TemplateArgument &ArgPack) {
954 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
955 }
956
Douglas Gregorebe10102009-08-20 07:17:43 +0000957 /// \brief Build a new compound statement.
958 ///
959 /// By default, performs semantic analysis to build the new statement.
960 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000961 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000962 MultiStmtArg Statements,
963 SourceLocation RBraceLoc,
964 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +0000965 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +0000966 IsStmtExpr);
967 }
968
969 /// \brief Build a new case statement.
970 ///
971 /// By default, performs semantic analysis to build the new statement.
972 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000973 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +0000974 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000975 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +0000976 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000977 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +0000978 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +0000979 ColonLoc);
980 }
Mike Stump11289f42009-09-09 15:08:12 +0000981
Douglas Gregorebe10102009-08-20 07:17:43 +0000982 /// \brief Attach the body to a new case statement.
983 ///
984 /// By default, performs semantic analysis to build the new statement.
985 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000986 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +0000987 getSema().ActOnCaseStmtBody(S, Body);
988 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +0000989 }
Mike Stump11289f42009-09-09 15:08:12 +0000990
Douglas Gregorebe10102009-08-20 07:17:43 +0000991 /// \brief Build a new default statement.
992 ///
993 /// By default, performs semantic analysis to build the new statement.
994 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +0000995 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +0000996 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +0000997 Stmt *SubStmt) {
998 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Douglas Gregorebe10102009-08-20 07:17:43 +0000999 /*CurScope=*/0);
1000 }
Mike Stump11289f42009-09-09 15:08:12 +00001001
Douglas Gregorebe10102009-08-20 07:17:43 +00001002 /// \brief Build a new label statement.
1003 ///
1004 /// By default, performs semantic analysis to build the new statement.
1005 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001006 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1007 SourceLocation ColonLoc, Stmt *SubStmt) {
1008 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001009 }
Mike Stump11289f42009-09-09 15:08:12 +00001010
Douglas Gregorebe10102009-08-20 07:17:43 +00001011 /// \brief Build a new "if" statement.
1012 ///
1013 /// By default, performs semantic analysis to build the new statement.
1014 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001015 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chris Lattnercab02a62011-02-17 20:34:02 +00001016 VarDecl *CondVar, Stmt *Then,
1017 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001018 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001019 }
Mike Stump11289f42009-09-09 15:08:12 +00001020
Douglas Gregorebe10102009-08-20 07:17:43 +00001021 /// \brief Start building a new switch statement.
1022 ///
1023 /// By default, performs semantic analysis to build the new statement.
1024 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001025 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001026 Expr *Cond, VarDecl *CondVar) {
John McCallb268a282010-08-23 23:25:46 +00001027 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001028 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001029 }
Mike Stump11289f42009-09-09 15:08:12 +00001030
Douglas Gregorebe10102009-08-20 07:17:43 +00001031 /// \brief Attach the body to the switch statement.
1032 ///
1033 /// By default, performs semantic analysis to build the new statement.
1034 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001035 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001036 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001037 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001038 }
1039
1040 /// \brief Build a new while statement.
1041 ///
1042 /// By default, performs semantic analysis to build the new statement.
1043 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001044 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1045 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001046 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001047 }
Mike Stump11289f42009-09-09 15:08:12 +00001048
Douglas Gregorebe10102009-08-20 07:17:43 +00001049 /// \brief Build a new do-while statement.
1050 ///
1051 /// By default, performs semantic analysis to build the new statement.
1052 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001053 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001054 SourceLocation WhileLoc, SourceLocation LParenLoc,
1055 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001056 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1057 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001058 }
1059
1060 /// \brief Build a new for statement.
1061 ///
1062 /// By default, performs semantic analysis to build the new statement.
1063 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001064 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
1065 Stmt *Init, Sema::FullExprArg Cond,
1066 VarDecl *CondVar, Sema::FullExprArg Inc,
1067 SourceLocation RParenLoc, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001068 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001069 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001070 }
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregorebe10102009-08-20 07:17:43 +00001072 /// \brief Build a new goto statement.
1073 ///
1074 /// By default, performs semantic analysis to build the new statement.
1075 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001076 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1077 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001078 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001079 }
1080
1081 /// \brief Build a new indirect goto statement.
1082 ///
1083 /// By default, performs semantic analysis to build the new statement.
1084 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001085 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001086 SourceLocation StarLoc,
1087 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001088 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001089 }
Mike Stump11289f42009-09-09 15:08:12 +00001090
Douglas Gregorebe10102009-08-20 07:17:43 +00001091 /// \brief Build a new return statement.
1092 ///
1093 /// By default, performs semantic analysis to build the new statement.
1094 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001095 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
John McCallb268a282010-08-23 23:25:46 +00001096 return getSema().ActOnReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001097 }
Mike Stump11289f42009-09-09 15:08:12 +00001098
Douglas Gregorebe10102009-08-20 07:17:43 +00001099 /// \brief Build a new declaration statement.
1100 ///
1101 /// By default, performs semantic analysis to build the new statement.
1102 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001103 StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls,
Mike Stump11289f42009-09-09 15:08:12 +00001104 SourceLocation StartLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 SourceLocation EndLoc) {
Richard Smith2abf6762011-02-23 00:37:57 +00001106 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls);
1107 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001108 }
Mike Stump11289f42009-09-09 15:08:12 +00001109
Anders Carlssonaaeef072010-01-24 05:50:09 +00001110 /// \brief Build a new inline asm statement.
1111 ///
1112 /// By default, performs semantic analysis to build the new statement.
1113 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001114 StmtResult RebuildAsmStmt(SourceLocation AsmLoc,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001115 bool IsSimple,
1116 bool IsVolatile,
1117 unsigned NumOutputs,
1118 unsigned NumInputs,
Anders Carlsson9a020f92010-01-30 22:25:16 +00001119 IdentifierInfo **Names,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001120 MultiExprArg Constraints,
1121 MultiExprArg Exprs,
John McCallb268a282010-08-23 23:25:46 +00001122 Expr *AsmString,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001123 MultiExprArg Clobbers,
1124 SourceLocation RParenLoc,
1125 bool MSAsm) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001126 return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001127 NumInputs, Names, move(Constraints),
John McCallb268a282010-08-23 23:25:46 +00001128 Exprs, AsmString, Clobbers,
Anders Carlssonaaeef072010-01-24 05:50:09 +00001129 RParenLoc, MSAsm);
1130 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001131
1132 /// \brief Build a new Objective-C @try statement.
1133 ///
1134 /// By default, performs semantic analysis to build the new statement.
1135 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001136 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001137 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001138 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001139 Stmt *Finally) {
1140 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts),
1141 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001142 }
1143
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001144 /// \brief Rebuild an Objective-C exception declaration.
1145 ///
1146 /// By default, performs semantic analysis to build the new declaration.
1147 /// Subclasses may override this routine to provide different behavior.
1148 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1149 TypeSourceInfo *TInfo, QualType T) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001150 return getSema().BuildObjCExceptionDecl(TInfo, T,
1151 ExceptionDecl->getIdentifier(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001152 ExceptionDecl->getLocation());
1153 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001154
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001155 /// \brief Build a new Objective-C @catch statement.
1156 ///
1157 /// By default, performs semantic analysis to build the new statement.
1158 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001159 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001160 SourceLocation RParenLoc,
1161 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001162 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001163 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001164 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001165 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001166
Douglas Gregor306de2f2010-04-22 23:59:56 +00001167 /// \brief Build a new Objective-C @finally statement.
1168 ///
1169 /// By default, performs semantic analysis to build the new statement.
1170 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001171 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001172 Stmt *Body) {
1173 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001174 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001175
Douglas Gregor6148de72010-04-22 22:01:21 +00001176 /// \brief Build a new Objective-C @throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001177 ///
1178 /// By default, performs semantic analysis to build the new statement.
1179 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001180 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001181 Expr *Operand) {
1182 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001183 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001184
Douglas Gregor6148de72010-04-22 22:01:21 +00001185 /// \brief Build a new Objective-C @synchronized statement.
1186 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001189 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001190 Expr *Object,
1191 Stmt *Body) {
1192 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object,
1193 Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001194 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001195
1196 /// \brief Build a new Objective-C fast enumeration statement.
1197 ///
1198 /// By default, performs semantic analysis to build the new statement.
1199 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001200 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001201 SourceLocation LParenLoc,
1202 Stmt *Element,
1203 Expr *Collection,
1204 SourceLocation RParenLoc,
1205 Stmt *Body) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00001206 return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001207 Element,
1208 Collection,
Douglas Gregorf68a5082010-04-22 23:10:45 +00001209 RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001210 Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001211 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001212
Douglas Gregorebe10102009-08-20 07:17:43 +00001213 /// \brief Build a new C++ exception declaration.
1214 ///
1215 /// By default, performs semantic analysis to build the new decaration.
1216 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001217 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001218 TypeSourceInfo *Declarator,
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 IdentifierInfo *Name,
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00001220 SourceLocation Loc) {
1221 return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001222 }
1223
1224 /// \brief Build a new C++ catch statement.
1225 ///
1226 /// By default, performs semantic analysis to build the new statement.
1227 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001228 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001229 VarDecl *ExceptionDecl,
1230 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001231 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1232 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001233 }
Mike Stump11289f42009-09-09 15:08:12 +00001234
Douglas Gregorebe10102009-08-20 07:17:43 +00001235 /// \brief Build a new C++ try statement.
1236 ///
1237 /// By default, performs semantic analysis to build the new statement.
1238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001239 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001240 Stmt *TryBlock,
1241 MultiStmtArg Handlers) {
John McCallb268a282010-08-23 23:25:46 +00001242 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00001243 }
Mike Stump11289f42009-09-09 15:08:12 +00001244
Douglas Gregora16548e2009-08-11 05:31:07 +00001245 /// \brief Build a new expression that references a declaration.
1246 ///
1247 /// By default, performs semantic analysis to build the new expression.
1248 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001249 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001250 LookupResult &R,
1251 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001252 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1253 }
1254
1255
1256 /// \brief Build a new expression that references a declaration.
1257 ///
1258 /// By default, performs semantic analysis to build the new expression.
1259 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001260 ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier,
John McCallfaf5fb42010-08-26 23:41:50 +00001261 SourceRange QualifierRange,
1262 ValueDecl *VD,
1263 const DeclarationNameInfo &NameInfo,
1264 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001265 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00001266 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
John McCallce546572009-12-08 09:08:17 +00001267
1268 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001269
1270 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001271 }
Mike Stump11289f42009-09-09 15:08:12 +00001272
Douglas Gregora16548e2009-08-11 05:31:07 +00001273 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001274 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001275 /// By default, performs semantic analysis to build the new expression.
1276 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001277 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001278 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001279 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001280 }
1281
Douglas Gregorad8a3362009-09-04 17:36:40 +00001282 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001283 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001284 /// By default, performs semantic analysis to build the new expression.
1285 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001286 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001287 SourceLocation OperatorLoc,
1288 bool isArrow,
1289 CXXScopeSpec &SS,
1290 TypeSourceInfo *ScopeType,
1291 SourceLocation CCLoc,
1292 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001293 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001294
Douglas Gregora16548e2009-08-11 05:31:07 +00001295 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001296 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001297 /// By default, performs semantic analysis to build the new expression.
1298 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001299 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001300 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001301 Expr *SubExpr) {
1302 return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001303 }
Mike Stump11289f42009-09-09 15:08:12 +00001304
Douglas Gregor882211c2010-04-28 22:16:22 +00001305 /// \brief Build a new builtin offsetof expression.
1306 ///
1307 /// By default, performs semantic analysis to build the new expression.
1308 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001309 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001310 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001311 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001312 unsigned NumComponents,
1313 SourceLocation RParenLoc) {
1314 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1315 NumComponents, RParenLoc);
1316 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00001317
Douglas Gregora16548e2009-08-11 05:31:07 +00001318 /// \brief Build a new sizeof or alignof expression with a type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001319 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001320 /// By default, performs semantic analysis to build the new expression.
1321 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001322 ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo,
John McCall4c98fd82009-11-04 07:28:41 +00001323 SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001324 bool isSizeOf, SourceRange R) {
John McCallbcd03502009-12-07 02:54:59 +00001325 return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001326 }
1327
Mike Stump11289f42009-09-09 15:08:12 +00001328 /// \brief Build a new sizeof or alignof expression with an expression
Douglas Gregora16548e2009-08-11 05:31:07 +00001329 /// argument.
Mike Stump11289f42009-09-09 15:08:12 +00001330 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001331 /// By default, performs semantic analysis to build the new expression.
1332 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001333 ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001334 bool isSizeOf, SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001335 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00001336 = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001337 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001338 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001339
Douglas Gregora16548e2009-08-11 05:31:07 +00001340 return move(Result);
1341 }
Mike Stump11289f42009-09-09 15:08:12 +00001342
Douglas Gregora16548e2009-08-11 05:31:07 +00001343 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001344 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001345 /// By default, performs semantic analysis to build the new expression.
1346 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001347 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001348 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001349 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001350 SourceLocation RBracketLoc) {
John McCallb268a282010-08-23 23:25:46 +00001351 return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS,
1352 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001353 RBracketLoc);
1354 }
1355
1356 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001357 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001358 /// By default, performs semantic analysis to build the new expression.
1359 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001360 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001361 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001362 SourceLocation RParenLoc,
1363 Expr *ExecConfig = 0) {
John McCallb268a282010-08-23 23:25:46 +00001364 return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001365 move(Args), RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001366 }
1367
1368 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001369 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001370 /// By default, performs semantic analysis to build the new expression.
1371 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001372 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001373 bool isArrow,
1374 NestedNameSpecifier *Qualifier,
1375 SourceRange QualifierRange,
1376 const DeclarationNameInfo &MemberNameInfo,
1377 ValueDecl *Member,
1378 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001379 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001380 NamedDecl *FirstQualifierInScope) {
Anders Carlsson5da84842009-09-01 04:26:58 +00001381 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001382 // We have a reference to an unnamed field. This is always the
1383 // base of an anonymous struct/union member access, i.e. the
1384 // field is always of record type.
Anders Carlsson5da84842009-09-01 04:26:58 +00001385 assert(!Qualifier && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001386 assert(Member->getType()->isRecordType() &&
1387 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001388
John McCallb268a282010-08-23 23:25:46 +00001389 if (getSema().PerformObjectMemberConversion(Base, Qualifier,
John McCall16df1e52010-03-30 21:47:33 +00001390 FoundDecl, Member))
John McCallfaf5fb42010-08-26 23:41:50 +00001391 return ExprError();
Douglas Gregor4b654412009-12-24 20:23:34 +00001392
John McCall7decc9e2010-11-18 06:31:45 +00001393 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Mike Stump11289f42009-09-09 15:08:12 +00001394 MemberExpr *ME =
John McCallb268a282010-08-23 23:25:46 +00001395 new (getSema().Context) MemberExpr(Base, isArrow,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001396 Member, MemberNameInfo,
John McCall7decc9e2010-11-18 06:31:45 +00001397 cast<FieldDecl>(Member)->getType(),
1398 VK, OK_Ordinary);
Anders Carlsson5da84842009-09-01 04:26:58 +00001399 return getSema().Owned(ME);
1400 }
Mike Stump11289f42009-09-09 15:08:12 +00001401
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001402 CXXScopeSpec SS;
1403 if (Qualifier) {
Douglas Gregor869ad452011-02-24 17:54:50 +00001404 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001405 }
1406
John McCallb268a282010-08-23 23:25:46 +00001407 getSema().DefaultFunctionArrayConversion(Base);
1408 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001409
John McCall16df1e52010-03-30 21:47:33 +00001410 // FIXME: this involves duplicating earlier analysis in a lot of
1411 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001412 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001413 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001414 R.resolveKind();
1415
John McCallb268a282010-08-23 23:25:46 +00001416 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
John McCall10eae182009-11-30 22:42:35 +00001417 SS, FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001418 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001419 }
Mike Stump11289f42009-09-09 15:08:12 +00001420
Douglas Gregora16548e2009-08-11 05:31:07 +00001421 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001422 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001423 /// By default, performs semantic analysis to build the new expression.
1424 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001425 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001426 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001427 Expr *LHS, Expr *RHS) {
1428 return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001429 }
1430
1431 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001432 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001433 /// By default, performs semantic analysis to build the new expression.
1434 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001435 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001436 SourceLocation QuestionLoc,
1437 Expr *LHS,
1438 SourceLocation ColonLoc,
1439 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001440 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1441 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001442 }
1443
Douglas Gregora16548e2009-08-11 05:31:07 +00001444 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001445 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001446 /// By default, performs semantic analysis to build the new expression.
1447 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001448 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00001449 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001450 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001451 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00001452 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001453 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001454 }
Mike Stump11289f42009-09-09 15:08:12 +00001455
Douglas Gregora16548e2009-08-11 05:31:07 +00001456 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00001457 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001458 /// By default, performs semantic analysis to build the new expression.
1459 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001460 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00001461 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001462 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001463 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00001464 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001465 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001466 }
Mike Stump11289f42009-09-09 15:08:12 +00001467
Douglas Gregora16548e2009-08-11 05:31:07 +00001468 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001469 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001470 /// By default, performs semantic analysis to build the new expression.
1471 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001472 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00001473 SourceLocation OpLoc,
1474 SourceLocation AccessorLoc,
1475 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00001476
John McCall10eae182009-11-30 22:42:35 +00001477 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001478 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00001479 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00001480 OpLoc, /*IsArrow*/ false,
1481 SS, /*FirstQualifierInScope*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001482 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00001483 /* TemplateArgs */ 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00001484 }
Mike Stump11289f42009-09-09 15:08:12 +00001485
Douglas Gregora16548e2009-08-11 05:31:07 +00001486 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00001487 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001488 /// By default, performs semantic analysis to build the new expression.
1489 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001490 ExprResult RebuildInitList(SourceLocation LBraceLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001491 MultiExprArg Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00001492 SourceLocation RBraceLoc,
1493 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00001494 ExprResult Result
Douglas Gregord3d93062009-11-09 17:16:50 +00001495 = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc);
1496 if (Result.isInvalid() || ResultTy->isDependentType())
1497 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001498
Douglas Gregord3d93062009-11-09 17:16:50 +00001499 // Patch in the result type we were given, which may have been computed
1500 // when the initial InitListExpr was built.
1501 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
1502 ILE->setType(ResultTy);
1503 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00001504 }
Mike Stump11289f42009-09-09 15:08:12 +00001505
Douglas Gregora16548e2009-08-11 05:31:07 +00001506 /// \brief Build a new designated initializer 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 RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00001511 MultiExprArg ArrayExprs,
1512 SourceLocation EqualOrColonLoc,
1513 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001514 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00001515 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00001516 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00001517 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00001518 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001519 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001520
Douglas Gregora16548e2009-08-11 05:31:07 +00001521 ArrayExprs.release();
1522 return move(Result);
1523 }
Mike Stump11289f42009-09-09 15:08:12 +00001524
Douglas Gregora16548e2009-08-11 05:31:07 +00001525 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00001526 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001527 /// By default, builds the implicit value initialization without performing
1528 /// any semantic analysis. Subclasses may override this routine to provide
1529 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001530 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001531 return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T));
1532 }
Mike Stump11289f42009-09-09 15:08:12 +00001533
Douglas Gregora16548e2009-08-11 05:31:07 +00001534 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00001535 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001536 /// By default, performs semantic analysis to build the new expression.
1537 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001538 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001539 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001540 SourceLocation RParenLoc) {
1541 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001542 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00001543 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001544 }
1545
1546 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001547 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001548 /// By default, performs semantic analysis to build the new expression.
1549 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001550 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001551 MultiExprArg SubExprs,
1552 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001553 return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc,
Fariborz Jahanian906d8712009-11-25 01:26:41 +00001554 move(SubExprs));
Douglas Gregora16548e2009-08-11 05:31:07 +00001555 }
Mike Stump11289f42009-09-09 15:08:12 +00001556
Douglas Gregora16548e2009-08-11 05:31:07 +00001557 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00001558 ///
1559 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00001560 /// rather than attempting to map the label statement itself.
1561 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001562 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001563 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001564 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00001565 }
Mike Stump11289f42009-09-09 15:08:12 +00001566
Douglas Gregora16548e2009-08-11 05:31:07 +00001567 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00001568 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001569 /// By default, performs semantic analysis to build the new expression.
1570 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001571 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001572 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00001573 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001574 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001575 }
Mike Stump11289f42009-09-09 15:08:12 +00001576
Douglas Gregora16548e2009-08-11 05:31:07 +00001577 /// \brief Build a new __builtin_choose_expr expression.
1578 ///
1579 /// By default, performs semantic analysis to build the new expression.
1580 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001581 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001582 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001583 SourceLocation RParenLoc) {
1584 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00001585 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001586 RParenLoc);
1587 }
Mike Stump11289f42009-09-09 15:08:12 +00001588
Douglas Gregora16548e2009-08-11 05:31:07 +00001589 /// \brief Build a new overloaded operator call expression.
1590 ///
1591 /// By default, performs semantic analysis to build the new expression.
1592 /// The semantic analysis provides the behavior of template instantiation,
1593 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00001594 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00001595 /// argument-dependent lookup, etc. Subclasses may override this routine to
1596 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001597 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00001598 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00001599 Expr *Callee,
1600 Expr *First,
1601 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00001602
1603 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00001604 /// reinterpret_cast.
1605 ///
1606 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00001607 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00001608 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001609 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001610 Stmt::StmtClass Class,
1611 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001612 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001613 SourceLocation RAngleLoc,
1614 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001615 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001616 SourceLocation RParenLoc) {
1617 switch (Class) {
1618 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001619 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001620 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001621 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001622
1623 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001624 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001625 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001626 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001627
Douglas Gregora16548e2009-08-11 05:31:07 +00001628 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001629 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001630 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001631 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001632 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001633
Douglas Gregora16548e2009-08-11 05:31:07 +00001634 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00001635 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00001636 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001637 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001638
Douglas Gregora16548e2009-08-11 05:31:07 +00001639 default:
1640 assert(false && "Invalid C++ named cast");
1641 break;
1642 }
Mike Stump11289f42009-09-09 15:08:12 +00001643
John McCallfaf5fb42010-08-26 23:41:50 +00001644 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00001645 }
Mike Stump11289f42009-09-09 15:08:12 +00001646
Douglas Gregora16548e2009-08-11 05:31:07 +00001647 /// \brief Build a new C++ static_cast expression.
1648 ///
1649 /// By default, performs semantic analysis to build the new expression.
1650 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001651 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001652 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001653 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001654 SourceLocation RAngleLoc,
1655 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001656 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001657 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001658 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00001659 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001660 SourceRange(LAngleLoc, RAngleLoc),
1661 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001662 }
1663
1664 /// \brief Build a new C++ dynamic_cast expression.
1665 ///
1666 /// By default, performs semantic analysis to build the new expression.
1667 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001668 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001669 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001670 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001671 SourceLocation RAngleLoc,
1672 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001673 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001674 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001675 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00001676 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001677 SourceRange(LAngleLoc, RAngleLoc),
1678 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001679 }
1680
1681 /// \brief Build a new C++ reinterpret_cast expression.
1682 ///
1683 /// By default, performs semantic analysis to build the new expression.
1684 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001685 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001686 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001687 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001688 SourceLocation RAngleLoc,
1689 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001690 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001691 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001692 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00001693 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001694 SourceRange(LAngleLoc, RAngleLoc),
1695 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001696 }
1697
1698 /// \brief Build a new C++ const_cast expression.
1699 ///
1700 /// By default, performs semantic analysis to build the new expression.
1701 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001702 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001703 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00001704 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001705 SourceLocation RAngleLoc,
1706 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001707 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00001708 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00001709 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00001710 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00001711 SourceRange(LAngleLoc, RAngleLoc),
1712 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00001713 }
Mike Stump11289f42009-09-09 15:08:12 +00001714
Douglas Gregora16548e2009-08-11 05:31:07 +00001715 /// \brief Build a new C++ functional-style cast expression.
1716 ///
1717 /// By default, performs semantic analysis to build the new expression.
1718 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001719 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
1720 SourceLocation LParenLoc,
1721 Expr *Sub,
1722 SourceLocation RParenLoc) {
1723 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001724 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00001725 RParenLoc);
1726 }
Mike Stump11289f42009-09-09 15:08:12 +00001727
Douglas Gregora16548e2009-08-11 05:31:07 +00001728 /// \brief Build a new C++ typeid(type) expression.
1729 ///
1730 /// By default, performs semantic analysis to build the new expression.
1731 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001732 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001733 SourceLocation TypeidLoc,
1734 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001735 SourceLocation RParenLoc) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00001736 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001737 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001738 }
Mike Stump11289f42009-09-09 15:08:12 +00001739
Francois Pichet9f4f2072010-09-08 12:20:18 +00001740
Douglas Gregora16548e2009-08-11 05:31:07 +00001741 /// \brief Build a new C++ typeid(expr) expression.
1742 ///
1743 /// By default, performs semantic analysis to build the new expression.
1744 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001745 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00001746 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00001747 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00001748 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001749 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00001750 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00001751 }
1752
Francois Pichet9f4f2072010-09-08 12:20:18 +00001753 /// \brief Build a new C++ __uuidof(type) expression.
1754 ///
1755 /// By default, performs semantic analysis to build the new expression.
1756 /// Subclasses may override this routine to provide different behavior.
1757 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1758 SourceLocation TypeidLoc,
1759 TypeSourceInfo *Operand,
1760 SourceLocation RParenLoc) {
1761 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1762 RParenLoc);
1763 }
1764
1765 /// \brief Build a new C++ __uuidof(expr) expression.
1766 ///
1767 /// By default, performs semantic analysis to build the new expression.
1768 /// Subclasses may override this routine to provide different behavior.
1769 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
1770 SourceLocation TypeidLoc,
1771 Expr *Operand,
1772 SourceLocation RParenLoc) {
1773 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
1774 RParenLoc);
1775 }
1776
Douglas Gregora16548e2009-08-11 05:31:07 +00001777 /// \brief Build a new C++ "this" expression.
1778 ///
1779 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00001780 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00001781 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001782 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00001783 QualType ThisType,
1784 bool isImplicit) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001785 return getSema().Owned(
Douglas Gregorb15af892010-01-07 23:12:05 +00001786 new (getSema().Context) CXXThisExpr(ThisLoc, ThisType,
1787 isImplicit));
Douglas Gregora16548e2009-08-11 05:31:07 +00001788 }
1789
1790 /// \brief Build a new C++ throw expression.
1791 ///
1792 /// By default, performs semantic analysis to build the new expression.
1793 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001794 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) {
John McCallb268a282010-08-23 23:25:46 +00001795 return getSema().ActOnCXXThrow(ThrowLoc, Sub);
Douglas Gregora16548e2009-08-11 05:31:07 +00001796 }
1797
1798 /// \brief Build a new C++ default-argument expression.
1799 ///
1800 /// By default, builds a new default-argument expression, which does not
1801 /// require any semantic analysis. Subclasses may override this routine to
1802 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001803 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00001804 ParmVarDecl *Param) {
1805 return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc,
1806 Param));
Douglas Gregora16548e2009-08-11 05:31:07 +00001807 }
1808
1809 /// \brief Build a new C++ zero-initialization expression.
1810 ///
1811 /// By default, performs semantic analysis to build the new expression.
1812 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001813 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
1814 SourceLocation LParenLoc,
1815 SourceLocation RParenLoc) {
1816 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Mike Stump11289f42009-09-09 15:08:12 +00001817 MultiExprArg(getSema(), 0, 0),
Douglas Gregor2b88c112010-09-08 00:15:04 +00001818 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001819 }
Mike Stump11289f42009-09-09 15:08:12 +00001820
Douglas Gregora16548e2009-08-11 05:31:07 +00001821 /// \brief Build a new C++ "new" expression.
1822 ///
1823 /// By default, performs semantic analysis to build the new expression.
1824 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001825 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001826 bool UseGlobal,
1827 SourceLocation PlacementLParen,
1828 MultiExprArg PlacementArgs,
1829 SourceLocation PlacementRParen,
1830 SourceRange TypeIdParens,
1831 QualType AllocatedType,
1832 TypeSourceInfo *AllocatedTypeInfo,
1833 Expr *ArraySize,
1834 SourceLocation ConstructorLParen,
1835 MultiExprArg ConstructorArgs,
1836 SourceLocation ConstructorRParen) {
Mike Stump11289f42009-09-09 15:08:12 +00001837 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00001838 PlacementLParen,
1839 move(PlacementArgs),
1840 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00001841 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00001842 AllocatedType,
1843 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00001844 ArraySize,
Douglas Gregora16548e2009-08-11 05:31:07 +00001845 ConstructorLParen,
1846 move(ConstructorArgs),
1847 ConstructorRParen);
1848 }
Mike Stump11289f42009-09-09 15:08:12 +00001849
Douglas Gregora16548e2009-08-11 05:31:07 +00001850 /// \brief Build a new C++ "delete" expression.
1851 ///
1852 /// By default, performs semantic analysis to build the new expression.
1853 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001854 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001855 bool IsGlobalDelete,
1856 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001857 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001858 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00001859 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00001860 }
Mike Stump11289f42009-09-09 15:08:12 +00001861
Douglas Gregora16548e2009-08-11 05:31:07 +00001862 /// \brief Build a new unary type trait expression.
1863 ///
1864 /// By default, performs semantic analysis to build the new expression.
1865 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001866 ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait,
Douglas Gregor54e5b132010-09-09 16:14:44 +00001867 SourceLocation StartLoc,
1868 TypeSourceInfo *T,
1869 SourceLocation RParenLoc) {
1870 return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00001871 }
1872
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00001873 /// \brief Build a new binary type trait expression.
1874 ///
1875 /// By default, performs semantic analysis to build the new expression.
1876 /// Subclasses may override this routine to provide different behavior.
1877 ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait,
1878 SourceLocation StartLoc,
1879 TypeSourceInfo *LhsT,
1880 TypeSourceInfo *RhsT,
1881 SourceLocation RParenLoc) {
1882 return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc);
1883 }
1884
Mike Stump11289f42009-09-09 15:08:12 +00001885 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00001886 /// expression.
1887 ///
1888 /// By default, performs semantic analysis to build the new expression.
1889 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001890 ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 SourceRange QualifierRange,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001892 const DeclarationNameInfo &NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001893 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00001895 SS.MakeTrivial(SemaRef.Context, NNS, QualifierRange);
John McCalle66edc12009-11-24 19:00:30 +00001896
1897 if (TemplateArgs)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001898 return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00001899 *TemplateArgs);
1900
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001901 return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo);
Douglas Gregora16548e2009-08-11 05:31:07 +00001902 }
1903
1904 /// \brief Build a new template-id expression.
1905 ///
1906 /// By default, performs semantic analysis to build the new expression.
1907 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001908 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
John McCalle66edc12009-11-24 19:00:30 +00001909 LookupResult &R,
1910 bool RequiresADL,
John McCall6b51f282009-11-23 01:53:49 +00001911 const TemplateArgumentListInfo &TemplateArgs) {
John McCalle66edc12009-11-24 19:00:30 +00001912 return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 }
1914
1915 /// \brief Build a new object-construction expression.
1916 ///
1917 /// By default, performs semantic analysis to build the new expression.
1918 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001919 ExprResult RebuildCXXConstructExpr(QualType T,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001920 SourceLocation Loc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 CXXConstructorDecl *Constructor,
1922 bool IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001923 MultiExprArg Args,
1924 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00001925 CXXConstructExpr::ConstructionKind ConstructKind,
1926 SourceRange ParenRange) {
John McCall37ad5512010-08-23 06:44:23 +00001927 ASTOwningVector<Expr*> ConvertedArgs(SemaRef);
Alexis Hunta8136cc2010-05-05 15:23:54 +00001928 if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00001929 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00001930 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00001931
Douglas Gregordb121ba2009-12-14 16:27:04 +00001932 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00001933 move_arg(ConvertedArgs),
Chandler Carruth01718152010-10-25 08:47:36 +00001934 RequiresZeroInit, ConstructKind,
1935 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00001936 }
1937
1938 /// \brief Build a new object-construction expression.
1939 ///
1940 /// By default, performs semantic analysis to build the new expression.
1941 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001942 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
1943 SourceLocation LParenLoc,
1944 MultiExprArg Args,
1945 SourceLocation RParenLoc) {
1946 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001947 LParenLoc,
1948 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001949 RParenLoc);
1950 }
1951
1952 /// \brief Build a new object-construction expression.
1953 ///
1954 /// By default, performs semantic analysis to build the new expression.
1955 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00001956 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
1957 SourceLocation LParenLoc,
1958 MultiExprArg Args,
1959 SourceLocation RParenLoc) {
1960 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00001961 LParenLoc,
1962 move(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00001963 RParenLoc);
1964 }
Mike Stump11289f42009-09-09 15:08:12 +00001965
Douglas Gregora16548e2009-08-11 05:31:07 +00001966 /// \brief Build a new member reference expression.
1967 ///
1968 /// By default, performs semantic analysis to build the new expression.
1969 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001970 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001971 QualType BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 bool IsArrow,
1973 SourceLocation OperatorLoc,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00001974 NestedNameSpecifier *Qualifier,
1975 SourceRange QualifierRange,
John McCall10eae182009-11-30 22:42:35 +00001976 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001977 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00001978 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00001979 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00001980 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00001981
John McCallb268a282010-08-23 23:25:46 +00001982 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00001983 OperatorLoc, IsArrow,
John McCall10eae182009-11-30 22:42:35 +00001984 SS, FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001985 MemberNameInfo,
1986 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001987 }
1988
John McCall10eae182009-11-30 22:42:35 +00001989 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00001990 ///
1991 /// By default, performs semantic analysis to build the new expression.
1992 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001993 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE,
John McCall2d74de92009-12-01 22:10:20 +00001994 QualType BaseType,
John McCall10eae182009-11-30 22:42:35 +00001995 SourceLocation OperatorLoc,
1996 bool IsArrow,
1997 NestedNameSpecifier *Qualifier,
1998 SourceRange QualifierRange,
John McCall38836f02010-01-15 08:34:02 +00001999 NamedDecl *FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00002000 LookupResult &R,
2001 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002002 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00002003 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Mike Stump11289f42009-09-09 15:08:12 +00002004
John McCallb268a282010-08-23 23:25:46 +00002005 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002006 OperatorLoc, IsArrow,
John McCall38836f02010-01-15 08:34:02 +00002007 SS, FirstQualifierInScope,
2008 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002009 }
Mike Stump11289f42009-09-09 15:08:12 +00002010
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002011 /// \brief Build a new noexcept expression.
2012 ///
2013 /// By default, performs semantic analysis to build the new expression.
2014 /// Subclasses may override this routine to provide different behavior.
2015 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2016 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2017 }
2018
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002019 /// \brief Build a new expression to compute the length of a parameter pack.
2020 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2021 SourceLocation PackLoc,
2022 SourceLocation RParenLoc,
2023 unsigned Length) {
2024 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2025 OperatorLoc, Pack, PackLoc,
2026 RParenLoc, Length);
2027 }
2028
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 /// \brief Build a new Objective-C @encode 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 RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002034 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002035 SourceLocation RParenLoc) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00002036 return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002037 RParenLoc));
Mike Stump11289f42009-09-09 15:08:12 +00002038 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002039
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002040 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002041 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002042 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002043 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002044 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002045 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002046 MultiExprArg Args,
2047 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002048 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2049 ReceiverTypeInfo->getType(),
2050 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002051 Sel, Method, LBracLoc, SelectorLoc,
2052 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002053 }
2054
2055 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002056 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002057 Selector Sel,
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002058 SourceLocation SelectorLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002059 ObjCMethodDecl *Method,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002060 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002061 MultiExprArg Args,
2062 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002063 return SemaRef.BuildInstanceMessage(Receiver,
2064 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002065 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00002066 Sel, Method, LBracLoc, SelectorLoc,
2067 RBracLoc, move(Args));
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002068 }
2069
Douglas Gregord51d90d2010-04-26 20:11:03 +00002070 /// \brief Build a new Objective-C ivar reference expression.
2071 ///
2072 /// By default, performs semantic analysis to build the new expression.
2073 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002074 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002075 SourceLocation IvarLoc,
2076 bool IsArrow, bool IsFreeIvar) {
2077 // FIXME: We lose track of the IsFreeIvar bit.
2078 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002079 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002080 LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc,
2081 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002082 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002083 /*FIME:*/IvarLoc,
John McCall48871652010-08-21 09:40:31 +00002084 SS, 0,
John McCalle9cccd82010-06-16 08:42:20 +00002085 false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002086 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002087 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002088
Douglas Gregord51d90d2010-04-26 20:11:03 +00002089 if (Result.get())
2090 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002091
John McCallb268a282010-08-23 23:25:46 +00002092 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002093 /*FIXME:*/IvarLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002094 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002095 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002096 /*TemplateArgs=*/0);
2097 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002098
2099 /// \brief Build a new Objective-C property reference expression.
2100 ///
2101 /// By default, performs semantic analysis to build the new expression.
2102 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002103 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
Douglas Gregor9faee212010-04-26 20:47:02 +00002104 ObjCPropertyDecl *Property,
2105 SourceLocation PropertyLoc) {
2106 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002107 Expr *Base = BaseArg;
Douglas Gregor9faee212010-04-26 20:47:02 +00002108 LookupResult R(getSema(), Property->getDeclName(), PropertyLoc,
2109 Sema::LookupMemberName);
2110 bool IsArrow = false;
John McCalldadc5752010-08-24 06:29:42 +00002111 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregor9faee212010-04-26 20:47:02 +00002112 /*FIME:*/PropertyLoc,
John McCall48871652010-08-21 09:40:31 +00002113 SS, 0, false);
Douglas Gregor9faee212010-04-26 20:47:02 +00002114 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002115 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002116
Douglas Gregor9faee212010-04-26 20:47:02 +00002117 if (Result.get())
2118 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002119
John McCallb268a282010-08-23 23:25:46 +00002120 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002121 /*FIXME:*/PropertyLoc, IsArrow,
2122 SS,
Douglas Gregor9faee212010-04-26 20:47:02 +00002123 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002124 R,
Douglas Gregor9faee212010-04-26 20:47:02 +00002125 /*TemplateArgs=*/0);
2126 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002127
John McCallb7bd14f2010-12-02 01:19:52 +00002128 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002129 ///
2130 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002131 /// Subclasses may override this routine to provide different behavior.
2132 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2133 ObjCMethodDecl *Getter,
2134 ObjCMethodDecl *Setter,
2135 SourceLocation PropertyLoc) {
2136 // Since these expressions can only be value-dependent, we do not
2137 // need to perform semantic analysis again.
2138 return Owned(
2139 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2140 VK_LValue, OK_ObjCProperty,
2141 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002142 }
2143
Douglas Gregord51d90d2010-04-26 20:11:03 +00002144 /// \brief Build a new Objective-C "isa" expression.
2145 ///
2146 /// By default, performs semantic analysis to build the new expression.
2147 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002148 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002149 bool IsArrow) {
2150 CXXScopeSpec SS;
John McCallb268a282010-08-23 23:25:46 +00002151 Expr *Base = BaseArg;
Douglas Gregord51d90d2010-04-26 20:11:03 +00002152 LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc,
2153 Sema::LookupMemberName);
John McCalldadc5752010-08-24 06:29:42 +00002154 ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002155 /*FIME:*/IsaLoc,
John McCall48871652010-08-21 09:40:31 +00002156 SS, 0, false);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002157 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002158 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00002159
Douglas Gregord51d90d2010-04-26 20:11:03 +00002160 if (Result.get())
2161 return move(Result);
Alexis Hunta8136cc2010-05-05 15:23:54 +00002162
John McCallb268a282010-08-23 23:25:46 +00002163 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
Alexis Hunta8136cc2010-05-05 15:23:54 +00002164 /*FIXME:*/IsaLoc, IsArrow, SS,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002165 /*FirstQualifierInScope=*/0,
Alexis Hunta8136cc2010-05-05 15:23:54 +00002166 R,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002167 /*TemplateArgs=*/0);
2168 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002169
Douglas Gregora16548e2009-08-11 05:31:07 +00002170 /// \brief Build a new shuffle vector expression.
2171 ///
2172 /// By default, performs semantic analysis to build the new expression.
2173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002174 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002175 MultiExprArg SubExprs,
2176 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002177 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002178 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2180 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2181 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
2182 assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002183
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 // Build a reference to the __builtin_shufflevector builtin
2185 FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first);
Mike Stump11289f42009-09-09 15:08:12 +00002186 Expr *Callee
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(),
John McCall7decc9e2010-11-18 06:31:45 +00002188 VK_LValue, BuiltinLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002189 SemaRef.UsualUnaryConversions(Callee);
Mike Stump11289f42009-09-09 15:08:12 +00002190
2191 // Build the CallExpr
Douglas Gregora16548e2009-08-11 05:31:07 +00002192 unsigned NumSubExprs = SubExprs.size();
2193 Expr **Subs = (Expr **)SubExprs.release();
2194 CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee,
2195 Subs, NumSubExprs,
Douglas Gregor603d81b2010-07-13 08:18:22 +00002196 Builtin->getCallResultType(),
John McCall7decc9e2010-11-18 06:31:45 +00002197 Expr::getValueKindForType(Builtin->getResultType()),
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 RParenLoc);
John McCalldadc5752010-08-24 06:29:42 +00002199 ExprResult OwnedCall(SemaRef.Owned(TheCall));
Mike Stump11289f42009-09-09 15:08:12 +00002200
Douglas Gregora16548e2009-08-11 05:31:07 +00002201 // Type-check the __builtin_shufflevector expression.
John McCalldadc5752010-08-24 06:29:42 +00002202 ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall);
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002204 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002205
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 OwnedCall.release();
Mike Stump11289f42009-09-09 15:08:12 +00002207 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 }
John McCall31f82722010-11-12 08:19:04 +00002209
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002210 /// \brief Build a new template argument pack expansion.
2211 ///
2212 /// By default, performs semantic analysis to build a new pack expansion
2213 /// for a template argument. Subclasses may override this routine to provide
2214 /// different behavior.
2215 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002216 SourceLocation EllipsisLoc,
2217 llvm::Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002218 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002219 case TemplateArgument::Expression: {
2220 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002221 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2222 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002223 if (Result.isInvalid())
2224 return TemplateArgumentLoc();
2225
2226 return TemplateArgumentLoc(Result.get(), Result.get());
2227 }
Douglas Gregor968f23a2011-01-03 19:31:53 +00002228
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002229 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002230 return TemplateArgumentLoc(TemplateArgument(
2231 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002232 NumExpansions),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002233 Pattern.getTemplateQualifierRange(),
2234 Pattern.getTemplateNameLoc(),
2235 EllipsisLoc);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002236
2237 case TemplateArgument::Null:
2238 case TemplateArgument::Integral:
2239 case TemplateArgument::Declaration:
2240 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002241 case TemplateArgument::TemplateExpansion:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002242 llvm_unreachable("Pack expansion pattern has no parameter packs");
2243
2244 case TemplateArgument::Type:
2245 if (TypeSourceInfo *Expansion
2246 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002247 EllipsisLoc,
2248 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002249 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2250 Expansion);
2251 break;
2252 }
2253
2254 return TemplateArgumentLoc();
2255 }
2256
Douglas Gregor968f23a2011-01-03 19:31:53 +00002257 /// \brief Build a new expression pack expansion.
2258 ///
2259 /// By default, performs semantic analysis to build a new pack expansion
2260 /// for an expression. Subclasses may override this routine to provide
2261 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002262 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
2263 llvm::Optional<unsigned> NumExpansions) {
2264 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002265 }
2266
John McCall31f82722010-11-12 08:19:04 +00002267private:
2268 QualType TransformTypeInObjectScope(QualType T,
2269 QualType ObjectType,
2270 NamedDecl *FirstQualifierInScope,
2271 NestedNameSpecifier *Prefix);
2272
2273 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T,
2274 QualType ObjectType,
2275 NamedDecl *FirstQualifierInScope,
2276 NestedNameSpecifier *Prefix);
Douglas Gregor14454802011-02-25 02:25:35 +00002277
2278 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2279 QualType ObjectType,
2280 NamedDecl *FirstQualifierInScope,
2281 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002282};
Douglas Gregora16548e2009-08-11 05:31:07 +00002283
Douglas Gregorebe10102009-08-20 07:17:43 +00002284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002285StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002286 if (!S)
2287 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00002288
Douglas Gregorebe10102009-08-20 07:17:43 +00002289 switch (S->getStmtClass()) {
2290 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002291
Douglas Gregorebe10102009-08-20 07:17:43 +00002292 // Transform individual statement nodes
2293#define STMT(Node, Parent) \
2294 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002295#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002296#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002297#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002298
Douglas Gregorebe10102009-08-20 07:17:43 +00002299 // Transform expressions by calling TransformExpr.
2300#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002301#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002302#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002303#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002304 {
John McCalldadc5752010-08-24 06:29:42 +00002305 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002306 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002307 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002308
John McCallb268a282010-08-23 23:25:46 +00002309 return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take()));
Douglas Gregorebe10102009-08-20 07:17:43 +00002310 }
Mike Stump11289f42009-09-09 15:08:12 +00002311 }
2312
John McCallc3007a22010-10-26 07:05:15 +00002313 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00002314}
Mike Stump11289f42009-09-09 15:08:12 +00002315
2316
Douglas Gregore922c772009-08-04 22:27:00 +00002317template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002318ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002319 if (!E)
2320 return SemaRef.Owned(E);
2321
2322 switch (E->getStmtClass()) {
2323 case Stmt::NoStmtClass: break;
2324#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00002325#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00002326#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00002327 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00002328#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002329 }
2330
John McCallc3007a22010-10-26 07:05:15 +00002331 return SemaRef.Owned(E);
Douglas Gregor766b0bb2009-08-06 22:17:10 +00002332}
2333
2334template<typename Derived>
Douglas Gregora3efea12011-01-03 19:04:46 +00002335bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
2336 unsigned NumInputs,
2337 bool IsCall,
2338 llvm::SmallVectorImpl<Expr *> &Outputs,
2339 bool *ArgChanged) {
2340 for (unsigned I = 0; I != NumInputs; ++I) {
2341 // If requested, drop call arguments that need to be dropped.
2342 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
2343 if (ArgChanged)
2344 *ArgChanged = true;
2345
2346 break;
2347 }
2348
Douglas Gregor968f23a2011-01-03 19:31:53 +00002349 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
2350 Expr *Pattern = Expansion->getPattern();
2351
2352 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
2353 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
2354 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
2355
2356 // Determine whether the set of unexpanded parameter packs can and should
2357 // be expanded.
2358 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002359 bool RetainExpansion = false;
Douglas Gregorb8840002011-01-14 21:20:45 +00002360 llvm::Optional<unsigned> OrigNumExpansions
2361 = Expansion->getNumExpansions();
2362 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00002363 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
2364 Pattern->getSourceRange(),
2365 Unexpanded.data(),
2366 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00002367 Expand, RetainExpansion,
2368 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00002369 return true;
2370
2371 if (!Expand) {
2372 // The transform has determined that we should perform a simple
2373 // transformation on the pack expansion, producing another pack
2374 // expansion.
2375 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
2376 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
2377 if (OutPattern.isInvalid())
2378 return true;
2379
2380 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00002381 Expansion->getEllipsisLoc(),
2382 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002383 if (Out.isInvalid())
2384 return true;
2385
2386 if (ArgChanged)
2387 *ArgChanged = true;
2388 Outputs.push_back(Out.get());
2389 continue;
2390 }
2391
2392 // The transform has determined that we should perform an elementwise
2393 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002394 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00002395 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
2396 ExprResult Out = getDerived().TransformExpr(Pattern);
2397 if (Out.isInvalid())
2398 return true;
2399
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002400 if (Out.get()->containsUnexpandedParameterPack()) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002401 Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(),
2402 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00002403 if (Out.isInvalid())
2404 return true;
2405 }
2406
Douglas Gregor968f23a2011-01-03 19:31:53 +00002407 if (ArgChanged)
2408 *ArgChanged = true;
2409 Outputs.push_back(Out.get());
2410 }
2411
2412 continue;
2413 }
2414
Douglas Gregora3efea12011-01-03 19:04:46 +00002415 ExprResult Result = getDerived().TransformExpr(Inputs[I]);
2416 if (Result.isInvalid())
2417 return true;
2418
2419 if (Result.get() != Inputs[I] && ArgChanged)
2420 *ArgChanged = true;
2421
2422 Outputs.push_back(Result.get());
2423 }
2424
2425 return false;
2426}
2427
2428template<typename Derived>
Douglas Gregor1135c352009-08-06 05:28:30 +00002429NestedNameSpecifier *
2430TreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002431 SourceRange Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002432 QualType ObjectType,
2433 NamedDecl *FirstQualifierInScope) {
John McCall31f82722010-11-12 08:19:04 +00002434 NestedNameSpecifier *Prefix = NNS->getPrefix();
Mike Stump11289f42009-09-09 15:08:12 +00002435
Douglas Gregorebe10102009-08-20 07:17:43 +00002436 // Transform the prefix of this nested name specifier.
Douglas Gregor1135c352009-08-06 05:28:30 +00002437 if (Prefix) {
Mike Stump11289f42009-09-09 15:08:12 +00002438 Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002439 ObjectType,
2440 FirstQualifierInScope);
Douglas Gregor1135c352009-08-06 05:28:30 +00002441 if (!Prefix)
2442 return 0;
2443 }
Mike Stump11289f42009-09-09 15:08:12 +00002444
Douglas Gregor1135c352009-08-06 05:28:30 +00002445 switch (NNS->getKind()) {
2446 case NestedNameSpecifier::Identifier:
John McCall31f82722010-11-12 08:19:04 +00002447 if (Prefix) {
2448 // The object type and qualifier-in-scope really apply to the
2449 // leftmost entity.
2450 ObjectType = QualType();
2451 FirstQualifierInScope = 0;
2452 }
2453
Mike Stump11289f42009-09-09 15:08:12 +00002454 assert((Prefix || !ObjectType.isNull()) &&
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002455 "Identifier nested-name-specifier with no prefix or object type");
2456 if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() &&
2457 ObjectType.isNull())
Douglas Gregor1135c352009-08-06 05:28:30 +00002458 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002459
2460 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00002461 *NNS->getAsIdentifier(),
Douglas Gregor2b6ca462009-09-03 21:38:09 +00002462 ObjectType,
2463 FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00002464
Douglas Gregor1135c352009-08-06 05:28:30 +00002465 case NestedNameSpecifier::Namespace: {
Mike Stump11289f42009-09-09 15:08:12 +00002466 NamespaceDecl *NS
Douglas Gregor1135c352009-08-06 05:28:30 +00002467 = cast_or_null<NamespaceDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002468 getDerived().TransformDecl(Range.getBegin(),
2469 NNS->getAsNamespace()));
Mike Stump11289f42009-09-09 15:08:12 +00002470 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor1135c352009-08-06 05:28:30 +00002471 Prefix == NNS->getPrefix() &&
2472 NS == NNS->getAsNamespace())
2473 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002474
Douglas Gregor1135c352009-08-06 05:28:30 +00002475 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS);
2476 }
Mike Stump11289f42009-09-09 15:08:12 +00002477
Douglas Gregor7b26ff92011-02-24 02:36:08 +00002478 case NestedNameSpecifier::NamespaceAlias: {
2479 NamespaceAliasDecl *Alias
2480 = cast_or_null<NamespaceAliasDecl>(
2481 getDerived().TransformDecl(Range.getBegin(),
2482 NNS->getAsNamespaceAlias()));
2483 if (!getDerived().AlwaysRebuild() &&
2484 Prefix == NNS->getPrefix() &&
2485 Alias == NNS->getAsNamespaceAlias())
2486 return NNS;
2487
2488 return getDerived().RebuildNestedNameSpecifier(Prefix, Range, Alias);
2489 }
2490
Douglas Gregor1135c352009-08-06 05:28:30 +00002491 case NestedNameSpecifier::Global:
2492 // There is no meaningful transformation that one could perform on the
2493 // global scope.
2494 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002495
Douglas Gregor1135c352009-08-06 05:28:30 +00002496 case NestedNameSpecifier::TypeSpecWithTemplate:
2497 case NestedNameSpecifier::TypeSpec: {
Douglas Gregor07cc4ac2009-10-29 22:21:39 +00002498 TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName());
John McCall31f82722010-11-12 08:19:04 +00002499 QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0),
2500 ObjectType,
2501 FirstQualifierInScope,
2502 Prefix);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002503 if (T.isNull())
2504 return 0;
Mike Stump11289f42009-09-09 15:08:12 +00002505
Douglas Gregor1135c352009-08-06 05:28:30 +00002506 if (!getDerived().AlwaysRebuild() &&
2507 Prefix == NNS->getPrefix() &&
2508 T == QualType(NNS->getAsType(), 0))
2509 return NNS;
Mike Stump11289f42009-09-09 15:08:12 +00002510
2511 return getDerived().RebuildNestedNameSpecifier(Prefix, Range,
2512 NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00002513 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00002514 }
2515 }
Mike Stump11289f42009-09-09 15:08:12 +00002516
Douglas Gregor1135c352009-08-06 05:28:30 +00002517 // Required to silence a GCC warning
Mike Stump11289f42009-09-09 15:08:12 +00002518 return 0;
Douglas Gregor1135c352009-08-06 05:28:30 +00002519}
2520
2521template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00002522NestedNameSpecifierLoc
2523TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
2524 NestedNameSpecifierLoc NNS,
2525 QualType ObjectType,
2526 NamedDecl *FirstQualifierInScope) {
2527 llvm::SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
2528 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
2529 Qualifier = Qualifier.getPrefix())
2530 Qualifiers.push_back(Qualifier);
2531
2532 CXXScopeSpec SS;
2533 while (!Qualifiers.empty()) {
2534 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
2535 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
2536
2537 switch (QNNS->getKind()) {
2538 case NestedNameSpecifier::Identifier:
2539 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0,
2540 *QNNS->getAsIdentifier(),
2541 Q.getLocalBeginLoc(),
2542 Q.getLocalEndLoc(),
2543 ObjectType, false, SS,
2544 FirstQualifierInScope, false))
2545 return NestedNameSpecifierLoc();
2546
2547 break;
2548
2549 case NestedNameSpecifier::Namespace: {
2550 NamespaceDecl *NS
2551 = cast_or_null<NamespaceDecl>(
2552 getDerived().TransformDecl(
2553 Q.getLocalBeginLoc(),
2554 QNNS->getAsNamespace()));
2555 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
2556 break;
2557 }
2558
2559 case NestedNameSpecifier::NamespaceAlias: {
2560 NamespaceAliasDecl *Alias
2561 = cast_or_null<NamespaceAliasDecl>(
2562 getDerived().TransformDecl(Q.getLocalBeginLoc(),
2563 QNNS->getAsNamespaceAlias()));
2564 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
2565 Q.getLocalEndLoc());
2566 break;
2567 }
2568
2569 case NestedNameSpecifier::Global:
2570 // There is no meaningful transformation that one could perform on the
2571 // global scope.
2572 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
2573 break;
2574
2575 case NestedNameSpecifier::TypeSpecWithTemplate:
2576 case NestedNameSpecifier::TypeSpec: {
2577 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
2578 FirstQualifierInScope, SS);
2579
2580 if (!TL)
2581 return NestedNameSpecifierLoc();
2582
2583 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
2584 (SemaRef.getLangOptions().CPlusPlus0x &&
2585 TL.getType()->isEnumeralType())) {
2586 assert(!TL.getType().hasLocalQualifiers() &&
2587 "Can't get cv-qualifiers here");
2588 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
2589 Q.getLocalEndLoc());
2590 break;
2591 }
2592
2593 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
2594 << TL.getType() << SS.getRange();
2595 return NestedNameSpecifierLoc();
2596 }
2597 }
2598
Douglas Gregora6ce6082011-02-25 18:19:59 +00002599 // The qualifier-in-scope only applies to the leftmost entity.
Douglas Gregor14454802011-02-25 02:25:35 +00002600 FirstQualifierInScope = 0;
2601 }
2602
2603 // Don't rebuild the nested-name-specifier if we don't have to.
2604 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
2605 !getDerived().AlwaysRebuild())
2606 return NNS;
2607
2608 // If we can re-use the source-location data from the original
2609 // nested-name-specifier, do so.
2610 if (SS.location_size() == NNS.getDataLength() &&
2611 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
2612 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
2613
2614 // Allocate new nested-name-specifier location information.
2615 return SS.getWithLocInContext(SemaRef.Context);
2616}
2617
2618template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002619DeclarationNameInfo
2620TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00002621::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002622 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002623 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002624 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002625
2626 switch (Name.getNameKind()) {
2627 case DeclarationName::Identifier:
2628 case DeclarationName::ObjCZeroArgSelector:
2629 case DeclarationName::ObjCOneArgSelector:
2630 case DeclarationName::ObjCMultiArgSelector:
2631 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00002632 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00002633 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002634 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00002635
Douglas Gregorf816bd72009-09-03 22:13:48 +00002636 case DeclarationName::CXXConstructorName:
2637 case DeclarationName::CXXDestructorName:
2638 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002639 TypeSourceInfo *NewTInfo;
2640 CanQualType NewCanTy;
2641 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00002642 NewTInfo = getDerived().TransformType(OldTInfo);
2643 if (!NewTInfo)
2644 return DeclarationNameInfo();
2645 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002646 }
2647 else {
2648 NewTInfo = 0;
2649 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00002650 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002651 if (NewT.isNull())
2652 return DeclarationNameInfo();
2653 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
2654 }
Mike Stump11289f42009-09-09 15:08:12 +00002655
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002656 DeclarationName NewName
2657 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
2658 NewCanTy);
2659 DeclarationNameInfo NewNameInfo(NameInfo);
2660 NewNameInfo.setName(NewName);
2661 NewNameInfo.setNamedTypeInfo(NewTInfo);
2662 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00002663 }
Mike Stump11289f42009-09-09 15:08:12 +00002664 }
2665
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002666 assert(0 && "Unknown name kind.");
2667 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00002668}
2669
2670template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00002671TemplateName
Douglas Gregor308047d2009-09-09 00:23:06 +00002672TreeTransform<Derived>::TransformTemplateName(TemplateName Name,
John McCall31f82722010-11-12 08:19:04 +00002673 QualType ObjectType,
2674 NamedDecl *FirstQualifierInScope) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002675 SourceLocation Loc = getDerived().getBaseLocation();
2676
Douglas Gregor71dc5092009-08-06 06:41:21 +00002677 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
Mike Stump11289f42009-09-09 15:08:12 +00002678 NestedNameSpecifier *NNS
Douglas Gregor71dc5092009-08-06 06:41:21 +00002679 = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00002680 /*FIXME*/ SourceRange(Loc),
2681 ObjectType,
2682 FirstQualifierInScope);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002683 if (!NNS)
2684 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002685
Douglas Gregor71dc5092009-08-06 06:41:21 +00002686 if (TemplateDecl *Template = QTN->getTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002687 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002688 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002689 if (!TransTemplate)
2690 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002691
Douglas Gregor71dc5092009-08-06 06:41:21 +00002692 if (!getDerived().AlwaysRebuild() &&
2693 NNS == QTN->getQualifier() &&
2694 TransTemplate == Template)
2695 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002696
Douglas Gregor71dc5092009-08-06 06:41:21 +00002697 return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(),
2698 TransTemplate);
2699 }
Mike Stump11289f42009-09-09 15:08:12 +00002700
John McCalle66edc12009-11-24 19:00:30 +00002701 // These should be getting filtered out before they make it into the AST.
John McCall31f82722010-11-12 08:19:04 +00002702 llvm_unreachable("overloaded template name survived to here");
Douglas Gregor71dc5092009-08-06 06:41:21 +00002703 }
Mike Stump11289f42009-09-09 15:08:12 +00002704
Douglas Gregor71dc5092009-08-06 06:41:21 +00002705 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
John McCall31f82722010-11-12 08:19:04 +00002706 NestedNameSpecifier *NNS = DTN->getQualifier();
2707 if (NNS) {
2708 NNS = getDerived().TransformNestedNameSpecifier(NNS,
2709 /*FIXME:*/SourceRange(Loc),
2710 ObjectType,
2711 FirstQualifierInScope);
2712 if (!NNS) return TemplateName();
2713
2714 // These apply to the scope specifier, not the template.
2715 ObjectType = QualType();
2716 FirstQualifierInScope = 0;
2717 }
Mike Stump11289f42009-09-09 15:08:12 +00002718
Douglas Gregor71dc5092009-08-06 06:41:21 +00002719 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorc59e5612009-10-19 22:04:39 +00002720 NNS == DTN->getQualifier() &&
2721 ObjectType.isNull())
Douglas Gregor71dc5092009-08-06 06:41:21 +00002722 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002723
Douglas Gregora5614c52010-09-08 23:56:00 +00002724 if (DTN->isIdentifier()) {
2725 // FIXME: Bad range
2726 SourceRange QualifierRange(getDerived().getBaseLocation());
2727 return getDerived().RebuildTemplateName(NNS, QualifierRange,
2728 *DTN->getIdentifier(),
John McCall31f82722010-11-12 08:19:04 +00002729 ObjectType,
2730 FirstQualifierInScope);
Douglas Gregora5614c52010-09-08 23:56:00 +00002731 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00002732
2733 return getDerived().RebuildTemplateName(NNS, DTN->getOperator(),
Douglas Gregor71395fa2009-11-04 00:56:37 +00002734 ObjectType);
Douglas Gregor71dc5092009-08-06 06:41:21 +00002735 }
Mike Stump11289f42009-09-09 15:08:12 +00002736
Douglas Gregor71dc5092009-08-06 06:41:21 +00002737 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
Mike Stump11289f42009-09-09 15:08:12 +00002738 TemplateDecl *TransTemplate
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002739 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template));
Douglas Gregor71dc5092009-08-06 06:41:21 +00002740 if (!TransTemplate)
2741 return TemplateName();
Mike Stump11289f42009-09-09 15:08:12 +00002742
Douglas Gregor71dc5092009-08-06 06:41:21 +00002743 if (!getDerived().AlwaysRebuild() &&
2744 TransTemplate == Template)
2745 return Name;
Mike Stump11289f42009-09-09 15:08:12 +00002746
Douglas Gregor71dc5092009-08-06 06:41:21 +00002747 return TemplateName(TransTemplate);
2748 }
Mike Stump11289f42009-09-09 15:08:12 +00002749
Douglas Gregor5590be02011-01-15 06:45:20 +00002750 if (SubstTemplateTemplateParmPackStorage *SubstPack
2751 = Name.getAsSubstTemplateTemplateParmPack()) {
2752 TemplateTemplateParmDecl *TransParam
2753 = cast_or_null<TemplateTemplateParmDecl>(
2754 getDerived().TransformDecl(Loc, 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
John McCalle66edc12009-11-24 19:00:30 +00002766 // These should be getting filtered out before they reach the AST.
John McCall31f82722010-11-12 08:19:04 +00002767 llvm_unreachable("overloaded function decl survived to here");
John McCalle66edc12009-11-24 19:00:30 +00002768 return TemplateName();
Douglas Gregor71dc5092009-08-06 06:41:21 +00002769}
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:
2788 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc);
2789 break;
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002790
2791 case TemplateArgument::TemplateExpansion:
2792 Output = TemplateArgumentLoc(Arg, SourceRange(), Loc, Loc);
2793 break;
2794
John McCall0ad16662009-10-29 08:12:44 +00002795 case TemplateArgument::Expression:
2796 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
2797 break;
2798
2799 case TemplateArgument::Declaration:
2800 case TemplateArgument::Integral:
2801 case TemplateArgument::Pack:
John McCall0d07eb32009-10-29 18:45:58 +00002802 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002803 break;
2804 }
2805}
2806
2807template<typename Derived>
2808bool TreeTransform<Derived>::TransformTemplateArgument(
2809 const TemplateArgumentLoc &Input,
2810 TemplateArgumentLoc &Output) {
2811 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00002812 switch (Arg.getKind()) {
2813 case TemplateArgument::Null:
2814 case TemplateArgument::Integral:
John McCall0ad16662009-10-29 08:12:44 +00002815 Output = Input;
2816 return false;
Mike Stump11289f42009-09-09 15:08:12 +00002817
Douglas Gregore922c772009-08-04 22:27:00 +00002818 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00002819 TypeSourceInfo *DI = Input.getTypeSourceInfo();
John McCall0ad16662009-10-29 08:12:44 +00002820 if (DI == NULL)
John McCallbcd03502009-12-07 02:54:59 +00002821 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00002822
2823 DI = getDerived().TransformType(DI);
2824 if (!DI) return true;
2825
2826 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
2827 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002828 }
Mike Stump11289f42009-09-09 15:08:12 +00002829
Douglas Gregore922c772009-08-04 22:27:00 +00002830 case TemplateArgument::Declaration: {
John McCall0ad16662009-10-29 08:12:44 +00002831 // FIXME: we should never have to transform one of these.
Douglas Gregoref6ab412009-10-27 06:26:26 +00002832 DeclarationName Name;
2833 if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl()))
2834 Name = ND->getDeclName();
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002835 TemporaryBase Rebase(*this, Input.getLocation(), Name);
Douglas Gregora04f2ca2010-03-01 15:56:25 +00002836 Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl());
John McCall0ad16662009-10-29 08:12:44 +00002837 if (!D) return true;
2838
John McCall0d07eb32009-10-29 18:45:58 +00002839 Expr *SourceExpr = Input.getSourceDeclExpression();
2840 if (SourceExpr) {
2841 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002842 Sema::Unevaluated);
John McCalldadc5752010-08-24 06:29:42 +00002843 ExprResult E = getDerived().TransformExpr(SourceExpr);
John McCallb268a282010-08-23 23:25:46 +00002844 SourceExpr = (E.isInvalid() ? 0 : E.take());
John McCall0d07eb32009-10-29 18:45:58 +00002845 }
2846
2847 Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr);
John McCall0ad16662009-10-29 08:12:44 +00002848 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002849 }
Mike Stump11289f42009-09-09 15:08:12 +00002850
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002851 case TemplateArgument::Template: {
Alexis Hunta8136cc2010-05-05 15:23:54 +00002852 TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002853 TemplateName Template
2854 = getDerived().TransformTemplateName(Arg.getAsTemplate());
2855 if (Template.isNull())
2856 return true;
Alexis Hunta8136cc2010-05-05 15:23:54 +00002857
Douglas Gregor9167f8b2009-11-11 01:00:40 +00002858 Output = TemplateArgumentLoc(TemplateArgument(Template),
2859 Input.getTemplateQualifierRange(),
2860 Input.getTemplateNameLoc());
2861 return false;
2862 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002863
2864 case TemplateArgument::TemplateExpansion:
2865 llvm_unreachable("Caller should expand pack expansions");
2866
Douglas Gregore922c772009-08-04 22:27:00 +00002867 case TemplateArgument::Expression: {
2868 // Template argument expressions are not potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00002869 EnterExpressionEvaluationContext Unevaluated(getSema(),
John McCallfaf5fb42010-08-26 23:41:50 +00002870 Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00002871
John McCall0ad16662009-10-29 08:12:44 +00002872 Expr *InputExpr = Input.getSourceExpression();
2873 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
2874
John McCalldadc5752010-08-24 06:29:42 +00002875 ExprResult E
John McCall0ad16662009-10-29 08:12:44 +00002876 = getDerived().TransformExpr(InputExpr);
2877 if (E.isInvalid()) return true;
John McCallb268a282010-08-23 23:25:46 +00002878 Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take());
John McCall0ad16662009-10-29 08:12:44 +00002879 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002880 }
Mike Stump11289f42009-09-09 15:08:12 +00002881
Douglas Gregore922c772009-08-04 22:27:00 +00002882 case TemplateArgument::Pack: {
2883 llvm::SmallVector<TemplateArgument, 4> TransformedArgs;
2884 TransformedArgs.reserve(Arg.pack_size());
Mike Stump11289f42009-09-09 15:08:12 +00002885 for (TemplateArgument::pack_iterator A = Arg.pack_begin(),
Douglas Gregore922c772009-08-04 22:27:00 +00002886 AEnd = Arg.pack_end();
2887 A != AEnd; ++A) {
Mike Stump11289f42009-09-09 15:08:12 +00002888
John McCall0ad16662009-10-29 08:12:44 +00002889 // FIXME: preserve source information here when we start
2890 // caring about parameter packs.
2891
John McCall0d07eb32009-10-29 18:45:58 +00002892 TemplateArgumentLoc InputArg;
2893 TemplateArgumentLoc OutputArg;
2894 getDerived().InventTemplateArgumentLoc(*A, InputArg);
2895 if (getDerived().TransformTemplateArgument(InputArg, OutputArg))
John McCall0ad16662009-10-29 08:12:44 +00002896 return true;
2897
John McCall0d07eb32009-10-29 18:45:58 +00002898 TransformedArgs.push_back(OutputArg.getArgument());
Douglas Gregore922c772009-08-04 22:27:00 +00002899 }
Douglas Gregor1ccc8412010-11-07 23:05:16 +00002900
2901 TemplateArgument *TransformedArgsPtr
2902 = new (getSema().Context) TemplateArgument[TransformedArgs.size()];
2903 std::copy(TransformedArgs.begin(), TransformedArgs.end(),
2904 TransformedArgsPtr);
2905 Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr,
2906 TransformedArgs.size()),
2907 Input.getLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00002908 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00002909 }
2910 }
Mike Stump11289f42009-09-09 15:08:12 +00002911
Douglas Gregore922c772009-08-04 22:27:00 +00002912 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00002913 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00002914}
2915
Douglas Gregorfe921a72010-12-20 23:36:19 +00002916/// \brief Iterator adaptor that invents template argument location information
2917/// for each of the template arguments in its underlying iterator.
2918template<typename Derived, typename InputIterator>
2919class TemplateArgumentLocInventIterator {
2920 TreeTransform<Derived> &Self;
2921 InputIterator Iter;
2922
2923public:
2924 typedef TemplateArgumentLoc value_type;
2925 typedef TemplateArgumentLoc reference;
2926 typedef typename std::iterator_traits<InputIterator>::difference_type
2927 difference_type;
2928 typedef std::input_iterator_tag iterator_category;
2929
2930 class pointer {
2931 TemplateArgumentLoc Arg;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002932
Douglas Gregorfe921a72010-12-20 23:36:19 +00002933 public:
2934 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
2935
2936 const TemplateArgumentLoc *operator->() const { return &Arg; }
2937 };
2938
2939 TemplateArgumentLocInventIterator() { }
2940
2941 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
2942 InputIterator Iter)
2943 : Self(Self), Iter(Iter) { }
2944
2945 TemplateArgumentLocInventIterator &operator++() {
2946 ++Iter;
2947 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00002948 }
2949
Douglas Gregorfe921a72010-12-20 23:36:19 +00002950 TemplateArgumentLocInventIterator operator++(int) {
2951 TemplateArgumentLocInventIterator Old(*this);
2952 ++(*this);
2953 return Old;
2954 }
2955
2956 reference operator*() const {
2957 TemplateArgumentLoc Result;
2958 Self.InventTemplateArgumentLoc(*Iter, Result);
2959 return Result;
2960 }
2961
2962 pointer operator->() const { return pointer(**this); }
2963
2964 friend bool operator==(const TemplateArgumentLocInventIterator &X,
2965 const TemplateArgumentLocInventIterator &Y) {
2966 return X.Iter == Y.Iter;
2967 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00002968
Douglas Gregorfe921a72010-12-20 23:36:19 +00002969 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
2970 const TemplateArgumentLocInventIterator &Y) {
2971 return X.Iter != Y.Iter;
2972 }
2973};
2974
Douglas Gregor42cafa82010-12-20 17:42:22 +00002975template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00002976template<typename InputIterator>
2977bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
2978 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00002979 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00002980 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00002981 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00002982 TemplateArgumentLoc In = *First;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002983
2984 if (In.getArgument().getKind() == TemplateArgument::Pack) {
2985 // Unpack argument packs, which we translate them into separate
2986 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00002987 // FIXME: We could do much better if we could guarantee that the
2988 // TemplateArgumentLocInfo for the pack expansion would be usable for
2989 // all of the template arguments in the argument pack.
2990 typedef TemplateArgumentLocInventIterator<Derived,
2991 TemplateArgument::pack_iterator>
2992 PackLocIterator;
2993 if (TransformTemplateArguments(PackLocIterator(*this,
2994 In.getArgument().pack_begin()),
2995 PackLocIterator(*this,
2996 In.getArgument().pack_end()),
2997 Outputs))
2998 return true;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002999
3000 continue;
3001 }
3002
3003 if (In.getArgument().isPackExpansion()) {
3004 // We have a pack expansion, for which we will be substituting into
3005 // the pattern.
3006 SourceLocation Ellipsis;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003007 llvm::Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003008 TemplateArgumentLoc Pattern
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003009 = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions,
3010 getSema().Context);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003011
3012 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3013 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3014 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
3015
3016 // Determine whether the set of unexpanded parameter packs can and should
3017 // be expanded.
3018 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003019 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003020 llvm::Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003021 if (getDerived().TryExpandParameterPacks(Ellipsis,
3022 Pattern.getSourceRange(),
3023 Unexpanded.data(),
3024 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003025 Expand,
3026 RetainExpansion,
3027 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003028 return true;
3029
3030 if (!Expand) {
3031 // The transform has determined that we should perform a simple
3032 // transformation on the pack expansion, producing another pack
3033 // expansion.
3034 TemplateArgumentLoc OutPattern;
3035 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3036 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3037 return true;
3038
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003039 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3040 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003041 if (Out.getArgument().isNull())
3042 return true;
3043
3044 Outputs.addArgument(Out);
3045 continue;
3046 }
3047
3048 // The transform has determined that we should perform an elementwise
3049 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003050 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003051 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3052
3053 if (getDerived().TransformTemplateArgument(Pattern, Out))
3054 return true;
3055
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003056 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003057 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3058 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003059 if (Out.getArgument().isNull())
3060 return true;
3061 }
3062
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003063 Outputs.addArgument(Out);
3064 }
3065
Douglas Gregor48d24112011-01-10 20:53:55 +00003066 // If we're supposed to retain a pack expansion, do so by temporarily
3067 // forgetting the partially-substituted parameter pack.
3068 if (RetainExpansion) {
3069 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3070
3071 if (getDerived().TransformTemplateArgument(Pattern, Out))
3072 return true;
3073
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003074 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3075 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003076 if (Out.getArgument().isNull())
3077 return true;
3078
3079 Outputs.addArgument(Out);
3080 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003081
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003082 continue;
3083 }
3084
3085 // The simple case:
3086 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003087 return true;
3088
3089 Outputs.addArgument(Out);
3090 }
3091
3092 return false;
3093
3094}
3095
Douglas Gregord6ff3322009-08-04 16:50:30 +00003096//===----------------------------------------------------------------------===//
3097// Type transformation
3098//===----------------------------------------------------------------------===//
3099
3100template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003101QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003102 if (getDerived().AlreadyTransformed(T))
3103 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003104
John McCall550e0c22009-10-21 00:40:46 +00003105 // Temporary workaround. All of these transformations should
3106 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003107 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3108 getDerived().getBaseLocation());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003109
John McCall31f82722010-11-12 08:19:04 +00003110 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003111
John McCall550e0c22009-10-21 00:40:46 +00003112 if (!NewDI)
3113 return QualType();
3114
3115 return NewDI->getType();
3116}
3117
3118template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003119TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
John McCall550e0c22009-10-21 00:40:46 +00003120 if (getDerived().AlreadyTransformed(DI->getType()))
3121 return DI;
3122
3123 TypeLocBuilder TLB;
3124
3125 TypeLoc TL = DI->getTypeLoc();
3126 TLB.reserve(TL.getFullDataSize());
3127
John McCall31f82722010-11-12 08:19:04 +00003128 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003129 if (Result.isNull())
3130 return 0;
3131
John McCallbcd03502009-12-07 02:54:59 +00003132 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003133}
3134
3135template<typename Derived>
3136QualType
John McCall31f82722010-11-12 08:19:04 +00003137TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003138 switch (T.getTypeLocClass()) {
3139#define ABSTRACT_TYPELOC(CLASS, PARENT)
3140#define TYPELOC(CLASS, PARENT) \
3141 case TypeLoc::CLASS: \
John McCall31f82722010-11-12 08:19:04 +00003142 return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T));
John McCall550e0c22009-10-21 00:40:46 +00003143#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003144 }
Mike Stump11289f42009-09-09 15:08:12 +00003145
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003146 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003147 return QualType();
3148}
3149
3150/// FIXME: By default, this routine adds type qualifiers only to types
3151/// that can have qualifiers, and silently suppresses those qualifiers
3152/// that are not permitted (e.g., qualifiers on reference or function
3153/// types). This is the right thing for template instantiation, but
3154/// probably not for other clients.
3155template<typename Derived>
3156QualType
3157TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003158 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003159 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003160
John McCall31f82722010-11-12 08:19:04 +00003161 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003162 if (Result.isNull())
3163 return QualType();
3164
3165 // Silently suppress qualifiers if the result type can't be qualified.
3166 // FIXME: this is the right thing for template instantiation, but
3167 // probably not for other clients.
3168 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003169 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003170
John McCallcb0f89a2010-06-05 06:41:15 +00003171 if (!Quals.empty()) {
3172 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
3173 TLB.push<QualifiedTypeLoc>(Result);
3174 // No location information to preserve.
3175 }
John McCall550e0c22009-10-21 00:40:46 +00003176
3177 return Result;
3178}
3179
John McCall31f82722010-11-12 08:19:04 +00003180/// \brief Transforms a type that was written in a scope specifier,
3181/// given an object type, the results of unqualified lookup, and
3182/// an already-instantiated prefix.
3183///
3184/// The object type is provided iff the scope specifier qualifies the
3185/// member of a dependent member-access expression. The prefix is
3186/// provided iff the the scope specifier in which this appears has a
3187/// prefix.
3188///
3189/// This is private to TreeTransform.
3190template<typename Derived>
3191QualType
3192TreeTransform<Derived>::TransformTypeInObjectScope(QualType T,
3193 QualType ObjectType,
3194 NamedDecl *UnqualLookup,
3195 NestedNameSpecifier *Prefix) {
3196 if (getDerived().AlreadyTransformed(T))
3197 return T;
3198
3199 TypeSourceInfo *TSI =
Douglas Gregor2d525f02011-01-25 19:13:18 +00003200 SemaRef.Context.getTrivialTypeSourceInfo(T, getDerived().getBaseLocation());
John McCall31f82722010-11-12 08:19:04 +00003201
3202 TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType,
3203 UnqualLookup, Prefix);
3204 if (!TSI) return QualType();
3205 return TSI->getType();
3206}
3207
3208template<typename Derived>
3209TypeSourceInfo *
3210TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI,
3211 QualType ObjectType,
3212 NamedDecl *UnqualLookup,
3213 NestedNameSpecifier *Prefix) {
Douglas Gregor14454802011-02-25 02:25:35 +00003214 // TODO: in some cases, we might have some verification to do here.
John McCall31f82722010-11-12 08:19:04 +00003215 if (ObjectType.isNull())
3216 return getDerived().TransformType(TSI);
3217
3218 QualType T = TSI->getType();
3219 if (getDerived().AlreadyTransformed(T))
3220 return TSI;
3221
3222 TypeLocBuilder TLB;
3223 QualType Result;
3224
3225 if (isa<TemplateSpecializationType>(T)) {
3226 TemplateSpecializationTypeLoc TL
3227 = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3228
3229 TemplateName Template =
3230 getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(),
3231 ObjectType, UnqualLookup);
3232 if (Template.isNull()) return 0;
3233
3234 Result = getDerived()
3235 .TransformTemplateSpecializationType(TLB, TL, Template);
3236 } else if (isa<DependentTemplateSpecializationType>(T)) {
3237 DependentTemplateSpecializationTypeLoc TL
3238 = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc());
3239
3240 Result = getDerived()
3241 .TransformDependentTemplateSpecializationType(TLB, TL, Prefix);
3242 } else {
3243 // Nothing special needs to be done for these.
3244 Result = getDerived().TransformType(TLB, TSI->getTypeLoc());
3245 }
3246
3247 if (Result.isNull()) return 0;
3248 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3249}
3250
Douglas Gregor14454802011-02-25 02:25:35 +00003251template<typename Derived>
3252TypeLoc
3253TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3254 QualType ObjectType,
3255 NamedDecl *UnqualLookup,
3256 CXXScopeSpec &SS) {
3257 // FIXME: Painfully copy-paste from the above!
3258
3259 // TODO: in some cases, we might have some verification to do here.
3260 if (ObjectType.isNull()) {
3261 TypeLocBuilder TLB;
3262 TLB.reserve(TL.getFullDataSize());
3263 QualType Result = getDerived().TransformType(TLB, TL);
3264 if (Result.isNull())
3265 return TypeLoc();
3266
3267 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3268 }
3269
3270 QualType T = TL.getType();
3271 if (getDerived().AlreadyTransformed(T))
3272 return TL;
3273
3274 TypeLocBuilder TLB;
3275 QualType Result;
3276
3277 if (isa<TemplateSpecializationType>(T)) {
3278 TemplateSpecializationTypeLoc SpecTL
3279 = cast<TemplateSpecializationTypeLoc>(TL);
3280
3281 TemplateName Template =
3282 getDerived().TransformTemplateName(SpecTL.getTypePtr()->getTemplateName(),
3283 ObjectType, UnqualLookup);
3284 if (Template.isNull())
3285 return TypeLoc();
3286
3287 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
3288 Template);
3289 } else if (isa<DependentTemplateSpecializationType>(T)) {
3290 DependentTemplateSpecializationTypeLoc SpecTL
3291 = cast<DependentTemplateSpecializationTypeLoc>(TL);
3292
3293 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
3294 SpecTL,
3295 SS.getScopeRep());
3296 } else {
3297 // Nothing special needs to be done for these.
3298 Result = getDerived().TransformType(TLB, TL);
3299 }
3300
3301 if (Result.isNull())
3302 return TypeLoc();
3303
3304 return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc();
3305}
3306
John McCall550e0c22009-10-21 00:40:46 +00003307template <class TyLoc> static inline
3308QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3309 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3310 NewT.setNameLoc(T.getNameLoc());
3311 return T.getType();
3312}
3313
John McCall550e0c22009-10-21 00:40:46 +00003314template<typename Derived>
3315QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003316 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003317 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3318 NewT.setBuiltinLoc(T.getBuiltinLoc());
3319 if (T.needsExtraLocalData())
3320 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3321 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003322}
Mike Stump11289f42009-09-09 15:08:12 +00003323
Douglas Gregord6ff3322009-08-04 16:50:30 +00003324template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003325QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003326 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003327 // FIXME: recurse?
3328 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003329}
Mike Stump11289f42009-09-09 15:08:12 +00003330
Douglas Gregord6ff3322009-08-04 16:50:30 +00003331template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003332QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003333 PointerTypeLoc TL) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00003334 QualType PointeeType
3335 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003336 if (PointeeType.isNull())
3337 return QualType();
3338
3339 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00003340 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003341 // A dependent pointer type 'T *' has is being transformed such
3342 // that an Objective-C class type is being replaced for 'T'. The
3343 // resulting pointer type is an ObjCObjectPointerType, not a
3344 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00003345 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Alexis Hunta8136cc2010-05-05 15:23:54 +00003346
John McCall8b07ec22010-05-15 11:32:37 +00003347 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
3348 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003349 return Result;
3350 }
John McCall31f82722010-11-12 08:19:04 +00003351
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003352 if (getDerived().AlwaysRebuild() ||
3353 PointeeType != TL.getPointeeLoc().getType()) {
3354 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
3355 if (Result.isNull())
3356 return QualType();
3357 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003358
Douglas Gregorc298ffc2010-04-22 16:44:27 +00003359 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
3360 NewT.setSigilLoc(TL.getSigilLoc());
Alexis Hunta8136cc2010-05-05 15:23:54 +00003361 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003362}
Mike Stump11289f42009-09-09 15:08:12 +00003363
3364template<typename Derived>
3365QualType
John McCall550e0c22009-10-21 00:40:46 +00003366TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003367 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00003368 QualType PointeeType
Alexis Hunta8136cc2010-05-05 15:23:54 +00003369 = getDerived().TransformType(TLB, TL.getPointeeLoc());
3370 if (PointeeType.isNull())
3371 return QualType();
3372
3373 QualType Result = TL.getType();
3374 if (getDerived().AlwaysRebuild() ||
3375 PointeeType != TL.getPointeeLoc().getType()) {
3376 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00003377 TL.getSigilLoc());
3378 if (Result.isNull())
3379 return QualType();
3380 }
3381
Douglas Gregor049211a2010-04-22 16:50:51 +00003382 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00003383 NewT.setSigilLoc(TL.getSigilLoc());
3384 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003385}
3386
John McCall70dd5f62009-10-30 00:06:24 +00003387/// Transforms a reference type. Note that somewhat paradoxically we
3388/// don't care whether the type itself is an l-value type or an r-value
3389/// type; we only care if the type was *written* as an l-value type
3390/// or an r-value type.
3391template<typename Derived>
3392QualType
3393TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003394 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00003395 const ReferenceType *T = TL.getTypePtr();
3396
3397 // Note that this works with the pointee-as-written.
3398 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
3399 if (PointeeType.isNull())
3400 return QualType();
3401
3402 QualType Result = TL.getType();
3403 if (getDerived().AlwaysRebuild() ||
3404 PointeeType != T->getPointeeTypeAsWritten()) {
3405 Result = getDerived().RebuildReferenceType(PointeeType,
3406 T->isSpelledAsLValue(),
3407 TL.getSigilLoc());
3408 if (Result.isNull())
3409 return QualType();
3410 }
3411
3412 // r-value references can be rebuilt as l-value references.
3413 ReferenceTypeLoc NewTL;
3414 if (isa<LValueReferenceType>(Result))
3415 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
3416 else
3417 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
3418 NewTL.setSigilLoc(TL.getSigilLoc());
3419
3420 return Result;
3421}
3422
Mike Stump11289f42009-09-09 15:08:12 +00003423template<typename Derived>
3424QualType
John McCall550e0c22009-10-21 00:40:46 +00003425TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003426 LValueReferenceTypeLoc TL) {
3427 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003428}
3429
Mike Stump11289f42009-09-09 15:08:12 +00003430template<typename Derived>
3431QualType
John McCall550e0c22009-10-21 00:40:46 +00003432TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003433 RValueReferenceTypeLoc TL) {
3434 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003435}
Mike Stump11289f42009-09-09 15:08:12 +00003436
Douglas Gregord6ff3322009-08-04 16:50:30 +00003437template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003438QualType
John McCall550e0c22009-10-21 00:40:46 +00003439TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003440 MemberPointerTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003441 const MemberPointerType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003442
3443 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003444 if (PointeeType.isNull())
3445 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003446
John McCall550e0c22009-10-21 00:40:46 +00003447 // TODO: preserve source information for this.
3448 QualType ClassType
3449 = getDerived().TransformType(QualType(T->getClass(), 0));
Douglas Gregord6ff3322009-08-04 16:50:30 +00003450 if (ClassType.isNull())
3451 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003452
John McCall550e0c22009-10-21 00:40:46 +00003453 QualType Result = TL.getType();
3454 if (getDerived().AlwaysRebuild() ||
3455 PointeeType != T->getPointeeType() ||
3456 ClassType != QualType(T->getClass(), 0)) {
John McCall70dd5f62009-10-30 00:06:24 +00003457 Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType,
3458 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00003459 if (Result.isNull())
3460 return QualType();
3461 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00003462
John McCall550e0c22009-10-21 00:40:46 +00003463 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
3464 NewTL.setSigilLoc(TL.getSigilLoc());
3465
3466 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003467}
3468
Mike Stump11289f42009-09-09 15:08:12 +00003469template<typename Derived>
3470QualType
John McCall550e0c22009-10-21 00:40:46 +00003471TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003472 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003473 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003474 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003475 if (ElementType.isNull())
3476 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003477
John McCall550e0c22009-10-21 00:40:46 +00003478 QualType Result = TL.getType();
3479 if (getDerived().AlwaysRebuild() ||
3480 ElementType != T->getElementType()) {
3481 Result = getDerived().RebuildConstantArrayType(ElementType,
3482 T->getSizeModifier(),
3483 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00003484 T->getIndexTypeCVRQualifiers(),
3485 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003486 if (Result.isNull())
3487 return QualType();
3488 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003489
John McCall550e0c22009-10-21 00:40:46 +00003490 ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result);
3491 NewTL.setLBracketLoc(TL.getLBracketLoc());
3492 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003493
John McCall550e0c22009-10-21 00:40:46 +00003494 Expr *Size = TL.getSizeExpr();
3495 if (Size) {
John McCallfaf5fb42010-08-26 23:41:50 +00003496 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003497 Size = getDerived().TransformExpr(Size).template takeAs<Expr>();
3498 }
3499 NewTL.setSizeExpr(Size);
3500
3501 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003502}
Mike Stump11289f42009-09-09 15:08:12 +00003503
Douglas Gregord6ff3322009-08-04 16:50:30 +00003504template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003505QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00003506 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003507 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003508 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003509 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003510 if (ElementType.isNull())
3511 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003512
John McCall550e0c22009-10-21 00:40:46 +00003513 QualType Result = TL.getType();
3514 if (getDerived().AlwaysRebuild() ||
3515 ElementType != T->getElementType()) {
3516 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00003517 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00003518 T->getIndexTypeCVRQualifiers(),
3519 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003520 if (Result.isNull())
3521 return QualType();
3522 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003523
John McCall550e0c22009-10-21 00:40:46 +00003524 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
3525 NewTL.setLBracketLoc(TL.getLBracketLoc());
3526 NewTL.setRBracketLoc(TL.getRBracketLoc());
3527 NewTL.setSizeExpr(0);
3528
3529 return Result;
3530}
3531
3532template<typename Derived>
3533QualType
3534TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003535 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003536 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003537 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3538 if (ElementType.isNull())
3539 return QualType();
3540
3541 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003542 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003543
John McCalldadc5752010-08-24 06:29:42 +00003544 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00003545 = getDerived().TransformExpr(T->getSizeExpr());
3546 if (SizeResult.isInvalid())
3547 return QualType();
3548
John McCallb268a282010-08-23 23:25:46 +00003549 Expr *Size = SizeResult.take();
John McCall550e0c22009-10-21 00:40:46 +00003550
3551 QualType Result = TL.getType();
3552 if (getDerived().AlwaysRebuild() ||
3553 ElementType != T->getElementType() ||
3554 Size != T->getSizeExpr()) {
3555 Result = getDerived().RebuildVariableArrayType(ElementType,
3556 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00003557 Size,
John McCall550e0c22009-10-21 00:40:46 +00003558 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003559 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003560 if (Result.isNull())
3561 return QualType();
3562 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003563
John McCall550e0c22009-10-21 00:40:46 +00003564 VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result);
3565 NewTL.setLBracketLoc(TL.getLBracketLoc());
3566 NewTL.setRBracketLoc(TL.getRBracketLoc());
3567 NewTL.setSizeExpr(Size);
3568
3569 return Result;
3570}
3571
3572template<typename Derived>
3573QualType
3574TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003575 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003576 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003577 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
3578 if (ElementType.isNull())
3579 return QualType();
3580
3581 // Array bounds are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003582 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
John McCall550e0c22009-10-21 00:40:46 +00003583
John McCall33ddac02011-01-19 10:06:00 +00003584 // Prefer the expression from the TypeLoc; the other may have been uniqued.
3585 Expr *origSize = TL.getSizeExpr();
3586 if (!origSize) origSize = T->getSizeExpr();
3587
3588 ExprResult sizeResult
3589 = getDerived().TransformExpr(origSize);
3590 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00003591 return QualType();
3592
John McCall33ddac02011-01-19 10:06:00 +00003593 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00003594
3595 QualType Result = TL.getType();
3596 if (getDerived().AlwaysRebuild() ||
3597 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00003598 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00003599 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
3600 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00003601 size,
John McCall550e0c22009-10-21 00:40:46 +00003602 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00003603 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00003604 if (Result.isNull())
3605 return QualType();
3606 }
John McCall550e0c22009-10-21 00:40:46 +00003607
3608 // We might have any sort of array type now, but fortunately they
3609 // all have the same location layout.
3610 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
3611 NewTL.setLBracketLoc(TL.getLBracketLoc());
3612 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00003613 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00003614
3615 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003616}
Mike Stump11289f42009-09-09 15:08:12 +00003617
3618template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00003619QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00003620 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003621 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003622 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003623
3624 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00003625 QualType ElementType = getDerived().TransformType(T->getElementType());
3626 if (ElementType.isNull())
3627 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003628
Douglas Gregore922c772009-08-04 22:27:00 +00003629 // Vector sizes are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00003630 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00003631
John McCalldadc5752010-08-24 06:29:42 +00003632 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00003633 if (Size.isInvalid())
3634 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00003635
John McCall550e0c22009-10-21 00:40:46 +00003636 QualType Result = TL.getType();
3637 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00003638 ElementType != T->getElementType() ||
3639 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00003640 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
John McCallb268a282010-08-23 23:25:46 +00003641 Size.take(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00003642 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00003643 if (Result.isNull())
3644 return QualType();
3645 }
John McCall550e0c22009-10-21 00:40:46 +00003646
3647 // Result might be dependent or not.
3648 if (isa<DependentSizedExtVectorType>(Result)) {
3649 DependentSizedExtVectorTypeLoc NewTL
3650 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
3651 NewTL.setNameLoc(TL.getNameLoc());
3652 } else {
3653 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3654 NewTL.setNameLoc(TL.getNameLoc());
3655 }
3656
3657 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003658}
Mike Stump11289f42009-09-09 15:08:12 +00003659
3660template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003661QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003662 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003663 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003664 QualType ElementType = getDerived().TransformType(T->getElementType());
3665 if (ElementType.isNull())
3666 return QualType();
3667
John McCall550e0c22009-10-21 00:40:46 +00003668 QualType Result = TL.getType();
3669 if (getDerived().AlwaysRebuild() ||
3670 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00003671 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00003672 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00003673 if (Result.isNull())
3674 return QualType();
3675 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003676
John McCall550e0c22009-10-21 00:40:46 +00003677 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
3678 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00003679
John McCall550e0c22009-10-21 00:40:46 +00003680 return Result;
3681}
3682
3683template<typename Derived>
3684QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003685 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003686 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00003687 QualType ElementType = getDerived().TransformType(T->getElementType());
3688 if (ElementType.isNull())
3689 return QualType();
3690
3691 QualType Result = TL.getType();
3692 if (getDerived().AlwaysRebuild() ||
3693 ElementType != T->getElementType()) {
3694 Result = getDerived().RebuildExtVectorType(ElementType,
3695 T->getNumElements(),
3696 /*FIXME*/ SourceLocation());
3697 if (Result.isNull())
3698 return QualType();
3699 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00003700
John McCall550e0c22009-10-21 00:40:46 +00003701 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
3702 NewTL.setNameLoc(TL.getNameLoc());
3703
3704 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003705}
Mike Stump11289f42009-09-09 15:08:12 +00003706
3707template<typename Derived>
John McCall58f10c32010-03-11 09:03:00 +00003708ParmVarDecl *
Douglas Gregor715e4612011-01-14 22:40:04 +00003709TreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm,
3710 llvm::Optional<unsigned> NumExpansions) {
John McCall58f10c32010-03-11 09:03:00 +00003711 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Douglas Gregor715e4612011-01-14 22:40:04 +00003712 TypeSourceInfo *NewDI = 0;
3713
3714 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
3715 // If we're substituting into a pack expansion type and we know the
3716 TypeLoc OldTL = OldDI->getTypeLoc();
3717 PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL);
3718
3719 TypeLocBuilder TLB;
3720 TypeLoc NewTL = OldDI->getTypeLoc();
3721 TLB.reserve(NewTL.getFullDataSize());
3722
3723 QualType Result = getDerived().TransformType(TLB,
3724 OldExpansionTL.getPatternLoc());
3725 if (Result.isNull())
3726 return 0;
3727
3728 Result = RebuildPackExpansionType(Result,
3729 OldExpansionTL.getPatternLoc().getSourceRange(),
3730 OldExpansionTL.getEllipsisLoc(),
3731 NumExpansions);
3732 if (Result.isNull())
3733 return 0;
3734
3735 PackExpansionTypeLoc NewExpansionTL
3736 = TLB.push<PackExpansionTypeLoc>(Result);
3737 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
3738 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
3739 } else
3740 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00003741 if (!NewDI)
3742 return 0;
3743
3744 if (NewDI == OldDI)
3745 return OldParm;
3746 else
3747 return ParmVarDecl::Create(SemaRef.Context,
3748 OldParm->getDeclContext(),
3749 OldParm->getLocation(),
3750 OldParm->getIdentifier(),
3751 NewDI->getType(),
3752 NewDI,
3753 OldParm->getStorageClass(),
Douglas Gregorc4df4072010-04-19 22:54:31 +00003754 OldParm->getStorageClassAsWritten(),
John McCall58f10c32010-03-11 09:03:00 +00003755 /* DefArg */ NULL);
3756}
3757
3758template<typename Derived>
3759bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00003760 TransformFunctionTypeParams(SourceLocation Loc,
3761 ParmVarDecl **Params, unsigned NumParams,
3762 const QualType *ParamTypes,
3763 llvm::SmallVectorImpl<QualType> &OutParamTypes,
3764 llvm::SmallVectorImpl<ParmVarDecl*> *PVars) {
3765 for (unsigned i = 0; i != NumParams; ++i) {
3766 if (ParmVarDecl *OldParm = Params[i]) {
Douglas Gregor715e4612011-01-14 22:40:04 +00003767 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003768 if (OldParm->isParameterPack()) {
3769 // We have a function parameter pack that may need to be expanded.
3770 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00003771
Douglas Gregor5499af42011-01-05 23:12:31 +00003772 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003773 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
3774 PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL);
3775 TypeLoc Pattern = ExpansionTL.getPatternLoc();
3776 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregor5499af42011-01-05 23:12:31 +00003777
3778 // Determine whether we should expand the parameter packs.
3779 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003780 bool RetainExpansion = false;
Douglas Gregor715e4612011-01-14 22:40:04 +00003781 llvm::Optional<unsigned> OrigNumExpansions
3782 = ExpansionTL.getTypePtr()->getNumExpansions();
3783 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00003784 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
3785 Pattern.getSourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003786 Unexpanded.data(),
3787 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003788 ShouldExpand,
3789 RetainExpansion,
3790 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003791 return true;
3792 }
3793
3794 if (ShouldExpand) {
3795 // Expand the function parameter pack into multiple, separate
3796 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00003797 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003798 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003799 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3800 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003801 = getDerived().TransformFunctionTypeParam(OldParm,
3802 OrigNumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003803 if (!NewParm)
3804 return true;
3805
Douglas Gregordd472162011-01-07 00:20:55 +00003806 OutParamTypes.push_back(NewParm->getType());
3807 if (PVars)
3808 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003809 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003810
3811 // If we're supposed to retain a pack expansion, do so by temporarily
3812 // forgetting the partially-substituted parameter pack.
3813 if (RetainExpansion) {
3814 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3815 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00003816 = getDerived().TransformFunctionTypeParam(OldParm,
3817 OrigNumExpansions);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003818 if (!NewParm)
3819 return true;
3820
3821 OutParamTypes.push_back(NewParm->getType());
3822 if (PVars)
3823 PVars->push_back(NewParm);
3824 }
3825
Douglas Gregor5499af42011-01-05 23:12:31 +00003826 // We're done with the pack expansion.
3827 continue;
3828 }
3829
3830 // We'll substitute the parameter now without expanding the pack
3831 // expansion.
3832 }
3833
3834 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Douglas Gregor715e4612011-01-14 22:40:04 +00003835 ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm,
3836 NumExpansions);
John McCall58f10c32010-03-11 09:03:00 +00003837 if (!NewParm)
3838 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003839
Douglas Gregordd472162011-01-07 00:20:55 +00003840 OutParamTypes.push_back(NewParm->getType());
3841 if (PVars)
3842 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00003843 continue;
3844 }
John McCall58f10c32010-03-11 09:03:00 +00003845
3846 // Deal with the possibility that we don't have a parameter
3847 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00003848 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00003849 bool IsPackExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003850 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor5499af42011-01-05 23:12:31 +00003851 if (const PackExpansionType *Expansion
3852 = dyn_cast<PackExpansionType>(OldType)) {
3853 // We have a function parameter pack that may need to be expanded.
3854 QualType Pattern = Expansion->getPattern();
3855 llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded;
3856 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3857
3858 // Determine whether we should expand the parameter packs.
3859 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003860 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00003861 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Douglas Gregor5499af42011-01-05 23:12:31 +00003862 Unexpanded.data(),
3863 Unexpanded.size(),
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003864 ShouldExpand,
3865 RetainExpansion,
3866 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00003867 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00003868 }
3869
3870 if (ShouldExpand) {
3871 // Expand the function parameter pack into multiple, separate
3872 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003873 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00003874 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3875 QualType NewType = getDerived().TransformType(Pattern);
3876 if (NewType.isNull())
3877 return true;
John McCall58f10c32010-03-11 09:03:00 +00003878
Douglas Gregordd472162011-01-07 00:20:55 +00003879 OutParamTypes.push_back(NewType);
3880 if (PVars)
3881 PVars->push_back(0);
Douglas Gregor5499af42011-01-05 23:12:31 +00003882 }
3883
3884 // We're done with the pack expansion.
3885 continue;
3886 }
3887
Douglas Gregor48d24112011-01-10 20:53:55 +00003888 // If we're supposed to retain a pack expansion, do so by temporarily
3889 // forgetting the partially-substituted parameter pack.
3890 if (RetainExpansion) {
3891 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3892 QualType NewType = getDerived().TransformType(Pattern);
3893 if (NewType.isNull())
3894 return true;
3895
3896 OutParamTypes.push_back(NewType);
3897 if (PVars)
3898 PVars->push_back(0);
3899 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003900
Douglas Gregor5499af42011-01-05 23:12:31 +00003901 // We'll substitute the parameter now without expanding the pack
3902 // expansion.
3903 OldType = Expansion->getPattern();
3904 IsPackExpansion = true;
3905 }
3906
3907 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3908 QualType NewType = getDerived().TransformType(OldType);
3909 if (NewType.isNull())
3910 return true;
3911
3912 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003913 NewType = getSema().Context.getPackExpansionType(NewType,
3914 NumExpansions);
Douglas Gregor5499af42011-01-05 23:12:31 +00003915
Douglas Gregordd472162011-01-07 00:20:55 +00003916 OutParamTypes.push_back(NewType);
3917 if (PVars)
3918 PVars->push_back(0);
John McCall58f10c32010-03-11 09:03:00 +00003919 }
3920
3921 return false;
Douglas Gregor5499af42011-01-05 23:12:31 +00003922 }
John McCall58f10c32010-03-11 09:03:00 +00003923
3924template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003925QualType
John McCall550e0c22009-10-21 00:40:46 +00003926TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003927 FunctionProtoTypeLoc TL) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00003928 // Transform the parameters and return type.
3929 //
3930 // We instantiate in source order, with the return type first followed by
3931 // the parameters, because users tend to expect this (even if they shouldn't
3932 // rely on it!).
3933 //
Douglas Gregor7fb25412010-10-01 18:44:50 +00003934 // When the function has a trailing return type, we instantiate the
3935 // parameters before the return type, since the return type can then refer
3936 // to the parameters themselves (via decltype, sizeof, etc.).
3937 //
Douglas Gregord6ff3322009-08-04 16:50:30 +00003938 llvm::SmallVector<QualType, 4> ParamTypes;
John McCall550e0c22009-10-21 00:40:46 +00003939 llvm::SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00003940 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00003941
Douglas Gregor7fb25412010-10-01 18:44:50 +00003942 QualType ResultType;
3943
3944 if (TL.getTrailingReturn()) {
Douglas Gregordd472162011-01-07 00:20:55 +00003945 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3946 TL.getParmArray(),
3947 TL.getNumArgs(),
3948 TL.getTypePtr()->arg_type_begin(),
3949 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003950 return QualType();
3951
3952 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3953 if (ResultType.isNull())
3954 return QualType();
3955 }
3956 else {
3957 ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
3958 if (ResultType.isNull())
3959 return QualType();
3960
Douglas Gregordd472162011-01-07 00:20:55 +00003961 if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(),
3962 TL.getParmArray(),
3963 TL.getNumArgs(),
3964 TL.getTypePtr()->arg_type_begin(),
3965 ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00003966 return QualType();
3967 }
3968
John McCall550e0c22009-10-21 00:40:46 +00003969 QualType Result = TL.getType();
3970 if (getDerived().AlwaysRebuild() ||
3971 ResultType != T->getResultType() ||
Douglas Gregor9f627df2011-01-07 19:27:47 +00003972 T->getNumArgs() != ParamTypes.size() ||
John McCall550e0c22009-10-21 00:40:46 +00003973 !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) {
3974 Result = getDerived().RebuildFunctionProtoType(ResultType,
3975 ParamTypes.data(),
3976 ParamTypes.size(),
3977 T->isVariadic(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003978 T->getTypeQuals(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00003979 T->getRefQualifier(),
Eli Friedmand8725a92010-08-05 02:54:05 +00003980 T->getExtInfo());
John McCall550e0c22009-10-21 00:40:46 +00003981 if (Result.isNull())
3982 return QualType();
3983 }
Mike Stump11289f42009-09-09 15:08:12 +00003984
John McCall550e0c22009-10-21 00:40:46 +00003985 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
3986 NewTL.setLParenLoc(TL.getLParenLoc());
3987 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00003988 NewTL.setTrailingReturn(TL.getTrailingReturn());
John McCall550e0c22009-10-21 00:40:46 +00003989 for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i)
3990 NewTL.setArg(i, ParamDecls[i]);
3991
3992 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00003993}
Mike Stump11289f42009-09-09 15:08:12 +00003994
Douglas Gregord6ff3322009-08-04 16:50:30 +00003995template<typename Derived>
3996QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00003997 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003998 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00003999 const FunctionNoProtoType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004000 QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc());
4001 if (ResultType.isNull())
4002 return QualType();
4003
4004 QualType Result = TL.getType();
4005 if (getDerived().AlwaysRebuild() ||
4006 ResultType != T->getResultType())
4007 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4008
4009 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
4010 NewTL.setLParenLoc(TL.getLParenLoc());
4011 NewTL.setRParenLoc(TL.getRParenLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004012 NewTL.setTrailingReturn(false);
John McCall550e0c22009-10-21 00:40:46 +00004013
4014 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004015}
Mike Stump11289f42009-09-09 15:08:12 +00004016
John McCallb96ec562009-12-04 22:46:56 +00004017template<typename Derived> QualType
4018TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004019 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004020 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004021 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004022 if (!D)
4023 return QualType();
4024
4025 QualType Result = TL.getType();
4026 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4027 Result = getDerived().RebuildUnresolvedUsingType(D);
4028 if (Result.isNull())
4029 return QualType();
4030 }
4031
4032 // We might get an arbitrary type spec type back. We should at
4033 // least always get a type spec type, though.
4034 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4035 NewTL.setNameLoc(TL.getNameLoc());
4036
4037 return Result;
4038}
4039
Douglas Gregord6ff3322009-08-04 16:50:30 +00004040template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004041QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004042 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004043 const TypedefType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004044 TypedefDecl *Typedef
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004045 = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4046 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004047 if (!Typedef)
4048 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004049
John McCall550e0c22009-10-21 00:40:46 +00004050 QualType Result = TL.getType();
4051 if (getDerived().AlwaysRebuild() ||
4052 Typedef != T->getDecl()) {
4053 Result = getDerived().RebuildTypedefType(Typedef);
4054 if (Result.isNull())
4055 return QualType();
4056 }
Mike Stump11289f42009-09-09 15:08:12 +00004057
John McCall550e0c22009-10-21 00:40:46 +00004058 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4059 NewTL.setNameLoc(TL.getNameLoc());
4060
4061 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004062}
Mike Stump11289f42009-09-09 15:08:12 +00004063
Douglas Gregord6ff3322009-08-04 16:50:30 +00004064template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004065QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004066 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004067 // typeof expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004068 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004069
John McCalldadc5752010-08-24 06:29:42 +00004070 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004071 if (E.isInvalid())
4072 return QualType();
4073
John McCall550e0c22009-10-21 00:40:46 +00004074 QualType Result = TL.getType();
4075 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004076 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004077 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004078 if (Result.isNull())
4079 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004080 }
John McCall550e0c22009-10-21 00:40:46 +00004081 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004082
John McCall550e0c22009-10-21 00:40:46 +00004083 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004084 NewTL.setTypeofLoc(TL.getTypeofLoc());
4085 NewTL.setLParenLoc(TL.getLParenLoc());
4086 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004087
4088 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004089}
Mike Stump11289f42009-09-09 15:08:12 +00004090
4091template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004092QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004093 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004094 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4095 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4096 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004097 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004098
John McCall550e0c22009-10-21 00:40:46 +00004099 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004100 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4101 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004102 if (Result.isNull())
4103 return QualType();
4104 }
Mike Stump11289f42009-09-09 15:08:12 +00004105
John McCall550e0c22009-10-21 00:40:46 +00004106 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004107 NewTL.setTypeofLoc(TL.getTypeofLoc());
4108 NewTL.setLParenLoc(TL.getLParenLoc());
4109 NewTL.setRParenLoc(TL.getRParenLoc());
4110 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004111
4112 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004113}
Mike Stump11289f42009-09-09 15:08:12 +00004114
4115template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004116QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004117 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004118 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004119
Douglas Gregore922c772009-08-04 22:27:00 +00004120 // decltype expressions are not potentially evaluated contexts
John McCallfaf5fb42010-08-26 23:41:50 +00004121 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004122
John McCalldadc5752010-08-24 06:29:42 +00004123 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004124 if (E.isInvalid())
4125 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004126
John McCall550e0c22009-10-21 00:40:46 +00004127 QualType Result = TL.getType();
4128 if (getDerived().AlwaysRebuild() ||
4129 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004130 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004131 if (Result.isNull())
4132 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004133 }
John McCall550e0c22009-10-21 00:40:46 +00004134 else E.take();
Mike Stump11289f42009-09-09 15:08:12 +00004135
John McCall550e0c22009-10-21 00:40:46 +00004136 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
4137 NewTL.setNameLoc(TL.getNameLoc());
4138
4139 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004140}
4141
4142template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00004143QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
4144 AutoTypeLoc TL) {
4145 const AutoType *T = TL.getTypePtr();
4146 QualType OldDeduced = T->getDeducedType();
4147 QualType NewDeduced;
4148 if (!OldDeduced.isNull()) {
4149 NewDeduced = getDerived().TransformType(OldDeduced);
4150 if (NewDeduced.isNull())
4151 return QualType();
4152 }
4153
4154 QualType Result = TL.getType();
4155 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) {
4156 Result = getDerived().RebuildAutoType(NewDeduced);
4157 if (Result.isNull())
4158 return QualType();
4159 }
4160
4161 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
4162 NewTL.setNameLoc(TL.getNameLoc());
4163
4164 return Result;
4165}
4166
4167template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004168QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004169 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004170 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004171 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004172 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4173 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004174 if (!Record)
4175 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004176
John McCall550e0c22009-10-21 00:40:46 +00004177 QualType Result = TL.getType();
4178 if (getDerived().AlwaysRebuild() ||
4179 Record != T->getDecl()) {
4180 Result = getDerived().RebuildRecordType(Record);
4181 if (Result.isNull())
4182 return QualType();
4183 }
Mike Stump11289f42009-09-09 15:08:12 +00004184
John McCall550e0c22009-10-21 00:40:46 +00004185 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
4186 NewTL.setNameLoc(TL.getNameLoc());
4187
4188 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004189}
Mike Stump11289f42009-09-09 15:08:12 +00004190
4191template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004192QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004193 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004194 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004195 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004196 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4197 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004198 if (!Enum)
4199 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004200
John McCall550e0c22009-10-21 00:40:46 +00004201 QualType Result = TL.getType();
4202 if (getDerived().AlwaysRebuild() ||
4203 Enum != T->getDecl()) {
4204 Result = getDerived().RebuildEnumType(Enum);
4205 if (Result.isNull())
4206 return QualType();
4207 }
Mike Stump11289f42009-09-09 15:08:12 +00004208
John McCall550e0c22009-10-21 00:40:46 +00004209 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
4210 NewTL.setNameLoc(TL.getNameLoc());
4211
4212 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004213}
John McCallfcc33b02009-09-05 00:15:47 +00004214
John McCalle78aac42010-03-10 03:28:59 +00004215template<typename Derived>
4216QualType TreeTransform<Derived>::TransformInjectedClassNameType(
4217 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004218 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00004219 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
4220 TL.getTypePtr()->getDecl());
4221 if (!D) return QualType();
4222
4223 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
4224 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
4225 return T;
4226}
4227
Douglas Gregord6ff3322009-08-04 16:50:30 +00004228template<typename Derived>
4229QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004230 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004231 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004232 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004233}
4234
Mike Stump11289f42009-09-09 15:08:12 +00004235template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00004236QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00004237 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004238 SubstTemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004239 return TransformTypeSpecType(TLB, TL);
John McCallcebee162009-10-18 09:09:24 +00004240}
4241
4242template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00004243QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
4244 TypeLocBuilder &TLB,
4245 SubstTemplateTypeParmPackTypeLoc TL) {
4246 return TransformTypeSpecType(TLB, TL);
4247}
4248
4249template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00004250QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00004251 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004252 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00004253 const TemplateSpecializationType *T = TL.getTypePtr();
4254
Mike Stump11289f42009-09-09 15:08:12 +00004255 TemplateName Template
John McCall31f82722010-11-12 08:19:04 +00004256 = getDerived().TransformTemplateName(T->getTemplateName());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004257 if (Template.isNull())
4258 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004259
John McCall31f82722010-11-12 08:19:04 +00004260 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
4261}
4262
Douglas Gregorfe921a72010-12-20 23:36:19 +00004263namespace {
4264 /// \brief Simple iterator that traverses the template arguments in a
4265 /// container that provides a \c getArgLoc() member function.
4266 ///
4267 /// This iterator is intended to be used with the iterator form of
4268 /// \c TreeTransform<Derived>::TransformTemplateArguments().
4269 template<typename ArgLocContainer>
4270 class TemplateArgumentLocContainerIterator {
4271 ArgLocContainer *Container;
4272 unsigned Index;
4273
4274 public:
4275 typedef TemplateArgumentLoc value_type;
4276 typedef TemplateArgumentLoc reference;
4277 typedef int difference_type;
4278 typedef std::input_iterator_tag iterator_category;
4279
4280 class pointer {
4281 TemplateArgumentLoc Arg;
4282
4283 public:
4284 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
4285
4286 const TemplateArgumentLoc *operator->() const {
4287 return &Arg;
4288 }
4289 };
4290
4291
4292 TemplateArgumentLocContainerIterator() {}
4293
4294 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
4295 unsigned Index)
4296 : Container(&Container), Index(Index) { }
4297
4298 TemplateArgumentLocContainerIterator &operator++() {
4299 ++Index;
4300 return *this;
4301 }
4302
4303 TemplateArgumentLocContainerIterator operator++(int) {
4304 TemplateArgumentLocContainerIterator Old(*this);
4305 ++(*this);
4306 return Old;
4307 }
4308
4309 TemplateArgumentLoc operator*() const {
4310 return Container->getArgLoc(Index);
4311 }
4312
4313 pointer operator->() const {
4314 return pointer(Container->getArgLoc(Index));
4315 }
4316
4317 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004318 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004319 return X.Container == Y.Container && X.Index == Y.Index;
4320 }
4321
4322 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00004323 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00004324 return !(X == Y);
4325 }
4326 };
4327}
4328
4329
John McCall31f82722010-11-12 08:19:04 +00004330template <typename Derived>
4331QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
4332 TypeLocBuilder &TLB,
4333 TemplateSpecializationTypeLoc TL,
4334 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00004335 TemplateArgumentListInfo NewTemplateArgs;
4336 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4337 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00004338 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
4339 ArgIterator;
4340 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4341 ArgIterator(TL, TL.getNumArgs()),
4342 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004343 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004344
John McCall0ad16662009-10-29 08:12:44 +00004345 // FIXME: maybe don't rebuild if all the template arguments are the same.
4346
4347 QualType Result =
4348 getDerived().RebuildTemplateSpecializationType(Template,
4349 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00004350 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00004351
4352 if (!Result.isNull()) {
4353 TemplateSpecializationTypeLoc NewTL
4354 = TLB.push<TemplateSpecializationTypeLoc>(Result);
4355 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
4356 NewTL.setLAngleLoc(TL.getLAngleLoc());
4357 NewTL.setRAngleLoc(TL.getRAngleLoc());
4358 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
4359 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004360 }
Mike Stump11289f42009-09-09 15:08:12 +00004361
John McCall0ad16662009-10-29 08:12:44 +00004362 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004363}
Mike Stump11289f42009-09-09 15:08:12 +00004364
4365template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004366QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00004367TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004368 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004369 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00004370
4371 NestedNameSpecifier *NNS = 0;
4372 // NOTE: the qualifier in an ElaboratedType is optional.
4373 if (T->getQualifier() != 0) {
4374 NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004375 TL.getQualifierRange());
Abramo Bagnara6150c882010-05-11 21:36:43 +00004376 if (!NNS)
4377 return QualType();
4378 }
Mike Stump11289f42009-09-09 15:08:12 +00004379
John McCall31f82722010-11-12 08:19:04 +00004380 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
4381 if (NamedT.isNull())
4382 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00004383
John McCall550e0c22009-10-21 00:40:46 +00004384 QualType Result = TL.getType();
4385 if (getDerived().AlwaysRebuild() ||
4386 NNS != T->getQualifier() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00004387 NamedT != T->getNamedType()) {
John McCall954b5de2010-11-04 19:04:38 +00004388 Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(),
4389 T->getKeyword(), NNS, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00004390 if (Result.isNull())
4391 return QualType();
4392 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004393
Abramo Bagnara6150c882010-05-11 21:36:43 +00004394 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnarad7548482010-05-19 21:37:53 +00004395 NewTL.setKeywordLoc(TL.getKeywordLoc());
4396 NewTL.setQualifierRange(TL.getQualifierRange());
John McCall550e0c22009-10-21 00:40:46 +00004397
4398 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004399}
Mike Stump11289f42009-09-09 15:08:12 +00004400
4401template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00004402QualType TreeTransform<Derived>::TransformAttributedType(
4403 TypeLocBuilder &TLB,
4404 AttributedTypeLoc TL) {
4405 const AttributedType *oldType = TL.getTypePtr();
4406 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
4407 if (modifiedType.isNull())
4408 return QualType();
4409
4410 QualType result = TL.getType();
4411
4412 // FIXME: dependent operand expressions?
4413 if (getDerived().AlwaysRebuild() ||
4414 modifiedType != oldType->getModifiedType()) {
4415 // TODO: this is really lame; we should really be rebuilding the
4416 // equivalent type from first principles.
4417 QualType equivalentType
4418 = getDerived().TransformType(oldType->getEquivalentType());
4419 if (equivalentType.isNull())
4420 return QualType();
4421 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
4422 modifiedType,
4423 equivalentType);
4424 }
4425
4426 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
4427 newTL.setAttrNameLoc(TL.getAttrNameLoc());
4428 if (TL.hasAttrOperand())
4429 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
4430 if (TL.hasAttrExprOperand())
4431 newTL.setAttrExprOperand(TL.getAttrExprOperand());
4432 else if (TL.hasAttrEnumOperand())
4433 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
4434
4435 return result;
4436}
4437
4438template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00004439QualType
4440TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
4441 ParenTypeLoc TL) {
4442 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
4443 if (Inner.isNull())
4444 return QualType();
4445
4446 QualType Result = TL.getType();
4447 if (getDerived().AlwaysRebuild() ||
4448 Inner != TL.getInnerLoc().getType()) {
4449 Result = getDerived().RebuildParenType(Inner);
4450 if (Result.isNull())
4451 return QualType();
4452 }
4453
4454 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
4455 NewTL.setLParenLoc(TL.getLParenLoc());
4456 NewTL.setRParenLoc(TL.getRParenLoc());
4457 return Result;
4458}
4459
4460template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00004461QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004462 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004463 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00004464
Douglas Gregord6ff3322009-08-04 16:50:30 +00004465 NestedNameSpecifier *NNS
Abramo Bagnarad7548482010-05-19 21:37:53 +00004466 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004467 TL.getQualifierRange());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004468 if (!NNS)
4469 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004470
John McCallc392f372010-06-11 00:33:02 +00004471 QualType Result
4472 = getDerived().RebuildDependentNameType(T->getKeyword(), NNS,
4473 T->getIdentifier(),
4474 TL.getKeywordLoc(),
4475 TL.getQualifierRange(),
4476 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00004477 if (Result.isNull())
4478 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004479
Abramo Bagnarad7548482010-05-19 21:37:53 +00004480 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
4481 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00004482 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
4483
Abramo Bagnarad7548482010-05-19 21:37:53 +00004484 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4485 NewTL.setKeywordLoc(TL.getKeywordLoc());
4486 NewTL.setQualifierRange(TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004487 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00004488 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
4489 NewTL.setKeywordLoc(TL.getKeywordLoc());
4490 NewTL.setQualifierRange(TL.getQualifierRange());
4491 NewTL.setNameLoc(TL.getNameLoc());
4492 }
John McCall550e0c22009-10-21 00:40:46 +00004493 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004494}
Mike Stump11289f42009-09-09 15:08:12 +00004495
Douglas Gregord6ff3322009-08-04 16:50:30 +00004496template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00004497QualType TreeTransform<Derived>::
4498 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004499 DependentTemplateSpecializationTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004500 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCallc392f372010-06-11 00:33:02 +00004501
4502 NestedNameSpecifier *NNS
4503 = getDerived().TransformNestedNameSpecifier(T->getQualifier(),
John McCall31f82722010-11-12 08:19:04 +00004504 TL.getQualifierRange());
John McCallc392f372010-06-11 00:33:02 +00004505 if (!NNS)
4506 return QualType();
4507
John McCall31f82722010-11-12 08:19:04 +00004508 return getDerived()
4509 .TransformDependentTemplateSpecializationType(TLB, TL, NNS);
4510}
4511
4512template<typename Derived>
4513QualType TreeTransform<Derived>::
4514 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
4515 DependentTemplateSpecializationTypeLoc TL,
4516 NestedNameSpecifier *NNS) {
John McCall424cec92011-01-19 06:33:43 +00004517 const DependentTemplateSpecializationType *T = TL.getTypePtr();
John McCall31f82722010-11-12 08:19:04 +00004518
John McCallc392f372010-06-11 00:33:02 +00004519 TemplateArgumentListInfo NewTemplateArgs;
4520 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
4521 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor14454802011-02-25 02:25:35 +00004522
4523 // FIXME: Nested-name-specifier source location info!
Douglas Gregorfe921a72010-12-20 23:36:19 +00004524 typedef TemplateArgumentLocContainerIterator<
4525 DependentTemplateSpecializationTypeLoc> ArgIterator;
4526 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
4527 ArgIterator(TL, TL.getNumArgs()),
4528 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00004529 return QualType();
John McCallc392f372010-06-11 00:33:02 +00004530
Douglas Gregora5614c52010-09-08 23:56:00 +00004531 QualType Result
4532 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
4533 NNS,
4534 TL.getQualifierRange(),
4535 T->getIdentifier(),
4536 TL.getNameLoc(),
4537 NewTemplateArgs);
John McCallc392f372010-06-11 00:33:02 +00004538 if (Result.isNull())
4539 return QualType();
4540
4541 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
4542 QualType NamedT = ElabT->getNamedType();
4543
4544 // Copy information relevant to the template specialization.
4545 TemplateSpecializationTypeLoc NamedTL
4546 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
4547 NamedTL.setLAngleLoc(TL.getLAngleLoc());
4548 NamedTL.setRAngleLoc(TL.getRAngleLoc());
4549 for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I)
4550 NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I));
4551
4552 // Copy information relevant to the elaborated type.
4553 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
4554 NewTL.setKeywordLoc(TL.getKeywordLoc());
4555 NewTL.setQualifierRange(TL.getQualifierRange());
4556 } else {
Douglas Gregorffa20392010-06-17 16:03:49 +00004557 TypeLoc NewTL(Result, TL.getOpaqueData());
4558 TLB.pushFullCopy(NewTL);
John McCallc392f372010-06-11 00:33:02 +00004559 }
4560 return Result;
4561}
4562
4563template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00004564QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
4565 PackExpansionTypeLoc TL) {
Douglas Gregor822d0302011-01-12 17:07:58 +00004566 QualType Pattern
4567 = getDerived().TransformType(TLB, TL.getPatternLoc());
4568 if (Pattern.isNull())
4569 return QualType();
4570
4571 QualType Result = TL.getType();
4572 if (getDerived().AlwaysRebuild() ||
4573 Pattern != TL.getPatternLoc().getType()) {
4574 Result = getDerived().RebuildPackExpansionType(Pattern,
4575 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004576 TL.getEllipsisLoc(),
4577 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00004578 if (Result.isNull())
4579 return QualType();
4580 }
4581
4582 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
4583 NewT.setEllipsisLoc(TL.getEllipsisLoc());
4584 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00004585}
4586
4587template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004588QualType
4589TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004590 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004591 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004592 TLB.pushFullCopy(TL);
4593 return TL.getType();
4594}
4595
4596template<typename Derived>
4597QualType
4598TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004599 ObjCObjectTypeLoc TL) {
John McCall8b07ec22010-05-15 11:32:37 +00004600 // ObjCObjectType is never dependent.
4601 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004602 return TL.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004603}
Mike Stump11289f42009-09-09 15:08:12 +00004604
4605template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004606QualType
4607TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004608 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00004609 // ObjCObjectPointerType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00004610 TLB.pushFullCopy(TL);
Douglas Gregor21515a92010-04-22 17:28:13 +00004611 return TL.getType();
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00004612}
4613
Douglas Gregord6ff3322009-08-04 16:50:30 +00004614//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00004615// Statement transformation
4616//===----------------------------------------------------------------------===//
4617template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004618StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004619TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00004620 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004621}
4622
4623template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004624StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004625TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
4626 return getDerived().TransformCompoundStmt(S, false);
4627}
4628
4629template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004630StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004631TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00004632 bool IsStmtExpr) {
John McCall1ababa62010-08-27 19:56:05 +00004633 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00004634 bool SubStmtChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00004635 ASTOwningVector<Stmt*> Statements(getSema());
Douglas Gregorebe10102009-08-20 07:17:43 +00004636 for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end();
4637 B != BEnd; ++B) {
John McCalldadc5752010-08-24 06:29:42 +00004638 StmtResult Result = getDerived().TransformStmt(*B);
John McCall1ababa62010-08-27 19:56:05 +00004639 if (Result.isInvalid()) {
4640 // Immediately fail if this was a DeclStmt, since it's very
4641 // likely that this will cause problems for future statements.
4642 if (isa<DeclStmt>(*B))
4643 return StmtError();
4644
4645 // Otherwise, just keep processing substatements and fail later.
4646 SubStmtInvalid = true;
4647 continue;
4648 }
Mike Stump11289f42009-09-09 15:08:12 +00004649
Douglas Gregorebe10102009-08-20 07:17:43 +00004650 SubStmtChanged = SubStmtChanged || Result.get() != *B;
4651 Statements.push_back(Result.takeAs<Stmt>());
4652 }
Mike Stump11289f42009-09-09 15:08:12 +00004653
John McCall1ababa62010-08-27 19:56:05 +00004654 if (SubStmtInvalid)
4655 return StmtError();
4656
Douglas Gregorebe10102009-08-20 07:17:43 +00004657 if (!getDerived().AlwaysRebuild() &&
4658 !SubStmtChanged)
John McCallc3007a22010-10-26 07:05:15 +00004659 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004660
4661 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
4662 move_arg(Statements),
4663 S->getRBracLoc(),
4664 IsStmtExpr);
4665}
Mike Stump11289f42009-09-09 15:08:12 +00004666
Douglas Gregorebe10102009-08-20 07:17:43 +00004667template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004668StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004669TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004670 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00004671 {
4672 // The case value expressions are not potentially evaluated.
John McCallfaf5fb42010-08-26 23:41:50 +00004673 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00004674
Eli Friedman06577382009-11-19 03:14:00 +00004675 // Transform the left-hand case value.
4676 LHS = getDerived().TransformExpr(S->getLHS());
4677 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004678 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004679
Eli Friedman06577382009-11-19 03:14:00 +00004680 // Transform the right-hand case value (for the GNU case-range extension).
4681 RHS = getDerived().TransformExpr(S->getRHS());
4682 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004683 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00004684 }
Mike Stump11289f42009-09-09 15:08:12 +00004685
Douglas Gregorebe10102009-08-20 07:17:43 +00004686 // Build the case statement.
4687 // Case statements are always rebuilt so that they will attached to their
4688 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004689 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00004690 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004691 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00004692 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004693 S->getColonLoc());
4694 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004695 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004696
Douglas Gregorebe10102009-08-20 07:17:43 +00004697 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00004698 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004699 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004700 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004701
Douglas Gregorebe10102009-08-20 07:17:43 +00004702 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00004703 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004704}
4705
4706template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004707StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004708TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004709 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00004710 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004711 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004712 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004713
Douglas Gregorebe10102009-08-20 07:17:43 +00004714 // Default statements are always rebuilt
4715 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00004716 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004717}
Mike Stump11289f42009-09-09 15:08:12 +00004718
Douglas Gregorebe10102009-08-20 07:17:43 +00004719template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004720StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004721TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004722 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00004723 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004724 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004725
Chris Lattnercab02a62011-02-17 20:34:02 +00004726 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
4727 S->getDecl());
4728 if (!LD)
4729 return StmtError();
4730
4731
Douglas Gregorebe10102009-08-20 07:17:43 +00004732 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00004733 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004734 cast<LabelDecl>(LD), SourceLocation(),
4735 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004736}
Mike Stump11289f42009-09-09 15:08:12 +00004737
Douglas Gregorebe10102009-08-20 07:17:43 +00004738template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004739StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004740TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004741 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004742 ExprResult Cond;
Douglas Gregor633caca2009-11-23 23:44:04 +00004743 VarDecl *ConditionVar = 0;
4744 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004745 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00004746 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004747 getDerived().TransformDefinition(
4748 S->getConditionVariable()->getLocation(),
4749 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00004750 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004751 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004752 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00004753 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004754
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004755 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004756 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004757
4758 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00004759 if (S->getCond()) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004760 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(),
4761 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004762 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004763 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004764
John McCallb268a282010-08-23 23:25:46 +00004765 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004766 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004767 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00004768
John McCallb268a282010-08-23 23:25:46 +00004769 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4770 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004771 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004772
Douglas Gregorebe10102009-08-20 07:17:43 +00004773 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00004774 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00004775 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004776 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004777
Douglas Gregorebe10102009-08-20 07:17:43 +00004778 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00004779 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00004780 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004781 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004782
Douglas Gregorebe10102009-08-20 07:17:43 +00004783 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004784 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004785 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004786 Then.get() == S->getThen() &&
4787 Else.get() == S->getElse())
John McCallc3007a22010-10-26 07:05:15 +00004788 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004789
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004790 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00004791 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00004792 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004793}
4794
4795template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004796StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004797TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004798 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00004799 ExprResult Cond;
Douglas Gregordcf19622009-11-24 17:07:59 +00004800 VarDecl *ConditionVar = 0;
4801 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004802 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00004803 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004804 getDerived().TransformDefinition(
4805 S->getConditionVariable()->getLocation(),
4806 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00004807 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004808 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004809 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00004810 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004811
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004812 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004813 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004814 }
Mike Stump11289f42009-09-09 15:08:12 +00004815
Douglas Gregorebe10102009-08-20 07:17:43 +00004816 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004817 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00004818 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00004819 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00004820 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004821 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004822
Douglas Gregorebe10102009-08-20 07:17:43 +00004823 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00004824 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004825 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004826 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004827
Douglas Gregorebe10102009-08-20 07:17:43 +00004828 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00004829 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
4830 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004831}
Mike Stump11289f42009-09-09 15:08:12 +00004832
Douglas Gregorebe10102009-08-20 07:17:43 +00004833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004834StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004835TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004836 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004837 ExprResult Cond;
Douglas Gregor680f8612009-11-24 21:15:44 +00004838 VarDecl *ConditionVar = 0;
4839 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004840 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00004841 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004842 getDerived().TransformDefinition(
4843 S->getConditionVariable()->getLocation(),
4844 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00004845 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004846 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004847 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00004848 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004849
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004850 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004851 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004852
4853 if (S->getCond()) {
4854 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004855 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(),
4856 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004857 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004858 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00004859 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00004860 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004861 }
Mike Stump11289f42009-09-09 15:08:12 +00004862
John McCallb268a282010-08-23 23:25:46 +00004863 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4864 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004865 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004866
Douglas Gregorebe10102009-08-20 07:17:43 +00004867 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004868 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004869 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004870 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004871
Douglas Gregorebe10102009-08-20 07:17:43 +00004872 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00004873 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004874 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004875 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00004876 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004877
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004878 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00004879 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004880}
Mike Stump11289f42009-09-09 15:08:12 +00004881
Douglas Gregorebe10102009-08-20 07:17:43 +00004882template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004883StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00004884TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004885 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004886 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004887 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004888 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004889
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004890 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004891 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004892 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004893 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004894
Douglas Gregorebe10102009-08-20 07:17:43 +00004895 if (!getDerived().AlwaysRebuild() &&
4896 Cond.get() == S->getCond() &&
4897 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004898 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004899
John McCallb268a282010-08-23 23:25:46 +00004900 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
4901 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00004902 S->getRParenLoc());
4903}
Mike Stump11289f42009-09-09 15:08:12 +00004904
Douglas Gregorebe10102009-08-20 07:17:43 +00004905template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004906StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004907TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00004908 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00004909 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00004910 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004911 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004912
Douglas Gregorebe10102009-08-20 07:17:43 +00004913 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00004914 ExprResult Cond;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004915 VarDecl *ConditionVar = 0;
4916 if (S->getConditionVariable()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00004917 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004918 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00004919 getDerived().TransformDefinition(
4920 S->getConditionVariable()->getLocation(),
4921 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004922 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00004923 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004924 } else {
4925 Cond = getDerived().TransformExpr(S->getCond());
Alexis Hunta8136cc2010-05-05 15:23:54 +00004926
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004927 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004928 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004929
4930 if (S->getCond()) {
4931 // Convert the condition to a boolean value.
Douglas Gregor840bd6c2010-12-20 22:05:00 +00004932 ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(),
4933 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00004934 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004935 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004936
John McCallb268a282010-08-23 23:25:46 +00004937 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00004938 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00004939 }
Mike Stump11289f42009-09-09 15:08:12 +00004940
John McCallb268a282010-08-23 23:25:46 +00004941 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take()));
4942 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004943 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004944
Douglas Gregorebe10102009-08-20 07:17:43 +00004945 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00004946 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00004947 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004948 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004949
John McCallb268a282010-08-23 23:25:46 +00004950 Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get()));
4951 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00004952 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00004953
Douglas Gregorebe10102009-08-20 07:17:43 +00004954 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00004955 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00004956 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004957 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004958
Douglas Gregorebe10102009-08-20 07:17:43 +00004959 if (!getDerived().AlwaysRebuild() &&
4960 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00004961 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00004962 Inc.get() == S->getInc() &&
4963 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00004964 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00004965
Douglas Gregorebe10102009-08-20 07:17:43 +00004966 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00004967 Init.get(), FullCond, ConditionVar,
4968 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004969}
4970
4971template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004972StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004973TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00004974 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
4975 S->getLabel());
4976 if (!LD)
4977 return StmtError();
4978
Douglas Gregorebe10102009-08-20 07:17:43 +00004979 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00004980 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00004981 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00004982}
4983
4984template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00004985StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00004986TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00004987 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00004988 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00004989 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00004990
Douglas Gregorebe10102009-08-20 07:17:43 +00004991 if (!getDerived().AlwaysRebuild() &&
4992 Target.get() == S->getTarget())
John McCallc3007a22010-10-26 07:05:15 +00004993 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00004994
4995 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00004996 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00004997}
4998
4999template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005000StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005001TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005002 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005003}
Mike Stump11289f42009-09-09 15:08:12 +00005004
Douglas Gregorebe10102009-08-20 07:17:43 +00005005template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005006StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005007TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
John McCallc3007a22010-10-26 07:05:15 +00005008 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005009}
Mike Stump11289f42009-09-09 15:08:12 +00005010
Douglas Gregorebe10102009-08-20 07:17:43 +00005011template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005012StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005013TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005014 ExprResult Result = getDerived().TransformExpr(S->getRetValue());
Douglas Gregorebe10102009-08-20 07:17:43 +00005015 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005016 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005017
Mike Stump11289f42009-09-09 15:08:12 +00005018 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00005019 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00005020 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005021}
Mike Stump11289f42009-09-09 15:08:12 +00005022
Douglas Gregorebe10102009-08-20 07:17:43 +00005023template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005024StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005025TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005026 bool DeclChanged = false;
5027 llvm::SmallVector<Decl *, 4> Decls;
5028 for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end();
5029 D != DEnd; ++D) {
Douglas Gregor25289362010-03-01 17:25:41 +00005030 Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(),
5031 *D);
Douglas Gregorebe10102009-08-20 07:17:43 +00005032 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00005033 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005034
Douglas Gregorebe10102009-08-20 07:17:43 +00005035 if (Transformed != *D)
5036 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00005037
Douglas Gregorebe10102009-08-20 07:17:43 +00005038 Decls.push_back(Transformed);
5039 }
Mike Stump11289f42009-09-09 15:08:12 +00005040
Douglas Gregorebe10102009-08-20 07:17:43 +00005041 if (!getDerived().AlwaysRebuild() && !DeclChanged)
John McCallc3007a22010-10-26 07:05:15 +00005042 return SemaRef.Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00005043
5044 return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005045 S->getStartLoc(), S->getEndLoc());
5046}
Mike Stump11289f42009-09-09 15:08:12 +00005047
Douglas Gregorebe10102009-08-20 07:17:43 +00005048template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005049StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005050TreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005051
John McCall37ad5512010-08-23 06:44:23 +00005052 ASTOwningVector<Expr*> Constraints(getSema());
5053 ASTOwningVector<Expr*> Exprs(getSema());
Anders Carlsson9a020f92010-01-30 22:25:16 +00005054 llvm::SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00005055
John McCalldadc5752010-08-24 06:29:42 +00005056 ExprResult AsmString;
John McCall37ad5512010-08-23 06:44:23 +00005057 ASTOwningVector<Expr*> Clobbers(getSema());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005058
5059 bool ExprsChanged = false;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005060
Anders Carlssonaaeef072010-01-24 05:50:09 +00005061 // Go through the outputs.
5062 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005063 Names.push_back(S->getOutputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005064
Anders Carlssonaaeef072010-01-24 05:50:09 +00005065 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005066 Constraints.push_back(S->getOutputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005067
Anders Carlssonaaeef072010-01-24 05:50:09 +00005068 // Transform the output expr.
5069 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005070 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005071 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005072 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005073
Anders Carlssonaaeef072010-01-24 05:50:09 +00005074 ExprsChanged |= Result.get() != OutputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005075
John McCallb268a282010-08-23 23:25:46 +00005076 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005077 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005078
Anders Carlssonaaeef072010-01-24 05:50:09 +00005079 // Go through the inputs.
5080 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00005081 Names.push_back(S->getInputIdentifier(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005082
Anders Carlssonaaeef072010-01-24 05:50:09 +00005083 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00005084 Constraints.push_back(S->getInputConstraintLiteral(I));
Alexis Hunta8136cc2010-05-05 15:23:54 +00005085
Anders Carlssonaaeef072010-01-24 05:50:09 +00005086 // Transform the input expr.
5087 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00005088 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005089 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005090 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005091
Anders Carlssonaaeef072010-01-24 05:50:09 +00005092 ExprsChanged |= Result.get() != InputExpr;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005093
John McCallb268a282010-08-23 23:25:46 +00005094 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00005095 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005096
Anders Carlssonaaeef072010-01-24 05:50:09 +00005097 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
John McCallc3007a22010-10-26 07:05:15 +00005098 return SemaRef.Owned(S);
Anders Carlssonaaeef072010-01-24 05:50:09 +00005099
5100 // Go through the clobbers.
5101 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
John McCallc3007a22010-10-26 07:05:15 +00005102 Clobbers.push_back(S->getClobber(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00005103
5104 // No need to transform the asm string literal.
5105 AsmString = SemaRef.Owned(S->getAsmString());
5106
5107 return getDerived().RebuildAsmStmt(S->getAsmLoc(),
5108 S->isSimple(),
5109 S->isVolatile(),
5110 S->getNumOutputs(),
5111 S->getNumInputs(),
Anders Carlsson087bc132010-01-30 20:05:21 +00005112 Names.data(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005113 move_arg(Constraints),
5114 move_arg(Exprs),
John McCallb268a282010-08-23 23:25:46 +00005115 AsmString.get(),
Anders Carlssonaaeef072010-01-24 05:50:09 +00005116 move_arg(Clobbers),
5117 S->getRParenLoc(),
5118 S->isMSAsm());
Douglas Gregorebe10102009-08-20 07:17:43 +00005119}
5120
5121
5122template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005123StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005124TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005125 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00005126 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005127 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005128 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005129
Douglas Gregor96c79492010-04-23 22:50:49 +00005130 // Transform the @catch statements (if present).
5131 bool AnyCatchChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005132 ASTOwningVector<Stmt*> CatchStmts(SemaRef);
Douglas Gregor96c79492010-04-23 22:50:49 +00005133 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005134 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00005135 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005136 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00005137 if (Catch.get() != S->getCatchStmt(I))
5138 AnyCatchChanged = true;
5139 CatchStmts.push_back(Catch.release());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005140 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005141
Douglas Gregor306de2f2010-04-22 23:59:56 +00005142 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00005143 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00005144 if (S->getFinallyStmt()) {
5145 Finally = getDerived().TransformStmt(S->getFinallyStmt());
5146 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005147 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00005148 }
5149
5150 // If nothing changed, just retain this statement.
5151 if (!getDerived().AlwaysRebuild() &&
5152 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00005153 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00005154 Finally.get() == S->getFinallyStmt())
John McCallc3007a22010-10-26 07:05:15 +00005155 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005156
Douglas Gregor306de2f2010-04-22 23:59:56 +00005157 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00005158 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
5159 move_arg(CatchStmts), Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005160}
Mike Stump11289f42009-09-09 15:08:12 +00005161
Douglas Gregorebe10102009-08-20 07:17:43 +00005162template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005163StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005164TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005165 // Transform the @catch parameter, if there is one.
5166 VarDecl *Var = 0;
5167 if (VarDecl *FromVar = S->getCatchParamDecl()) {
5168 TypeSourceInfo *TSInfo = 0;
5169 if (FromVar->getTypeSourceInfo()) {
5170 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
5171 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005172 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005173 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005174
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005175 QualType T;
5176 if (TSInfo)
5177 T = TSInfo->getType();
5178 else {
5179 T = getDerived().TransformType(FromVar->getType());
5180 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005181 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005182 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005183
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005184 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
5185 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00005186 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005187 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005188
John McCalldadc5752010-08-24 06:29:42 +00005189 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005190 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005191 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005192
5193 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00005194 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005195 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005196}
Mike Stump11289f42009-09-09 15:08:12 +00005197
Douglas Gregorebe10102009-08-20 07:17:43 +00005198template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005199StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005200TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00005201 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005202 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00005203 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005204 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005205
Douglas Gregor306de2f2010-04-22 23:59:56 +00005206 // If nothing changed, just retain this statement.
5207 if (!getDerived().AlwaysRebuild() &&
5208 Body.get() == S->getFinallyBody())
John McCallc3007a22010-10-26 07:05:15 +00005209 return SemaRef.Owned(S);
Douglas Gregor306de2f2010-04-22 23:59:56 +00005210
5211 // Build a new statement.
5212 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00005213 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005214}
Mike Stump11289f42009-09-09 15:08:12 +00005215
Douglas Gregorebe10102009-08-20 07:17:43 +00005216template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005217StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005218TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005219 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00005220 if (S->getThrowExpr()) {
5221 Operand = getDerived().TransformExpr(S->getThrowExpr());
5222 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005223 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00005224 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005225
Douglas Gregor2900c162010-04-22 21:44:01 +00005226 if (!getDerived().AlwaysRebuild() &&
5227 Operand.get() == S->getThrowExpr())
John McCallc3007a22010-10-26 07:05:15 +00005228 return getSema().Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005229
John McCallb268a282010-08-23 23:25:46 +00005230 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005231}
Mike Stump11289f42009-09-09 15:08:12 +00005232
Douglas Gregorebe10102009-08-20 07:17:43 +00005233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005234StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005235TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005236 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00005237 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00005238 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00005239 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005240 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005241
Douglas Gregor6148de72010-04-22 22:01:21 +00005242 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005243 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00005244 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005245 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005246
Douglas Gregor6148de72010-04-22 22:01:21 +00005247 // If nothing change, just retain the current statement.
5248 if (!getDerived().AlwaysRebuild() &&
5249 Object.get() == S->getSynchExpr() &&
5250 Body.get() == S->getSynchBody())
John McCallc3007a22010-10-26 07:05:15 +00005251 return SemaRef.Owned(S);
Douglas Gregor6148de72010-04-22 22:01:21 +00005252
5253 // Build a new statement.
5254 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00005255 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005256}
5257
5258template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005259StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005260TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00005261 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00005262 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00005263 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005264 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005265 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005266
Douglas Gregorf68a5082010-04-22 23:10:45 +00005267 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00005268 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005269 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005270 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005271
Douglas Gregorf68a5082010-04-22 23:10:45 +00005272 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00005273 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00005274 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005275 return StmtError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005276
Douglas Gregorf68a5082010-04-22 23:10:45 +00005277 // If nothing changed, just retain this statement.
5278 if (!getDerived().AlwaysRebuild() &&
5279 Element.get() == S->getElement() &&
5280 Collection.get() == S->getCollection() &&
5281 Body.get() == S->getBody())
John McCallc3007a22010-10-26 07:05:15 +00005282 return SemaRef.Owned(S);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005283
Douglas Gregorf68a5082010-04-22 23:10:45 +00005284 // Build a new statement.
5285 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
5286 /*FIXME:*/S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00005287 Element.get(),
5288 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00005289 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005290 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005291}
5292
5293
5294template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005295StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005296TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
5297 // Transform the exception declaration, if any.
5298 VarDecl *Var = 0;
5299 if (S->getExceptionDecl()) {
5300 VarDecl *ExceptionDecl = S->getExceptionDecl();
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005301 TypeSourceInfo *T = getDerived().TransformType(
5302 ExceptionDecl->getTypeSourceInfo());
5303 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00005304 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005305
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005306 Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T,
Douglas Gregorebe10102009-08-20 07:17:43 +00005307 ExceptionDecl->getIdentifier(),
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00005308 ExceptionDecl->getLocation());
Douglas Gregorb412e172010-07-25 18:17:45 +00005309 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00005310 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00005311 }
Mike Stump11289f42009-09-09 15:08:12 +00005312
Douglas Gregorebe10102009-08-20 07:17:43 +00005313 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00005314 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00005315 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005316 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005317
Douglas Gregorebe10102009-08-20 07:17:43 +00005318 if (!getDerived().AlwaysRebuild() &&
5319 !Var &&
5320 Handler.get() == S->getHandlerBlock())
John McCallc3007a22010-10-26 07:05:15 +00005321 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005322
5323 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(),
5324 Var,
John McCallb268a282010-08-23 23:25:46 +00005325 Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005326}
Mike Stump11289f42009-09-09 15:08:12 +00005327
Douglas Gregorebe10102009-08-20 07:17:43 +00005328template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005329StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005330TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
5331 // Transform the try block itself.
John McCalldadc5752010-08-24 06:29:42 +00005332 StmtResult TryBlock
Douglas Gregorebe10102009-08-20 07:17:43 +00005333 = getDerived().TransformCompoundStmt(S->getTryBlock());
5334 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005335 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005336
Douglas Gregorebe10102009-08-20 07:17:43 +00005337 // Transform the handlers.
5338 bool HandlerChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005339 ASTOwningVector<Stmt*> Handlers(SemaRef);
Douglas Gregorebe10102009-08-20 07:17:43 +00005340 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00005341 StmtResult Handler
Douglas Gregorebe10102009-08-20 07:17:43 +00005342 = getDerived().TransformCXXCatchStmt(S->getHandler(I));
5343 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005344 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005345
Douglas Gregorebe10102009-08-20 07:17:43 +00005346 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
5347 Handlers.push_back(Handler.takeAs<Stmt>());
5348 }
Mike Stump11289f42009-09-09 15:08:12 +00005349
Douglas Gregorebe10102009-08-20 07:17:43 +00005350 if (!getDerived().AlwaysRebuild() &&
5351 TryBlock.get() == S->getTryBlock() &&
5352 !HandlerChanged)
John McCallc3007a22010-10-26 07:05:15 +00005353 return SemaRef.Owned(S);
Douglas Gregorebe10102009-08-20 07:17:43 +00005354
John McCallb268a282010-08-23 23:25:46 +00005355 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Mike Stump11289f42009-09-09 15:08:12 +00005356 move_arg(Handlers));
Douglas Gregorebe10102009-08-20 07:17:43 +00005357}
Mike Stump11289f42009-09-09 15:08:12 +00005358
Douglas Gregorebe10102009-08-20 07:17:43 +00005359//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00005360// Expression transformation
5361//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00005362template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005363ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005364TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00005365 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005366}
Mike Stump11289f42009-09-09 15:08:12 +00005367
5368template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005369ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005370TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005371 NestedNameSpecifier *Qualifier = 0;
5372 if (E->getQualifier()) {
5373 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005374 E->getQualifierRange());
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005375 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00005376 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005377 }
John McCallce546572009-12-08 09:08:17 +00005378
5379 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005380 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
5381 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005382 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00005383 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005384
John McCall815039a2010-08-17 21:27:17 +00005385 DeclarationNameInfo NameInfo = E->getNameInfo();
5386 if (NameInfo.getName()) {
5387 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
5388 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00005389 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00005390 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005391
5392 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005393 Qualifier == E->getQualifier() &&
5394 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005395 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00005396 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005397
5398 // Mark it referenced in the new context regardless.
5399 // FIXME: this is a bit instantiation-specific.
5400 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
5401
John McCallc3007a22010-10-26 07:05:15 +00005402 return SemaRef.Owned(E);
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005403 }
John McCallce546572009-12-08 09:08:17 +00005404
5405 TemplateArgumentListInfo TransArgs, *TemplateArgs = 0;
John McCallb3774b52010-08-19 23:49:38 +00005406 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00005407 TemplateArgs = &TransArgs;
5408 TransArgs.setLAngleLoc(E->getLAngleLoc());
5409 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005410 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5411 E->getNumTemplateArgs(),
5412 TransArgs))
5413 return ExprError();
John McCallce546572009-12-08 09:08:17 +00005414 }
5415
Douglas Gregor4bd90e52009-10-23 18:54:35 +00005416 return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005417 ND, NameInfo, TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00005418}
Mike Stump11289f42009-09-09 15:08:12 +00005419
Douglas Gregora16548e2009-08-11 05:31:07 +00005420template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005421ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005422TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005423 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005424}
Mike Stump11289f42009-09-09 15:08:12 +00005425
Douglas Gregora16548e2009-08-11 05:31:07 +00005426template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005427ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005428TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005429 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005430}
Mike Stump11289f42009-09-09 15:08:12 +00005431
Douglas Gregora16548e2009-08-11 05:31:07 +00005432template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005433ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005434TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005435 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005436}
Mike Stump11289f42009-09-09 15:08:12 +00005437
Douglas Gregora16548e2009-08-11 05:31:07 +00005438template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005439ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005440TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005441 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005442}
Mike Stump11289f42009-09-09 15:08:12 +00005443
Douglas Gregora16548e2009-08-11 05:31:07 +00005444template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005445ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005446TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00005447 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005448}
5449
5450template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005451ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005452TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005453 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005454 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005455 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005456
Douglas Gregora16548e2009-08-11 05:31:07 +00005457 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005458 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005459
John McCallb268a282010-08-23 23:25:46 +00005460 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005461 E->getRParen());
5462}
5463
Mike Stump11289f42009-09-09 15:08:12 +00005464template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005465ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005466TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005467 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005468 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005469 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005470
Douglas Gregora16548e2009-08-11 05:31:07 +00005471 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005472 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005473
Douglas Gregora16548e2009-08-11 05:31:07 +00005474 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
5475 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005476 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005477}
Mike Stump11289f42009-09-09 15:08:12 +00005478
Douglas Gregora16548e2009-08-11 05:31:07 +00005479template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005480ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00005481TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
5482 // Transform the type.
5483 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
5484 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00005485 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005486
Douglas Gregor882211c2010-04-28 22:16:22 +00005487 // Transform all of the components into components similar to what the
5488 // parser uses.
Alexis Hunta8136cc2010-05-05 15:23:54 +00005489 // FIXME: It would be slightly more efficient in the non-dependent case to
5490 // just map FieldDecls, rather than requiring the rebuilder to look for
5491 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00005492 // template code that we don't care.
5493 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00005494 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00005495 typedef OffsetOfExpr::OffsetOfNode Node;
5496 llvm::SmallVector<Component, 4> Components;
5497 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
5498 const Node &ON = E->getComponent(I);
5499 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00005500 Comp.isBrackets = true;
Douglas Gregor882211c2010-04-28 22:16:22 +00005501 Comp.LocStart = ON.getRange().getBegin();
5502 Comp.LocEnd = ON.getRange().getEnd();
5503 switch (ON.getKind()) {
5504 case Node::Array: {
5505 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00005506 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00005507 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005508 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00005509
Douglas Gregor882211c2010-04-28 22:16:22 +00005510 ExprChanged = ExprChanged || Index.get() != FromIndex;
5511 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00005512 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00005513 break;
5514 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005515
Douglas Gregor882211c2010-04-28 22:16:22 +00005516 case Node::Field:
5517 case Node::Identifier:
5518 Comp.isBrackets = false;
5519 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00005520 if (!Comp.U.IdentInfo)
5521 continue;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005522
Douglas Gregor882211c2010-04-28 22:16:22 +00005523 break;
Alexis Hunta8136cc2010-05-05 15:23:54 +00005524
Douglas Gregord1702062010-04-29 00:18:15 +00005525 case Node::Base:
5526 // Will be recomputed during the rebuild.
5527 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00005528 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005529
Douglas Gregor882211c2010-04-28 22:16:22 +00005530 Components.push_back(Comp);
5531 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005532
Douglas Gregor882211c2010-04-28 22:16:22 +00005533 // If nothing changed, retain the existing expression.
5534 if (!getDerived().AlwaysRebuild() &&
5535 Type == E->getTypeSourceInfo() &&
5536 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005537 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00005538
Douglas Gregor882211c2010-04-28 22:16:22 +00005539 // Build a new offsetof expression.
5540 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
5541 Components.data(), Components.size(),
5542 E->getRParenLoc());
5543}
5544
5545template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005546ExprResult
John McCall8d69a212010-11-15 23:31:06 +00005547TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
5548 assert(getDerived().AlreadyTransformed(E->getType()) &&
5549 "opaque value expression requires transformation");
5550 return SemaRef.Owned(E);
5551}
5552
5553template<typename Derived>
5554ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005555TreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005556 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00005557 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00005558
John McCallbcd03502009-12-07 02:54:59 +00005559 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00005560 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005561 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005562
John McCall4c98fd82009-11-04 07:28:41 +00005563 if (!getDerived().AlwaysRebuild() && OldT == NewT)
John McCallc3007a22010-10-26 07:05:15 +00005564 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005565
John McCall4c98fd82009-11-04 07:28:41 +00005566 return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00005567 E->isSizeOf(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005568 E->getSourceRange());
5569 }
Mike Stump11289f42009-09-09 15:08:12 +00005570
John McCalldadc5752010-08-24 06:29:42 +00005571 ExprResult SubExpr;
Mike Stump11289f42009-09-09 15:08:12 +00005572 {
Douglas Gregora16548e2009-08-11 05:31:07 +00005573 // C++0x [expr.sizeof]p1:
5574 // The operand is either an expression, which is an unevaluated operand
5575 // [...]
John McCallfaf5fb42010-08-26 23:41:50 +00005576 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005577
Douglas Gregora16548e2009-08-11 05:31:07 +00005578 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
5579 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005580 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005581
Douglas Gregora16548e2009-08-11 05:31:07 +00005582 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
John McCallc3007a22010-10-26 07:05:15 +00005583 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005584 }
Mike Stump11289f42009-09-09 15:08:12 +00005585
John McCallb268a282010-08-23 23:25:46 +00005586 return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005587 E->isSizeOf(),
5588 E->getSourceRange());
5589}
Mike Stump11289f42009-09-09 15:08:12 +00005590
Douglas Gregora16548e2009-08-11 05:31:07 +00005591template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005592ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005593TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005594 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005595 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005596 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005597
John McCalldadc5752010-08-24 06:29:42 +00005598 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005599 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005600 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005601
5602
Douglas Gregora16548e2009-08-11 05:31:07 +00005603 if (!getDerived().AlwaysRebuild() &&
5604 LHS.get() == E->getLHS() &&
5605 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005606 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005607
John McCallb268a282010-08-23 23:25:46 +00005608 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005609 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00005610 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005611 E->getRBracketLoc());
5612}
Mike Stump11289f42009-09-09 15:08:12 +00005613
5614template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005615ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005616TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005617 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00005618 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00005619 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005620 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00005621
5622 // Transform arguments.
5623 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00005624 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005625 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
5626 &ArgChanged))
5627 return ExprError();
5628
Douglas Gregora16548e2009-08-11 05:31:07 +00005629 if (!getDerived().AlwaysRebuild() &&
5630 Callee.get() == E->getCallee() &&
5631 !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00005632 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005633
Douglas Gregora16548e2009-08-11 05:31:07 +00005634 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00005635 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005636 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00005637 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005638 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00005639 E->getRParenLoc());
5640}
Mike Stump11289f42009-09-09 15:08:12 +00005641
5642template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005643ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005644TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005645 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005646 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005647 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005648
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005649 NestedNameSpecifier *Qualifier = 0;
5650 if (E->hasQualifier()) {
Mike Stump11289f42009-09-09 15:08:12 +00005651 Qualifier
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005652 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00005653 E->getQualifierRange());
Douglas Gregor84f14dd2009-09-01 00:37:14 +00005654 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00005655 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005656 }
Mike Stump11289f42009-09-09 15:08:12 +00005657
Eli Friedman2cfcef62009-12-04 06:40:45 +00005658 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005659 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
5660 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00005661 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00005662 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005663
John McCall16df1e52010-03-30 21:47:33 +00005664 NamedDecl *FoundDecl = E->getFoundDecl();
5665 if (FoundDecl == E->getMemberDecl()) {
5666 FoundDecl = Member;
5667 } else {
5668 FoundDecl = cast_or_null<NamedDecl>(
5669 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
5670 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00005671 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00005672 }
5673
Douglas Gregora16548e2009-08-11 05:31:07 +00005674 if (!getDerived().AlwaysRebuild() &&
5675 Base.get() == E->getBase() &&
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005676 Qualifier == E->getQualifier() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005677 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00005678 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00005679 !E->hasExplicitTemplateArgs()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00005680
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005681 // Mark it referenced in the new context regardless.
5682 // FIXME: this is a bit instantiation-specific.
5683 SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member);
John McCallc3007a22010-10-26 07:05:15 +00005684 return SemaRef.Owned(E);
Anders Carlsson9c45ad72009-12-22 05:24:09 +00005685 }
Douglas Gregora16548e2009-08-11 05:31:07 +00005686
John McCall6b51f282009-11-23 01:53:49 +00005687 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00005688 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00005689 TransArgs.setLAngleLoc(E->getLAngleLoc());
5690 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00005691 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
5692 E->getNumTemplateArgs(),
5693 TransArgs))
5694 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005695 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00005696
Douglas Gregora16548e2009-08-11 05:31:07 +00005697 // FIXME: Bogus source location for the operator
5698 SourceLocation FakeOperatorLoc
5699 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
5700
John McCall38836f02010-01-15 08:34:02 +00005701 // FIXME: to do this check properly, we will need to preserve the
5702 // first-qualifier-in-scope here, just in case we had a dependent
5703 // base (and therefore couldn't do the check) and a
5704 // nested-name-qualifier (and therefore could do the lookup).
5705 NamedDecl *FirstQualifierInScope = 0;
5706
John McCallb268a282010-08-23 23:25:46 +00005707 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005708 E->isArrow(),
Douglas Gregorf405d7e2009-08-31 23:41:50 +00005709 Qualifier,
5710 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00005711 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00005712 Member,
John McCall16df1e52010-03-30 21:47:33 +00005713 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00005714 (E->hasExplicitTemplateArgs()
John McCall6b51f282009-11-23 01:53:49 +00005715 ? &TransArgs : 0),
John McCall38836f02010-01-15 08:34:02 +00005716 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00005717}
Mike Stump11289f42009-09-09 15:08:12 +00005718
Douglas Gregora16548e2009-08-11 05:31:07 +00005719template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005720ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005721TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005722 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005723 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005724 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005725
John McCalldadc5752010-08-24 06:29:42 +00005726 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005727 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005728 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005729
Douglas Gregora16548e2009-08-11 05:31:07 +00005730 if (!getDerived().AlwaysRebuild() &&
5731 LHS.get() == E->getLHS() &&
5732 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005733 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005734
Douglas Gregora16548e2009-08-11 05:31:07 +00005735 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00005736 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005737}
5738
Mike Stump11289f42009-09-09 15:08:12 +00005739template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005740ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005741TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00005742 CompoundAssignOperator *E) {
5743 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005744}
Mike Stump11289f42009-09-09 15:08:12 +00005745
Douglas Gregora16548e2009-08-11 05:31:07 +00005746template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00005747ExprResult TreeTransform<Derived>::
5748TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
5749 // Just rebuild the common and RHS expressions and see whether we
5750 // get any changes.
5751
5752 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
5753 if (commonExpr.isInvalid())
5754 return ExprError();
5755
5756 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
5757 if (rhs.isInvalid())
5758 return ExprError();
5759
5760 if (!getDerived().AlwaysRebuild() &&
5761 commonExpr.get() == e->getCommon() &&
5762 rhs.get() == e->getFalseExpr())
5763 return SemaRef.Owned(e);
5764
5765 return getDerived().RebuildConditionalOperator(commonExpr.take(),
5766 e->getQuestionLoc(),
5767 0,
5768 e->getColonLoc(),
5769 rhs.get());
5770}
5771
5772template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005773ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005774TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00005775 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00005776 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005777 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005778
John McCalldadc5752010-08-24 06:29:42 +00005779 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005780 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005781 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005782
John McCalldadc5752010-08-24 06:29:42 +00005783 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00005784 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005785 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005786
Douglas Gregora16548e2009-08-11 05:31:07 +00005787 if (!getDerived().AlwaysRebuild() &&
5788 Cond.get() == E->getCond() &&
5789 LHS.get() == E->getLHS() &&
5790 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00005791 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005792
John McCallb268a282010-08-23 23:25:46 +00005793 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005794 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00005795 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00005796 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005797 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005798}
Mike Stump11289f42009-09-09 15:08:12 +00005799
5800template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005801ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005802TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00005803 // Implicit casts are eliminated during transformation, since they
5804 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00005805 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005806}
Mike Stump11289f42009-09-09 15:08:12 +00005807
Douglas Gregora16548e2009-08-11 05:31:07 +00005808template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005809ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005810TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005811 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
5812 if (!Type)
5813 return ExprError();
5814
John McCalldadc5752010-08-24 06:29:42 +00005815 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00005816 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00005817 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005818 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005819
Douglas Gregora16548e2009-08-11 05:31:07 +00005820 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005821 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005822 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005823 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005824
John McCall97513962010-01-15 18:39:57 +00005825 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00005826 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00005827 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00005828 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005829}
Mike Stump11289f42009-09-09 15:08:12 +00005830
Douglas Gregora16548e2009-08-11 05:31:07 +00005831template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005832ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005833TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00005834 TypeSourceInfo *OldT = E->getTypeSourceInfo();
5835 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
5836 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00005837 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005838
John McCalldadc5752010-08-24 06:29:42 +00005839 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00005840 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005841 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005842
Douglas Gregora16548e2009-08-11 05:31:07 +00005843 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00005844 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005845 Init.get() == E->getInitializer())
John McCallc3007a22010-10-26 07:05:15 +00005846 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00005847
John McCall5d7aa7f2010-01-19 22:33:45 +00005848 // Note: the expression type doesn't necessarily match the
5849 // type-as-written, but that's okay, because it should always be
5850 // derivable from the initializer.
5851
John McCalle15bbff2010-01-18 19:35:47 +00005852 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00005853 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00005854 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005855}
Mike Stump11289f42009-09-09 15:08:12 +00005856
Douglas Gregora16548e2009-08-11 05:31:07 +00005857template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005858ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005859TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00005860 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00005861 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005862 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005863
Douglas Gregora16548e2009-08-11 05:31:07 +00005864 if (!getDerived().AlwaysRebuild() &&
5865 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00005866 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005867
Douglas Gregora16548e2009-08-11 05:31:07 +00005868 // FIXME: Bad source location
Mike Stump11289f42009-09-09 15:08:12 +00005869 SourceLocation FakeOperatorLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00005870 = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00005871 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00005872 E->getAccessorLoc(),
5873 E->getAccessor());
5874}
Mike Stump11289f42009-09-09 15:08:12 +00005875
Douglas Gregora16548e2009-08-11 05:31:07 +00005876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005877ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005878TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005879 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00005880
John McCall37ad5512010-08-23 06:44:23 +00005881 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00005882 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
5883 Inits, &InitChanged))
5884 return ExprError();
5885
Douglas Gregora16548e2009-08-11 05:31:07 +00005886 if (!getDerived().AlwaysRebuild() && !InitChanged)
John McCallc3007a22010-10-26 07:05:15 +00005887 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005888
Douglas Gregora16548e2009-08-11 05:31:07 +00005889 return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits),
Douglas Gregord3d93062009-11-09 17:16:50 +00005890 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00005891}
Mike Stump11289f42009-09-09 15:08:12 +00005892
Douglas Gregora16548e2009-08-11 05:31:07 +00005893template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005894ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005895TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00005896 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00005897
Douglas Gregorebe10102009-08-20 07:17:43 +00005898 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00005899 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00005900 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005901 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005902
Douglas Gregorebe10102009-08-20 07:17:43 +00005903 // transform the designators.
John McCall37ad5512010-08-23 06:44:23 +00005904 ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00005905 bool ExprChanged = false;
5906 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
5907 DEnd = E->designators_end();
5908 D != DEnd; ++D) {
5909 if (D->isFieldDesignator()) {
5910 Desig.AddDesignator(Designator::getField(D->getFieldName(),
5911 D->getDotLoc(),
5912 D->getFieldLoc()));
5913 continue;
5914 }
Mike Stump11289f42009-09-09 15:08:12 +00005915
Douglas Gregora16548e2009-08-11 05:31:07 +00005916 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00005917 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005918 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005919 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005920
5921 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005922 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005923
Douglas Gregora16548e2009-08-11 05:31:07 +00005924 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
5925 ArrayExprs.push_back(Index.release());
5926 continue;
5927 }
Mike Stump11289f42009-09-09 15:08:12 +00005928
Douglas Gregora16548e2009-08-11 05:31:07 +00005929 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00005930 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00005931 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
5932 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005933 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005934
John McCalldadc5752010-08-24 06:29:42 +00005935 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00005936 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005937 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005938
5939 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00005940 End.get(),
5941 D->getLBracketLoc(),
5942 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00005943
Douglas Gregora16548e2009-08-11 05:31:07 +00005944 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
5945 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00005946
Douglas Gregora16548e2009-08-11 05:31:07 +00005947 ArrayExprs.push_back(Start.release());
5948 ArrayExprs.push_back(End.release());
5949 }
Mike Stump11289f42009-09-09 15:08:12 +00005950
Douglas Gregora16548e2009-08-11 05:31:07 +00005951 if (!getDerived().AlwaysRebuild() &&
5952 Init.get() == E->getInit() &&
5953 !ExprChanged)
John McCallc3007a22010-10-26 07:05:15 +00005954 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005955
Douglas Gregora16548e2009-08-11 05:31:07 +00005956 return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs),
5957 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005958 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00005959}
Mike Stump11289f42009-09-09 15:08:12 +00005960
Douglas Gregora16548e2009-08-11 05:31:07 +00005961template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005962ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00005963TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00005964 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00005965 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Alexis Hunta8136cc2010-05-05 15:23:54 +00005966
Douglas Gregor3da3c062009-10-28 00:29:27 +00005967 // FIXME: Will we ever have proper type location here? Will we actually
5968 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00005969 QualType T = getDerived().TransformType(E->getType());
5970 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00005971 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005972
Douglas Gregora16548e2009-08-11 05:31:07 +00005973 if (!getDerived().AlwaysRebuild() &&
5974 T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00005975 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005976
Douglas Gregora16548e2009-08-11 05:31:07 +00005977 return getDerived().RebuildImplicitValueInitExpr(T);
5978}
Mike Stump11289f42009-09-09 15:08:12 +00005979
Douglas Gregora16548e2009-08-11 05:31:07 +00005980template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005981ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00005982TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00005983 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
5984 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00005985 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005986
John McCalldadc5752010-08-24 06:29:42 +00005987 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00005988 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005989 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00005990
Douglas Gregora16548e2009-08-11 05:31:07 +00005991 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00005992 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00005993 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00005994 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00005995
John McCallb268a282010-08-23 23:25:46 +00005996 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00005997 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00005998}
5999
6000template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006001ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006002TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006003 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006004 ASTOwningVector<Expr*, 4> Inits(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006005 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
6006 &ArgumentChanged))
6007 return ExprError();
6008
Douglas Gregora16548e2009-08-11 05:31:07 +00006009 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
6010 move_arg(Inits),
6011 E->getRParenLoc());
6012}
Mike Stump11289f42009-09-09 15:08:12 +00006013
Douglas Gregora16548e2009-08-11 05:31:07 +00006014/// \brief Transform an address-of-label expression.
6015///
6016/// By default, the transformation of an address-of-label expression always
6017/// rebuilds the expression, so that the label identifier can be resolved to
6018/// the corresponding label statement by semantic analysis.
6019template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006020ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006021TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006022 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
6023 E->getLabel());
6024 if (!LD)
6025 return ExprError();
6026
Douglas Gregora16548e2009-08-11 05:31:07 +00006027 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006028 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00006029}
Mike Stump11289f42009-09-09 15:08:12 +00006030
6031template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006032ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006033TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006034 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00006035 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
6036 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006037 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006038
Douglas Gregora16548e2009-08-11 05:31:07 +00006039 if (!getDerived().AlwaysRebuild() &&
6040 SubStmt.get() == E->getSubStmt())
John McCallc3007a22010-10-26 07:05:15 +00006041 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006042
6043 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006044 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006045 E->getRParenLoc());
6046}
Mike Stump11289f42009-09-09 15:08:12 +00006047
Douglas Gregora16548e2009-08-11 05:31:07 +00006048template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006049ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006050TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006051 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00006052 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006053 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006054
John McCalldadc5752010-08-24 06:29:42 +00006055 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006056 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006057 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006058
John McCalldadc5752010-08-24 06:29:42 +00006059 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00006060 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006061 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006062
Douglas Gregora16548e2009-08-11 05:31:07 +00006063 if (!getDerived().AlwaysRebuild() &&
6064 Cond.get() == E->getCond() &&
6065 LHS.get() == E->getLHS() &&
6066 RHS.get() == E->getRHS())
John McCallc3007a22010-10-26 07:05:15 +00006067 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006068
Douglas Gregora16548e2009-08-11 05:31:07 +00006069 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00006070 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006071 E->getRParenLoc());
6072}
Mike Stump11289f42009-09-09 15:08:12 +00006073
Douglas Gregora16548e2009-08-11 05:31:07 +00006074template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006075ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006076TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006077 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006078}
6079
6080template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006081ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006082TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006083 switch (E->getOperator()) {
6084 case OO_New:
6085 case OO_Delete:
6086 case OO_Array_New:
6087 case OO_Array_Delete:
6088 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
John McCallfaf5fb42010-08-26 23:41:50 +00006089 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006090
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006091 case OO_Call: {
6092 // This is a call to an object's operator().
6093 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
6094
6095 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00006096 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006097 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006098 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006099
6100 // FIXME: Poor location information
6101 SourceLocation FakeLParenLoc
6102 = SemaRef.PP.getLocForEndOfToken(
6103 static_cast<Expr *>(Object.get())->getLocEnd());
6104
6105 // Transform the call arguments.
John McCall37ad5512010-08-23 06:44:23 +00006106 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006107 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
6108 Args))
6109 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006110
John McCallb268a282010-08-23 23:25:46 +00006111 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006112 move_arg(Args),
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006113 E->getLocEnd());
6114 }
6115
6116#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
6117 case OO_##Name:
6118#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
6119#include "clang/Basic/OperatorKinds.def"
6120 case OO_Subscript:
6121 // Handled below.
6122 break;
6123
6124 case OO_Conditional:
6125 llvm_unreachable("conditional operator is not actually overloadable");
John McCallfaf5fb42010-08-26 23:41:50 +00006126 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006127
6128 case OO_None:
6129 case NUM_OVERLOADED_OPERATORS:
6130 llvm_unreachable("not an overloaded operator?");
John McCallfaf5fb42010-08-26 23:41:50 +00006131 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00006132 }
6133
John McCalldadc5752010-08-24 06:29:42 +00006134 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00006135 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006136 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006137
John McCalldadc5752010-08-24 06:29:42 +00006138 ExprResult First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00006139 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006140 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006141
John McCalldadc5752010-08-24 06:29:42 +00006142 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00006143 if (E->getNumArgs() == 2) {
6144 Second = getDerived().TransformExpr(E->getArg(1));
6145 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006146 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006147 }
Mike Stump11289f42009-09-09 15:08:12 +00006148
Douglas Gregora16548e2009-08-11 05:31:07 +00006149 if (!getDerived().AlwaysRebuild() &&
6150 Callee.get() == E->getCallee() &&
6151 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00006152 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
John McCallc3007a22010-10-26 07:05:15 +00006153 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006154
Douglas Gregora16548e2009-08-11 05:31:07 +00006155 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
6156 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00006157 Callee.get(),
6158 First.get(),
6159 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006160}
Mike Stump11289f42009-09-09 15:08:12 +00006161
Douglas Gregora16548e2009-08-11 05:31:07 +00006162template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006163ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006164TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
6165 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006166}
Mike Stump11289f42009-09-09 15:08:12 +00006167
Douglas Gregora16548e2009-08-11 05:31:07 +00006168template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006169ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00006170TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
6171 // Transform the callee.
6172 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
6173 if (Callee.isInvalid())
6174 return ExprError();
6175
6176 // Transform exec config.
6177 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
6178 if (EC.isInvalid())
6179 return ExprError();
6180
6181 // Transform arguments.
6182 bool ArgChanged = false;
6183 ASTOwningVector<Expr*> Args(SemaRef);
6184 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6185 &ArgChanged))
6186 return ExprError();
6187
6188 if (!getDerived().AlwaysRebuild() &&
6189 Callee.get() == E->getCallee() &&
6190 !ArgChanged)
6191 return SemaRef.Owned(E);
6192
6193 // FIXME: Wrong source location information for the '('.
6194 SourceLocation FakeLParenLoc
6195 = ((Expr *)Callee.get())->getSourceRange().getBegin();
6196 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
6197 move_arg(Args),
6198 E->getRParenLoc(), EC.get());
6199}
6200
6201template<typename Derived>
6202ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006203TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006204 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6205 if (!Type)
6206 return ExprError();
6207
John McCalldadc5752010-08-24 06:29:42 +00006208 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006209 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006210 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006211 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006212
Douglas Gregora16548e2009-08-11 05:31:07 +00006213 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006214 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006215 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006216 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006217
Douglas Gregora16548e2009-08-11 05:31:07 +00006218 // FIXME: Poor source location information here.
Mike Stump11289f42009-09-09 15:08:12 +00006219 SourceLocation FakeLAngleLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00006220 = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc());
6221 SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin();
6222 SourceLocation FakeRParenLoc
6223 = SemaRef.PP.getLocForEndOfToken(
6224 E->getSubExpr()->getSourceRange().getEnd());
6225 return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(),
Mike Stump11289f42009-09-09 15:08:12 +00006226 E->getStmtClass(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006227 FakeLAngleLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006228 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006229 FakeRAngleLoc,
6230 FakeRAngleLoc,
John McCallb268a282010-08-23 23:25:46 +00006231 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006232 FakeRParenLoc);
6233}
Mike Stump11289f42009-09-09 15:08:12 +00006234
Douglas Gregora16548e2009-08-11 05:31:07 +00006235template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006236ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006237TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
6238 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006239}
Mike Stump11289f42009-09-09 15:08:12 +00006240
6241template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006242ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006243TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
6244 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00006245}
6246
Douglas Gregora16548e2009-08-11 05:31:07 +00006247template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006248ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006249TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006250 CXXReinterpretCastExpr *E) {
6251 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006252}
Mike Stump11289f42009-09-09 15:08:12 +00006253
Douglas Gregora16548e2009-08-11 05:31:07 +00006254template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006255ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006256TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
6257 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006258}
Mike Stump11289f42009-09-09 15:08:12 +00006259
Douglas Gregora16548e2009-08-11 05:31:07 +00006260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006261ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006262TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006263 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006264 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
6265 if (!Type)
6266 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006267
John McCalldadc5752010-08-24 06:29:42 +00006268 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00006269 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00006270 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006271 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006272
Douglas Gregora16548e2009-08-11 05:31:07 +00006273 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006274 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006275 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006276 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006277
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006278 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00006279 /*FIXME:*/E->getSubExpr()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006280 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006281 E->getRParenLoc());
6282}
Mike Stump11289f42009-09-09 15:08:12 +00006283
Douglas Gregora16548e2009-08-11 05:31:07 +00006284template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006285ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006286TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006287 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00006288 TypeSourceInfo *TInfo
6289 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6290 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006291 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006292
Douglas Gregora16548e2009-08-11 05:31:07 +00006293 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00006294 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006295 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006296
Douglas Gregor9da64192010-04-26 22:37:10 +00006297 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6298 E->getLocStart(),
6299 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00006300 E->getLocEnd());
6301 }
Mike Stump11289f42009-09-09 15:08:12 +00006302
Douglas Gregora16548e2009-08-11 05:31:07 +00006303 // We don't know whether the expression is potentially evaluated until
6304 // after we perform semantic analysis, so the expression is potentially
6305 // potentially evaluated.
Mike Stump11289f42009-09-09 15:08:12 +00006306 EnterExpressionEvaluationContext Unevaluated(SemaRef,
John McCallfaf5fb42010-08-26 23:41:50 +00006307 Sema::PotentiallyPotentiallyEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00006308
John McCalldadc5752010-08-24 06:29:42 +00006309 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00006310 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006311 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006312
Douglas Gregora16548e2009-08-11 05:31:07 +00006313 if (!getDerived().AlwaysRebuild() &&
6314 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006315 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006316
Douglas Gregor9da64192010-04-26 22:37:10 +00006317 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6318 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00006319 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006320 E->getLocEnd());
6321}
6322
6323template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006324ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00006325TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
6326 if (E->isTypeOperand()) {
6327 TypeSourceInfo *TInfo
6328 = getDerived().TransformType(E->getTypeOperandSourceInfo());
6329 if (!TInfo)
6330 return ExprError();
6331
6332 if (!getDerived().AlwaysRebuild() &&
6333 TInfo == E->getTypeOperandSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006334 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006335
6336 return getDerived().RebuildCXXTypeidExpr(E->getType(),
6337 E->getLocStart(),
6338 TInfo,
6339 E->getLocEnd());
6340 }
6341
6342 // We don't know whether the expression is potentially evaluated until
6343 // after we perform semantic analysis, so the expression is potentially
6344 // potentially evaluated.
6345 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
6346
6347 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
6348 if (SubExpr.isInvalid())
6349 return ExprError();
6350
6351 if (!getDerived().AlwaysRebuild() &&
6352 SubExpr.get() == E->getExprOperand())
John McCallc3007a22010-10-26 07:05:15 +00006353 return SemaRef.Owned(E);
Francois Pichet9f4f2072010-09-08 12:20:18 +00006354
6355 return getDerived().RebuildCXXUuidofExpr(E->getType(),
6356 E->getLocStart(),
6357 SubExpr.get(),
6358 E->getLocEnd());
6359}
6360
6361template<typename Derived>
6362ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006363TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006364 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006365}
Mike Stump11289f42009-09-09 15:08:12 +00006366
Douglas Gregora16548e2009-08-11 05:31:07 +00006367template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006368ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006369TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006370 CXXNullPtrLiteralExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00006371 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006372}
Mike Stump11289f42009-09-09 15:08:12 +00006373
Douglas Gregora16548e2009-08-11 05:31:07 +00006374template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006375ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006376TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006377 DeclContext *DC = getSema().getFunctionLevelDeclContext();
6378 CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC);
6379 QualType T = MD->getThisType(getSema().Context);
Mike Stump11289f42009-09-09 15:08:12 +00006380
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00006381 if (!getDerived().AlwaysRebuild() && T == E->getType())
John McCallc3007a22010-10-26 07:05:15 +00006382 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006383
Douglas Gregorb15af892010-01-07 23:12:05 +00006384 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00006385}
Mike Stump11289f42009-09-09 15:08:12 +00006386
Douglas Gregora16548e2009-08-11 05:31:07 +00006387template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006388ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006389TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006390 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006391 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006392 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006393
Douglas Gregora16548e2009-08-11 05:31:07 +00006394 if (!getDerived().AlwaysRebuild() &&
6395 SubExpr.get() == E->getSubExpr())
John McCallc3007a22010-10-26 07:05:15 +00006396 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00006397
John McCallb268a282010-08-23 23:25:46 +00006398 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006399}
Mike Stump11289f42009-09-09 15:08:12 +00006400
Douglas Gregora16548e2009-08-11 05:31:07 +00006401template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006402ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006403TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00006404 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006405 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
6406 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006407 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00006408 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006409
Chandler Carruth794da4c2010-02-08 06:42:49 +00006410 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006411 Param == E->getParam())
John McCallc3007a22010-10-26 07:05:15 +00006412 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006413
Douglas Gregor033f6752009-12-23 23:03:06 +00006414 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00006415}
Mike Stump11289f42009-09-09 15:08:12 +00006416
Douglas Gregora16548e2009-08-11 05:31:07 +00006417template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006418ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00006419TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
6420 CXXScalarValueInitExpr *E) {
6421 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6422 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006423 return ExprError();
Douglas Gregor2b88c112010-09-08 00:15:04 +00006424
Douglas Gregora16548e2009-08-11 05:31:07 +00006425 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006426 T == E->getTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006427 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006428
Douglas Gregor2b88c112010-09-08 00:15:04 +00006429 return getDerived().RebuildCXXScalarValueInitExpr(T,
6430 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00006431 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00006432}
Mike Stump11289f42009-09-09 15:08:12 +00006433
Douglas Gregora16548e2009-08-11 05:31:07 +00006434template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006435ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006436TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006437 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00006438 TypeSourceInfo *AllocTypeInfo
6439 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
6440 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006441 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006442
Douglas Gregora16548e2009-08-11 05:31:07 +00006443 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00006444 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00006445 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006446 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006447
Douglas Gregora16548e2009-08-11 05:31:07 +00006448 // Transform the placement arguments (if any).
6449 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006450 ASTOwningVector<Expr*> PlacementArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006451 if (getDerived().TransformExprs(E->getPlacementArgs(),
6452 E->getNumPlacementArgs(), true,
6453 PlacementArgs, &ArgumentChanged))
6454 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006455
Douglas Gregorebe10102009-08-20 07:17:43 +00006456 // transform the constructor arguments (if any).
John McCall37ad5512010-08-23 06:44:23 +00006457 ASTOwningVector<Expr*> ConstructorArgs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006458 if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true,
6459 ConstructorArgs, &ArgumentChanged))
6460 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006461
Douglas Gregord2d9da02010-02-26 00:38:10 +00006462 // Transform constructor, new operator, and delete operator.
6463 CXXConstructorDecl *Constructor = 0;
6464 if (E->getConstructor()) {
6465 Constructor = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006466 getDerived().TransformDecl(E->getLocStart(),
6467 E->getConstructor()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006468 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006469 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006470 }
6471
6472 FunctionDecl *OperatorNew = 0;
6473 if (E->getOperatorNew()) {
6474 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006475 getDerived().TransformDecl(E->getLocStart(),
6476 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006477 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00006478 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006479 }
6480
6481 FunctionDecl *OperatorDelete = 0;
6482 if (E->getOperatorDelete()) {
6483 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006484 getDerived().TransformDecl(E->getLocStart(),
6485 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006486 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006487 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006488 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006489
Douglas Gregora16548e2009-08-11 05:31:07 +00006490 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00006491 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006492 ArraySize.get() == E->getArraySize() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006493 Constructor == E->getConstructor() &&
6494 OperatorNew == E->getOperatorNew() &&
6495 OperatorDelete == E->getOperatorDelete() &&
6496 !ArgumentChanged) {
6497 // Mark any declarations we need as referenced.
6498 // FIXME: instantiation-specific.
6499 if (Constructor)
6500 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
6501 if (OperatorNew)
6502 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew);
6503 if (OperatorDelete)
6504 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
John McCallc3007a22010-10-26 07:05:15 +00006505 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006506 }
Mike Stump11289f42009-09-09 15:08:12 +00006507
Douglas Gregor0744ef62010-09-07 21:49:58 +00006508 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006509 if (!ArraySize.get()) {
6510 // If no array size was specified, but the new expression was
6511 // instantiated with an array type (e.g., "new T" where T is
6512 // instantiated with "int[4]"), extract the outer bound from the
6513 // array type as our array size. We do this with constant and
6514 // dependently-sized array types.
6515 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
6516 if (!ArrayT) {
6517 // Do nothing
6518 } else if (const ConstantArrayType *ConsArrayT
6519 = dyn_cast<ConstantArrayType>(ArrayT)) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00006520 ArraySize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00006521 = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context,
6522 ConsArrayT->getSize(),
6523 SemaRef.Context.getSizeType(),
6524 /*FIXME:*/E->getLocStart()));
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006525 AllocType = ConsArrayT->getElementType();
6526 } else if (const DependentSizedArrayType *DepArrayT
6527 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
6528 if (DepArrayT->getSizeExpr()) {
John McCallc3007a22010-10-26 07:05:15 +00006529 ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00006530 AllocType = DepArrayT->getElementType();
6531 }
6532 }
6533 }
Douglas Gregor0744ef62010-09-07 21:49:58 +00006534
Douglas Gregora16548e2009-08-11 05:31:07 +00006535 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
6536 E->isGlobalNew(),
6537 /*FIXME:*/E->getLocStart(),
6538 move_arg(PlacementArgs),
6539 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00006540 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006541 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00006542 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00006543 ArraySize.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006544 /*FIXME:*/E->getLocStart(),
6545 move_arg(ConstructorArgs),
Mike Stump11289f42009-09-09 15:08:12 +00006546 E->getLocEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00006547}
Mike Stump11289f42009-09-09 15:08:12 +00006548
Douglas Gregora16548e2009-08-11 05:31:07 +00006549template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006550ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006551TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006552 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00006553 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006554 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006555
Douglas Gregord2d9da02010-02-26 00:38:10 +00006556 // Transform the delete operator, if known.
6557 FunctionDecl *OperatorDelete = 0;
6558 if (E->getOperatorDelete()) {
6559 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006560 getDerived().TransformDecl(E->getLocStart(),
6561 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00006562 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00006563 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00006564 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006565
Douglas Gregora16548e2009-08-11 05:31:07 +00006566 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00006567 Operand.get() == E->getArgument() &&
6568 OperatorDelete == E->getOperatorDelete()) {
6569 // Mark any declarations we need as referenced.
6570 // FIXME: instantiation-specific.
6571 if (OperatorDelete)
6572 SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete);
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00006573
6574 if (!E->getArgument()->isTypeDependent()) {
6575 QualType Destroyed = SemaRef.Context.getBaseElementType(
6576 E->getDestroyedType());
6577 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
6578 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
6579 SemaRef.MarkDeclarationReferenced(E->getLocStart(),
6580 SemaRef.LookupDestructor(Record));
6581 }
6582 }
6583
John McCallc3007a22010-10-26 07:05:15 +00006584 return SemaRef.Owned(E);
Douglas Gregord2d9da02010-02-26 00:38:10 +00006585 }
Mike Stump11289f42009-09-09 15:08:12 +00006586
Douglas Gregora16548e2009-08-11 05:31:07 +00006587 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
6588 E->isGlobalDelete(),
6589 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00006590 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00006591}
Mike Stump11289f42009-09-09 15:08:12 +00006592
Douglas Gregora16548e2009-08-11 05:31:07 +00006593template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006594ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00006595TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006596 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00006597 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00006598 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006599 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006600
John McCallba7bf592010-08-24 05:47:05 +00006601 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00006602 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006603 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006604 E->getOperatorLoc(),
6605 E->isArrow()? tok::arrow : tok::period,
6606 ObjectTypePtr,
6607 MayBePseudoDestructor);
6608 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006609 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006610
John McCallba7bf592010-08-24 05:47:05 +00006611 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00006612 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
6613 if (QualifierLoc) {
6614 QualifierLoc
6615 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
6616 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00006617 return ExprError();
6618 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00006619 CXXScopeSpec SS;
6620 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00006621
Douglas Gregor678f90d2010-02-25 01:56:36 +00006622 PseudoDestructorTypeStorage Destroyed;
6623 if (E->getDestroyedTypeInfo()) {
6624 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00006625 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006626 ObjectType, 0,
6627 QualifierLoc.getNestedNameSpecifier());
Douglas Gregor678f90d2010-02-25 01:56:36 +00006628 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006629 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00006630 Destroyed = DestroyedTypeInfo;
6631 } else if (ObjectType->isDependentType()) {
6632 // We aren't likely to be able to resolve the identifier down to a type
6633 // now anyway, so just retain the identifier.
6634 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
6635 E->getDestroyedTypeLoc());
6636 } else {
6637 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00006638 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006639 *E->getDestroyedTypeIdentifier(),
6640 E->getDestroyedTypeLoc(),
6641 /*Scope=*/0,
6642 SS, ObjectTypePtr,
6643 false);
6644 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006645 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006646
Douglas Gregor678f90d2010-02-25 01:56:36 +00006647 Destroyed
6648 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
6649 E->getDestroyedTypeLoc());
6650 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006651
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006652 TypeSourceInfo *ScopeTypeInfo = 0;
6653 if (E->getScopeTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00006654 ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo());
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006655 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006656 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00006657 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00006658
John McCallb268a282010-08-23 23:25:46 +00006659 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00006660 E->getOperatorLoc(),
6661 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00006662 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00006663 ScopeTypeInfo,
6664 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00006665 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00006666 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00006667}
Mike Stump11289f42009-09-09 15:08:12 +00006668
Douglas Gregorad8a3362009-09-04 17:36:40 +00006669template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006670ExprResult
John McCalld14a8642009-11-21 08:51:07 +00006671TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006672 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00006673 TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName());
6674
6675 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
6676 Sema::LookupOrdinaryName);
6677
6678 // Transform all the decls.
6679 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
6680 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006681 NamedDecl *InstD = static_cast<NamedDecl*>(
6682 getDerived().TransformDecl(Old->getNameLoc(),
6683 *I));
John McCall84d87672009-12-10 09:41:52 +00006684 if (!InstD) {
6685 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
6686 // This can happen because of dependent hiding.
6687 if (isa<UsingShadowDecl>(*I))
6688 continue;
6689 else
John McCallfaf5fb42010-08-26 23:41:50 +00006690 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00006691 }
John McCalle66edc12009-11-24 19:00:30 +00006692
6693 // Expand using declarations.
6694 if (isa<UsingDecl>(InstD)) {
6695 UsingDecl *UD = cast<UsingDecl>(InstD);
6696 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
6697 E = UD->shadow_end(); I != E; ++I)
6698 R.addDecl(*I);
6699 continue;
6700 }
6701
6702 R.addDecl(InstD);
6703 }
6704
6705 // Resolve a kind, but don't do any further analysis. If it's
6706 // ambiguous, the callee needs to deal with it.
6707 R.resolveKind();
6708
6709 // Rebuild the nested-name qualifier, if present.
6710 CXXScopeSpec SS;
6711 NestedNameSpecifier *Qualifier = 0;
6712 if (Old->getQualifier()) {
6713 Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006714 Old->getQualifierRange());
John McCalle66edc12009-11-24 19:00:30 +00006715 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00006716 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006717
Douglas Gregor869ad452011-02-24 17:54:50 +00006718 SS.MakeTrivial(SemaRef.Context, Qualifier, Old->getQualifierRange());
Alexis Hunta8136cc2010-05-05 15:23:54 +00006719 }
6720
Douglas Gregor9262f472010-04-27 18:19:34 +00006721 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00006722 CXXRecordDecl *NamingClass
6723 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
6724 Old->getNameLoc(),
6725 Old->getNamingClass()));
6726 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00006727 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00006728
Douglas Gregorda7be082010-04-27 16:10:10 +00006729 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00006730 }
6731
6732 // If we have no template arguments, it's a normal declaration name.
6733 if (!Old->hasExplicitTemplateArgs())
6734 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
6735
6736 // If we have template arguments, rebuild them, then rebuild the
6737 // templateid expression.
6738 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006739 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
6740 Old->getNumTemplateArgs(),
6741 TransArgs))
6742 return ExprError();
John McCalle66edc12009-11-24 19:00:30 +00006743
6744 return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(),
6745 TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006746}
Mike Stump11289f42009-09-09 15:08:12 +00006747
Douglas Gregora16548e2009-08-11 05:31:07 +00006748template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006749ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006750TreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) {
Douglas Gregor54e5b132010-09-09 16:14:44 +00006751 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
6752 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006753 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006754
Douglas Gregora16548e2009-08-11 05:31:07 +00006755 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor54e5b132010-09-09 16:14:44 +00006756 T == E->getQueriedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00006757 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006758
Mike Stump11289f42009-09-09 15:08:12 +00006759 return getDerived().RebuildUnaryTypeTrait(E->getTrait(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006760 E->getLocStart(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006761 T,
6762 E->getLocEnd());
6763}
Mike Stump11289f42009-09-09 15:08:12 +00006764
Douglas Gregora16548e2009-08-11 05:31:07 +00006765template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006766ExprResult
Francois Pichet9dfa3ce2010-12-07 00:08:36 +00006767TreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) {
6768 TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo());
6769 if (!LhsT)
6770 return ExprError();
6771
6772 TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo());
6773 if (!RhsT)
6774 return ExprError();
6775
6776 if (!getDerived().AlwaysRebuild() &&
6777 LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo())
6778 return SemaRef.Owned(E);
6779
6780 return getDerived().RebuildBinaryTypeTrait(E->getTrait(),
6781 E->getLocStart(),
6782 LhsT, RhsT,
6783 E->getLocEnd());
6784}
6785
6786template<typename Derived>
6787ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006788TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006789 DependentScopeDeclRefExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006790 NestedNameSpecifier *NNS
Douglas Gregord019ff62009-10-22 17:20:55 +00006791 = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00006792 E->getQualifierRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006793 if (!NNS)
John McCallfaf5fb42010-08-26 23:41:50 +00006794 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006795
John McCall31f82722010-11-12 08:19:04 +00006796 // TODO: If this is a conversion-function-id, verify that the
6797 // destination type name (if present) resolves the same way after
6798 // instantiation as it did in the local scope.
6799
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006800 DeclarationNameInfo NameInfo
6801 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
6802 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00006803 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006804
John McCalle66edc12009-11-24 19:00:30 +00006805 if (!E->hasExplicitTemplateArgs()) {
6806 if (!getDerived().AlwaysRebuild() &&
6807 NNS == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006808 // Note: it is sufficient to compare the Name component of NameInfo:
6809 // if name has not changed, DNLoc has not changed either.
6810 NameInfo.getName() == E->getDeclName())
John McCallc3007a22010-10-26 07:05:15 +00006811 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006812
John McCalle66edc12009-11-24 19:00:30 +00006813 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6814 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006815 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006816 /*TemplateArgs*/ 0);
Douglas Gregord019ff62009-10-22 17:20:55 +00006817 }
John McCall6b51f282009-11-23 01:53:49 +00006818
6819 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00006820 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
6821 E->getNumTemplateArgs(),
6822 TransArgs))
6823 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006824
John McCalle66edc12009-11-24 19:00:30 +00006825 return getDerived().RebuildDependentScopeDeclRefExpr(NNS,
6826 E->getQualifierRange(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006827 NameInfo,
John McCalle66edc12009-11-24 19:00:30 +00006828 &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00006829}
6830
6831template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006832ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006833TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Douglas Gregordb56b912010-02-03 03:01:57 +00006834 // CXXConstructExprs are always implicit, so when we have a
6835 // 1-argument construction we just transform that argument.
6836 if (E->getNumArgs() == 1 ||
6837 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1))))
6838 return getDerived().TransformExpr(E->getArg(0));
6839
Douglas Gregora16548e2009-08-11 05:31:07 +00006840 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
6841
6842 QualType T = getDerived().TransformType(E->getType());
6843 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00006844 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00006845
6846 CXXConstructorDecl *Constructor
6847 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006848 getDerived().TransformDecl(E->getLocStart(),
6849 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006850 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006851 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006852
Douglas Gregora16548e2009-08-11 05:31:07 +00006853 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006854 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006855 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6856 &ArgumentChanged))
6857 return ExprError();
6858
Douglas Gregora16548e2009-08-11 05:31:07 +00006859 if (!getDerived().AlwaysRebuild() &&
6860 T == E->getType() &&
6861 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00006862 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00006863 // Mark the constructor as referenced.
6864 // FIXME: Instantiation-specific
Douglas Gregorde550352010-02-26 00:01:57 +00006865 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006866 return SemaRef.Owned(E);
Douglas Gregorde550352010-02-26 00:01:57 +00006867 }
Mike Stump11289f42009-09-09 15:08:12 +00006868
Douglas Gregordb121ba2009-12-14 16:27:04 +00006869 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
6870 Constructor, E->isElidable(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00006871 move_arg(Args),
6872 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00006873 E->getConstructionKind(),
6874 E->getParenRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00006875}
Mike Stump11289f42009-09-09 15:08:12 +00006876
Douglas Gregora16548e2009-08-11 05:31:07 +00006877/// \brief Transform a C++ temporary-binding expression.
6878///
Douglas Gregor363b1512009-12-24 18:51:59 +00006879/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
6880/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006881template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006882ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00006883TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006884 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006885}
Mike Stump11289f42009-09-09 15:08:12 +00006886
John McCall5d413782010-12-06 08:20:24 +00006887/// \brief Transform a C++ expression that contains cleanups that should
6888/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00006889///
John McCall5d413782010-12-06 08:20:24 +00006890/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00006891/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00006892template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006893ExprResult
John McCall5d413782010-12-06 08:20:24 +00006894TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00006895 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00006896}
Mike Stump11289f42009-09-09 15:08:12 +00006897
Douglas Gregora16548e2009-08-11 05:31:07 +00006898template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006899ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006900TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00006901 CXXTemporaryObjectExpr *E) {
6902 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6903 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006904 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006905
Douglas Gregora16548e2009-08-11 05:31:07 +00006906 CXXConstructorDecl *Constructor
6907 = cast_or_null<CXXConstructorDecl>(
Alexis Hunta8136cc2010-05-05 15:23:54 +00006908 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00006909 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00006910 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00006911 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006912
Douglas Gregora16548e2009-08-11 05:31:07 +00006913 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006914 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora16548e2009-08-11 05:31:07 +00006915 Args.reserve(E->getNumArgs());
Douglas Gregora3efea12011-01-03 19:04:46 +00006916 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
6917 &ArgumentChanged))
6918 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006919
Douglas Gregora16548e2009-08-11 05:31:07 +00006920 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006921 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006922 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006923 !ArgumentChanged) {
6924 // FIXME: Instantiation-specific
Douglas Gregor2b88c112010-09-08 00:15:04 +00006925 SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00006926 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00006927 }
Douglas Gregor2b88c112010-09-08 00:15:04 +00006928
6929 return getDerived().RebuildCXXTemporaryObjectExpr(T,
6930 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregora16548e2009-08-11 05:31:07 +00006931 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006932 E->getLocEnd());
6933}
Mike Stump11289f42009-09-09 15:08:12 +00006934
Douglas Gregora16548e2009-08-11 05:31:07 +00006935template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006936ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00006937TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00006938 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00006939 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
6940 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006941 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006942
Douglas Gregora16548e2009-08-11 05:31:07 +00006943 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00006944 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00006945 Args.reserve(E->arg_size());
6946 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
6947 &ArgumentChanged))
6948 return ExprError();
6949
Douglas Gregora16548e2009-08-11 05:31:07 +00006950 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00006951 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00006952 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00006953 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00006954
Douglas Gregora16548e2009-08-11 05:31:07 +00006955 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00006956 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00006957 E->getLParenLoc(),
6958 move_arg(Args),
Douglas Gregora16548e2009-08-11 05:31:07 +00006959 E->getRParenLoc());
6960}
Mike Stump11289f42009-09-09 15:08:12 +00006961
Douglas Gregora16548e2009-08-11 05:31:07 +00006962template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006963ExprResult
John McCall8cd78132009-11-19 22:55:06 +00006964TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00006965 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00006966 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00006967 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00006968 Expr *OldBase;
6969 QualType BaseType;
6970 QualType ObjectType;
6971 if (!E->isImplicitAccess()) {
6972 OldBase = E->getBase();
6973 Base = getDerived().TransformExpr(OldBase);
6974 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006975 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00006976
John McCall2d74de92009-12-01 22:10:20 +00006977 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00006978 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00006979 bool MayBePseudoDestructor = false;
John McCallb268a282010-08-23 23:25:46 +00006980 Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00006981 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00006982 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00006983 ObjectTy,
6984 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00006985 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006986 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00006987
John McCallba7bf592010-08-24 05:47:05 +00006988 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00006989 BaseType = ((Expr*) Base.get())->getType();
6990 } else {
6991 OldBase = 0;
6992 BaseType = getDerived().TransformType(E->getBaseType());
6993 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
6994 }
Mike Stump11289f42009-09-09 15:08:12 +00006995
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006996 // Transform the first part of the nested-name-specifier that qualifies
6997 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00006998 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00006999 = getDerived().TransformFirstQualifierInScope(
7000 E->getFirstQualifierFoundInScope(),
7001 E->getQualifierRange().getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007002
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007003 NestedNameSpecifier *Qualifier = 0;
7004 if (E->getQualifier()) {
7005 Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(),
7006 E->getQualifierRange(),
John McCall2d74de92009-12-01 22:10:20 +00007007 ObjectType,
7008 FirstQualifierInScope);
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007009 if (!Qualifier)
John McCallfaf5fb42010-08-26 23:41:50 +00007010 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007011 }
Mike Stump11289f42009-09-09 15:08:12 +00007012
John McCall31f82722010-11-12 08:19:04 +00007013 // TODO: If this is a conversion-function-id, verify that the
7014 // destination type name (if present) resolves the same way after
7015 // instantiation as it did in the local scope.
7016
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007017 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00007018 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007019 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007020 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007021
John McCall2d74de92009-12-01 22:10:20 +00007022 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00007023 // This is a reference to a member without an explicitly-specified
7024 // template argument list. Optimize for this common case.
7025 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00007026 Base.get() == OldBase &&
7027 BaseType == E->getBaseType() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007028 Qualifier == E->getQualifier() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007029 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00007030 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
John McCallc3007a22010-10-26 07:05:15 +00007031 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007032
John McCallb268a282010-08-23 23:25:46 +00007033 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007034 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00007035 E->isArrow(),
7036 E->getOperatorLoc(),
7037 Qualifier,
7038 E->getQualifierRange(),
John McCall10eae182009-11-30 22:42:35 +00007039 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007040 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007041 /*TemplateArgs*/ 0);
Douglas Gregor308047d2009-09-09 00:23:06 +00007042 }
7043
John McCall6b51f282009-11-23 01:53:49 +00007044 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007045 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7046 E->getNumTemplateArgs(),
7047 TransArgs))
7048 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007049
John McCallb268a282010-08-23 23:25:46 +00007050 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007051 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00007052 E->isArrow(),
7053 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007054 Qualifier,
7055 E->getQualifierRange(),
Douglas Gregor308047d2009-09-09 00:23:06 +00007056 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007057 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00007058 &TransArgs);
7059}
7060
7061template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007062ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007063TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00007064 // Transform the base of the expression.
John McCalldadc5752010-08-24 06:29:42 +00007065 ExprResult Base((Expr*) 0);
John McCall2d74de92009-12-01 22:10:20 +00007066 QualType BaseType;
7067 if (!Old->isImplicitAccess()) {
7068 Base = getDerived().TransformExpr(Old->getBase());
7069 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007070 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00007071 BaseType = ((Expr*) Base.get())->getType();
7072 } else {
7073 BaseType = getDerived().TransformType(Old->getBaseType());
7074 }
John McCall10eae182009-11-30 22:42:35 +00007075
7076 NestedNameSpecifier *Qualifier = 0;
7077 if (Old->getQualifier()) {
7078 Qualifier
7079 = getDerived().TransformNestedNameSpecifier(Old->getQualifier(),
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007080 Old->getQualifierRange());
John McCall10eae182009-11-30 22:42:35 +00007081 if (Qualifier == 0)
John McCallfaf5fb42010-08-26 23:41:50 +00007082 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007083 }
7084
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007085 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00007086 Sema::LookupOrdinaryName);
7087
7088 // Transform all the decls.
7089 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
7090 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007091 NamedDecl *InstD = static_cast<NamedDecl*>(
7092 getDerived().TransformDecl(Old->getMemberLoc(),
7093 *I));
John McCall84d87672009-12-10 09:41:52 +00007094 if (!InstD) {
7095 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
7096 // This can happen because of dependent hiding.
7097 if (isa<UsingShadowDecl>(*I))
7098 continue;
7099 else
John McCallfaf5fb42010-08-26 23:41:50 +00007100 return ExprError();
John McCall84d87672009-12-10 09:41:52 +00007101 }
John McCall10eae182009-11-30 22:42:35 +00007102
7103 // Expand using declarations.
7104 if (isa<UsingDecl>(InstD)) {
7105 UsingDecl *UD = cast<UsingDecl>(InstD);
7106 for (UsingDecl::shadow_iterator I = UD->shadow_begin(),
7107 E = UD->shadow_end(); I != E; ++I)
7108 R.addDecl(*I);
7109 continue;
7110 }
7111
7112 R.addDecl(InstD);
7113 }
7114
7115 R.resolveKind();
7116
Douglas Gregor9262f472010-04-27 18:19:34 +00007117 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00007118 if (Old->getNamingClass()) {
Alexis Hunta8136cc2010-05-05 15:23:54 +00007119 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00007120 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00007121 Old->getMemberLoc(),
7122 Old->getNamingClass()));
7123 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00007124 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007125
Douglas Gregorda7be082010-04-27 16:10:10 +00007126 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00007127 }
Alexis Hunta8136cc2010-05-05 15:23:54 +00007128
John McCall10eae182009-11-30 22:42:35 +00007129 TemplateArgumentListInfo TransArgs;
7130 if (Old->hasExplicitTemplateArgs()) {
7131 TransArgs.setLAngleLoc(Old->getLAngleLoc());
7132 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007133 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
7134 Old->getNumTemplateArgs(),
7135 TransArgs))
7136 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00007137 }
John McCall38836f02010-01-15 08:34:02 +00007138
7139 // FIXME: to do this check properly, we will need to preserve the
7140 // first-qualifier-in-scope here, just in case we had a dependent
7141 // base (and therefore couldn't do the check) and a
7142 // nested-name-qualifier (and therefore could do the lookup).
7143 NamedDecl *FirstQualifierInScope = 0;
Alexis Hunta8136cc2010-05-05 15:23:54 +00007144
John McCallb268a282010-08-23 23:25:46 +00007145 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00007146 BaseType,
John McCall10eae182009-11-30 22:42:35 +00007147 Old->getOperatorLoc(),
7148 Old->isArrow(),
7149 Qualifier,
7150 Old->getQualifierRange(),
John McCall38836f02010-01-15 08:34:02 +00007151 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00007152 R,
7153 (Old->hasExplicitTemplateArgs()
7154 ? &TransArgs : 0));
Douglas Gregora16548e2009-08-11 05:31:07 +00007155}
7156
7157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007158ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007159TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
7160 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
7161 if (SubExpr.isInvalid())
7162 return ExprError();
7163
7164 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
John McCallc3007a22010-10-26 07:05:15 +00007165 return SemaRef.Owned(E);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00007166
7167 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
7168}
7169
7170template<typename Derived>
7171ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007172TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00007173 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
7174 if (Pattern.isInvalid())
7175 return ExprError();
7176
7177 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
7178 return SemaRef.Owned(E);
7179
Douglas Gregorb8840002011-01-14 21:20:45 +00007180 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
7181 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007182}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007183
7184template<typename Derived>
7185ExprResult
7186TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
7187 // If E is not value-dependent, then nothing will change when we transform it.
7188 // Note: This is an instantiation-centric view.
7189 if (!E->isValueDependent())
7190 return SemaRef.Owned(E);
7191
7192 // Note: None of the implementations of TryExpandParameterPacks can ever
7193 // produce a diagnostic when given only a single unexpanded parameter pack,
7194 // so
7195 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
7196 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007197 bool RetainExpansion = false;
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007198 llvm::Optional<unsigned> NumExpansions;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007199 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
7200 &Unexpanded, 1,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007201 ShouldExpand, RetainExpansion,
7202 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007203 return ExprError();
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007204
Douglas Gregora8bac7f2011-01-10 07:32:04 +00007205 if (!ShouldExpand || RetainExpansion)
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007206 return SemaRef.Owned(E);
7207
7208 // We now know the length of the parameter pack, so build a new expression
7209 // that stores that length.
7210 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
7211 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00007212 *NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00007213}
7214
Douglas Gregore8e9dd62011-01-03 17:17:50 +00007215template<typename Derived>
7216ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +00007217TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
7218 SubstNonTypeTemplateParmPackExpr *E) {
7219 // Default behavior is to do nothing with this transformation.
7220 return SemaRef.Owned(E);
7221}
7222
7223template<typename Derived>
7224ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007225TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
John McCallc3007a22010-10-26 07:05:15 +00007226 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007227}
7228
Mike Stump11289f42009-09-09 15:08:12 +00007229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007230ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007231TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +00007232 TypeSourceInfo *EncodedTypeInfo
7233 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
7234 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007235 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007236
Douglas Gregora16548e2009-08-11 05:31:07 +00007237 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +00007238 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
John McCallc3007a22010-10-26 07:05:15 +00007239 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007240
7241 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +00007242 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00007243 E->getRParenLoc());
7244}
Mike Stump11289f42009-09-09 15:08:12 +00007245
Douglas Gregora16548e2009-08-11 05:31:07 +00007246template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007247ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007248TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007249 // Transform arguments.
7250 bool ArgChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007251 ASTOwningVector<Expr*> Args(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007252 Args.reserve(E->getNumArgs());
7253 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
7254 &ArgChanged))
7255 return ExprError();
7256
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007257 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
7258 // Class message: transform the receiver type.
7259 TypeSourceInfo *ReceiverTypeInfo
7260 = getDerived().TransformType(E->getClassReceiverTypeInfo());
7261 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00007262 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007263
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007264 // If nothing changed, just retain the existing message send.
7265 if (!getDerived().AlwaysRebuild() &&
7266 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007267 return SemaRef.Owned(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007268
7269 // Build a new class message send.
7270 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
7271 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007272 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007273 E->getMethodDecl(),
7274 E->getLeftLoc(),
7275 move_arg(Args),
7276 E->getRightLoc());
7277 }
7278
7279 // Instance message: transform the receiver
7280 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
7281 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +00007282 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007283 = getDerived().TransformExpr(E->getInstanceReceiver());
7284 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007285 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007286
7287 // If nothing changed, just retain the existing message send.
7288 if (!getDerived().AlwaysRebuild() &&
7289 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
John McCallc3007a22010-10-26 07:05:15 +00007290 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007291
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007292 // Build a new instance message send.
John McCallb268a282010-08-23 23:25:46 +00007293 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007294 E->getSelector(),
Argyrios Kyrtzidisd0039e52010-12-10 20:08:27 +00007295 E->getSelectorLoc(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007296 E->getMethodDecl(),
7297 E->getLeftLoc(),
7298 move_arg(Args),
7299 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00007300}
7301
Mike Stump11289f42009-09-09 15:08:12 +00007302template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007303ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007304TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007305 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007306}
7307
Mike Stump11289f42009-09-09 15:08:12 +00007308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007309ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007310TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
John McCallc3007a22010-10-26 07:05:15 +00007311 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007312}
7313
Mike Stump11289f42009-09-09 15:08:12 +00007314template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007315ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007316TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007317 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007318 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007319 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007320 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +00007321
7322 // We don't need to transform the ivar; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007323
Douglas Gregord51d90d2010-04-26 20:11:03 +00007324 // If nothing changed, just retain the existing expression.
7325 if (!getDerived().AlwaysRebuild() &&
7326 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007327 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007328
John McCallb268a282010-08-23 23:25:46 +00007329 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007330 E->getLocation(),
7331 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +00007332}
7333
Mike Stump11289f42009-09-09 15:08:12 +00007334template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007335ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007336TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +00007337 // 'super' and types never change. Property never changes. Just
7338 // retain the existing expression.
7339 if (!E->isObjectReceiver())
John McCallc3007a22010-10-26 07:05:15 +00007340 return SemaRef.Owned(E);
Fariborz Jahanian681c0752010-10-14 16:04:05 +00007341
Douglas Gregor9faee212010-04-26 20:47:02 +00007342 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007343 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +00007344 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007345 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007346
Douglas Gregor9faee212010-04-26 20:47:02 +00007347 // We don't need to transform the property; it will never change.
Alexis Hunta8136cc2010-05-05 15:23:54 +00007348
Douglas Gregor9faee212010-04-26 20:47:02 +00007349 // If nothing changed, just retain the existing expression.
7350 if (!getDerived().AlwaysRebuild() &&
7351 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007352 return SemaRef.Owned(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00007353
John McCallb7bd14f2010-12-02 01:19:52 +00007354 if (E->isExplicitProperty())
7355 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7356 E->getExplicitProperty(),
7357 E->getLocation());
7358
7359 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
7360 E->getType(),
7361 E->getImplicitPropertyGetter(),
7362 E->getImplicitPropertySetter(),
7363 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +00007364}
7365
Mike Stump11289f42009-09-09 15:08:12 +00007366template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007367ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007368TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00007369 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +00007370 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +00007371 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007372 return ExprError();
Alexis Hunta8136cc2010-05-05 15:23:54 +00007373
Douglas Gregord51d90d2010-04-26 20:11:03 +00007374 // If nothing changed, just retain the existing expression.
7375 if (!getDerived().AlwaysRebuild() &&
7376 Base.get() == E->getBase())
John McCallc3007a22010-10-26 07:05:15 +00007377 return SemaRef.Owned(E);
Alexis Hunta8136cc2010-05-05 15:23:54 +00007378
John McCallb268a282010-08-23 23:25:46 +00007379 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +00007380 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +00007381}
7382
Mike Stump11289f42009-09-09 15:08:12 +00007383template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007384ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007385TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007386 bool ArgumentChanged = false;
John McCall37ad5512010-08-23 06:44:23 +00007387 ASTOwningVector<Expr*> SubExprs(SemaRef);
Douglas Gregora3efea12011-01-03 19:04:46 +00007388 SubExprs.reserve(E->getNumSubExprs());
7389 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
7390 SubExprs, &ArgumentChanged))
7391 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007392
Douglas Gregora16548e2009-08-11 05:31:07 +00007393 if (!getDerived().AlwaysRebuild() &&
7394 !ArgumentChanged)
John McCallc3007a22010-10-26 07:05:15 +00007395 return SemaRef.Owned(E);
Mike Stump11289f42009-09-09 15:08:12 +00007396
Douglas Gregora16548e2009-08-11 05:31:07 +00007397 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
7398 move_arg(SubExprs),
7399 E->getRParenLoc());
7400}
7401
Mike Stump11289f42009-09-09 15:08:12 +00007402template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007403ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007404TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +00007405 BlockDecl *oldBlock = E->getBlockDecl();
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007406
John McCall490112f2011-02-04 18:33:18 +00007407 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0);
7408 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
7409
7410 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
7411 llvm::SmallVector<ParmVarDecl*, 4> params;
7412 llvm::SmallVector<QualType, 4> paramTypes;
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007413
7414 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +00007415 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
7416 oldBlock->param_begin(),
7417 oldBlock->param_size(),
7418 0, paramTypes, &params))
Douglas Gregor476e3022011-01-19 21:32:01 +00007419 return true;
John McCall490112f2011-02-04 18:33:18 +00007420
7421 const FunctionType *exprFunctionType = E->getFunctionType();
7422 QualType exprResultType = exprFunctionType->getResultType();
7423 if (!exprResultType.isNull()) {
7424 if (!exprResultType->isDependentType())
7425 blockScope->ReturnType = exprResultType;
7426 else if (exprResultType != getSema().Context.DependentTy)
7427 blockScope->ReturnType = getDerived().TransformType(exprResultType);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007428 }
Douglas Gregor476e3022011-01-19 21:32:01 +00007429
7430 // If the return type has not been determined yet, leave it as a dependent
7431 // type; it'll get set when we process the body.
John McCall490112f2011-02-04 18:33:18 +00007432 if (blockScope->ReturnType.isNull())
7433 blockScope->ReturnType = getSema().Context.DependentTy;
Douglas Gregor476e3022011-01-19 21:32:01 +00007434
7435 // Don't allow returning a objc interface by value.
John McCall490112f2011-02-04 18:33:18 +00007436 if (blockScope->ReturnType->isObjCObjectType()) {
7437 getSema().Diag(E->getCaretLocation(),
Douglas Gregor476e3022011-01-19 21:32:01 +00007438 diag::err_object_cannot_be_passed_returned_by_value)
John McCall490112f2011-02-04 18:33:18 +00007439 << 0 << blockScope->ReturnType;
Douglas Gregor476e3022011-01-19 21:32:01 +00007440 return ExprError();
7441 }
John McCall3882ace2011-01-05 12:14:39 +00007442
John McCall490112f2011-02-04 18:33:18 +00007443 QualType functionType = getDerived().RebuildFunctionProtoType(
7444 blockScope->ReturnType,
7445 paramTypes.data(),
7446 paramTypes.size(),
7447 oldBlock->isVariadic(),
Douglas Gregordb9d6642011-01-26 05:01:58 +00007448 0, RQ_None,
John McCall490112f2011-02-04 18:33:18 +00007449 exprFunctionType->getExtInfo());
7450 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +00007451
7452 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +00007453 if (!params.empty())
7454 blockScope->TheDecl->setParams(params.data(), params.size());
Douglas Gregor476e3022011-01-19 21:32:01 +00007455
7456 // If the return type wasn't explicitly set, it will have been marked as a
7457 // dependent type (DependentTy); clear out the return type setting so
7458 // we will deduce the return type when type-checking the block's body.
John McCall490112f2011-02-04 18:33:18 +00007459 if (blockScope->ReturnType == getSema().Context.DependentTy)
7460 blockScope->ReturnType = QualType();
Douglas Gregor476e3022011-01-19 21:32:01 +00007461
John McCall3882ace2011-01-05 12:14:39 +00007462 // Transform the body
John McCall490112f2011-02-04 18:33:18 +00007463 StmtResult body = getDerived().TransformStmt(E->getBody());
7464 if (body.isInvalid())
John McCall3882ace2011-01-05 12:14:39 +00007465 return ExprError();
7466
John McCall490112f2011-02-04 18:33:18 +00007467#ifndef NDEBUG
7468 // In builds with assertions, make sure that we captured everything we
7469 // captured before.
7470
7471 if (oldBlock->capturesCXXThis()) assert(blockScope->CapturesCXXThis);
7472
7473 for (BlockDecl::capture_iterator i = oldBlock->capture_begin(),
7474 e = oldBlock->capture_end(); i != e; ++i) {
John McCall351762c2011-02-07 10:33:21 +00007475 VarDecl *oldCapture = i->getVariable();
John McCall490112f2011-02-04 18:33:18 +00007476
7477 // Ignore parameter packs.
7478 if (isa<ParmVarDecl>(oldCapture) &&
7479 cast<ParmVarDecl>(oldCapture)->isParameterPack())
7480 continue;
7481
7482 VarDecl *newCapture =
7483 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
7484 oldCapture));
John McCall351762c2011-02-07 10:33:21 +00007485 assert(blockScope->CaptureMap.count(newCapture));
John McCall490112f2011-02-04 18:33:18 +00007486 }
7487#endif
7488
7489 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
7490 /*Scope=*/0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007491}
7492
Mike Stump11289f42009-09-09 15:08:12 +00007493template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007494ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007495TreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) {
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007496 NestedNameSpecifier *Qualifier = 0;
7497
7498 ValueDecl *ND
7499 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7500 E->getDecl()));
7501 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007502 return ExprError();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007503
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007504 if (!getDerived().AlwaysRebuild() &&
7505 ND == E->getDecl()) {
7506 // Mark it referenced in the new context regardless.
7507 // FIXME: this is a bit instantiation-specific.
7508 SemaRef.MarkDeclarationReferenced(E->getLocation(), ND);
7509
John McCallc3007a22010-10-26 07:05:15 +00007510 return SemaRef.Owned(E);
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007511 }
7512
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007513 DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation());
Fariborz Jahanian1babe772010-07-09 18:44:02 +00007514 return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(),
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007515 ND, NameInfo, 0);
Douglas Gregora16548e2009-08-11 05:31:07 +00007516}
Mike Stump11289f42009-09-09 15:08:12 +00007517
Douglas Gregora16548e2009-08-11 05:31:07 +00007518//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00007519// Type reconstruction
7520//===----------------------------------------------------------------------===//
7521
Mike Stump11289f42009-09-09 15:08:12 +00007522template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007523QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
7524 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007525 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007526 getDerived().getBaseEntity());
7527}
7528
Mike Stump11289f42009-09-09 15:08:12 +00007529template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +00007530QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
7531 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +00007532 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007533 getDerived().getBaseEntity());
7534}
7535
Mike Stump11289f42009-09-09 15:08:12 +00007536template<typename Derived>
7537QualType
John McCall70dd5f62009-10-30 00:06:24 +00007538TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
7539 bool WrittenAsLValue,
7540 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007541 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +00007542 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007543}
7544
7545template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007546QualType
John McCall70dd5f62009-10-30 00:06:24 +00007547TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
7548 QualType ClassType,
7549 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +00007550 return SemaRef.BuildMemberPointerType(PointeeType, ClassType,
John McCall70dd5f62009-10-30 00:06:24 +00007551 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007552}
7553
7554template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007555QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +00007556TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
7557 ArrayType::ArraySizeModifier SizeMod,
7558 const llvm::APInt *Size,
7559 Expr *SizeExpr,
7560 unsigned IndexTypeQuals,
7561 SourceRange BracketsRange) {
7562 if (SizeExpr || !Size)
7563 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
7564 IndexTypeQuals, BracketsRange,
7565 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +00007566
7567 QualType Types[] = {
7568 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
7569 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
7570 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +00007571 };
7572 const unsigned NumTypes = sizeof(Types) / sizeof(QualType);
7573 QualType SizeType;
7574 for (unsigned I = 0; I != NumTypes; ++I)
7575 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
7576 SizeType = Types[I];
7577 break;
7578 }
Mike Stump11289f42009-09-09 15:08:12 +00007579
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007580 IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
7581 /*FIXME*/BracketsRange.getBegin());
Mike Stump11289f42009-09-09 15:08:12 +00007582 return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007583 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +00007584 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +00007585}
Mike Stump11289f42009-09-09 15:08:12 +00007586
Douglas Gregord6ff3322009-08-04 16:50:30 +00007587template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007588QualType
7589TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007590 ArrayType::ArraySizeModifier SizeMod,
7591 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +00007592 unsigned IndexTypeQuals,
7593 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007594 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007595 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007596}
7597
7598template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007599QualType
Mike Stump11289f42009-09-09 15:08:12 +00007600TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007601 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +00007602 unsigned IndexTypeQuals,
7603 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007604 return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0,
John McCall70dd5f62009-10-30 00:06:24 +00007605 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007606}
Mike Stump11289f42009-09-09 15:08:12 +00007607
Douglas Gregord6ff3322009-08-04 16:50:30 +00007608template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007609QualType
7610TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007611 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007612 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007613 unsigned IndexTypeQuals,
7614 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007615 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007616 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007617 IndexTypeQuals, BracketsRange);
7618}
7619
7620template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007621QualType
7622TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007623 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +00007624 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007625 unsigned IndexTypeQuals,
7626 SourceRange BracketsRange) {
Mike Stump11289f42009-09-09 15:08:12 +00007627 return getDerived().RebuildArrayType(ElementType, SizeMod, 0,
John McCallb268a282010-08-23 23:25:46 +00007628 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007629 IndexTypeQuals, BracketsRange);
7630}
7631
7632template<typename Derived>
7633QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +00007634 unsigned NumElements,
7635 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00007636 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +00007637 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007638}
Mike Stump11289f42009-09-09 15:08:12 +00007639
Douglas Gregord6ff3322009-08-04 16:50:30 +00007640template<typename Derived>
7641QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
7642 unsigned NumElements,
7643 SourceLocation AttributeLoc) {
7644 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
7645 NumElements, true);
7646 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +00007647 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
7648 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +00007649 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007650}
Mike Stump11289f42009-09-09 15:08:12 +00007651
Douglas Gregord6ff3322009-08-04 16:50:30 +00007652template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007653QualType
7654TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +00007655 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007656 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +00007657 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007658}
Mike Stump11289f42009-09-09 15:08:12 +00007659
Douglas Gregord6ff3322009-08-04 16:50:30 +00007660template<typename Derived>
7661QualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T,
Mike Stump11289f42009-09-09 15:08:12 +00007662 QualType *ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007663 unsigned NumParamTypes,
Mike Stump11289f42009-09-09 15:08:12 +00007664 bool Variadic,
Eli Friedmand8725a92010-08-05 02:54:05 +00007665 unsigned Quals,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007666 RefQualifierKind RefQualifier,
Eli Friedmand8725a92010-08-05 02:54:05 +00007667 const FunctionType::ExtInfo &Info) {
Mike Stump11289f42009-09-09 15:08:12 +00007668 return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic,
Douglas Gregordb9d6642011-01-26 05:01:58 +00007669 Quals, RefQualifier,
Douglas Gregord6ff3322009-08-04 16:50:30 +00007670 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +00007671 getDerived().getBaseEntity(),
7672 Info);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007673}
Mike Stump11289f42009-09-09 15:08:12 +00007674
Douglas Gregord6ff3322009-08-04 16:50:30 +00007675template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00007676QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
7677 return SemaRef.Context.getFunctionNoProtoType(T);
7678}
7679
7680template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +00007681QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
7682 assert(D && "no decl found");
7683 if (D->isInvalidDecl()) return QualType();
7684
Douglas Gregorc298ffc2010-04-22 16:44:27 +00007685 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +00007686 TypeDecl *Ty;
7687 if (isa<UsingDecl>(D)) {
7688 UsingDecl *Using = cast<UsingDecl>(D);
7689 assert(Using->isTypeName() &&
7690 "UnresolvedUsingTypenameDecl transformed to non-typename using");
7691
7692 // A valid resolved using typename decl points to exactly one type decl.
7693 assert(++Using->shadow_begin() == Using->shadow_end());
7694 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Alexis Hunta8136cc2010-05-05 15:23:54 +00007695
John McCallb96ec562009-12-04 22:46:56 +00007696 } else {
7697 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
7698 "UnresolvedUsingTypenameDecl transformed to non-using decl");
7699 Ty = cast<UnresolvedUsingTypenameDecl>(D);
7700 }
7701
7702 return SemaRef.Context.getTypeDeclType(Ty);
7703}
7704
7705template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007706QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
7707 SourceLocation Loc) {
7708 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007709}
7710
7711template<typename Derived>
7712QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
7713 return SemaRef.Context.getTypeOfType(Underlying);
7714}
7715
7716template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +00007717QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
7718 SourceLocation Loc) {
7719 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007720}
7721
7722template<typename Derived>
7723QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00007724 TemplateName Template,
7725 SourceLocation TemplateNameLoc,
John McCall6b51f282009-11-23 01:53:49 +00007726 const TemplateArgumentListInfo &TemplateArgs) {
7727 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +00007728}
Mike Stump11289f42009-09-09 15:08:12 +00007729
Douglas Gregor1135c352009-08-06 05:28:30 +00007730template<typename Derived>
7731NestedNameSpecifier *
7732TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7733 SourceRange Range,
Douglas Gregorc26e0f62009-09-03 16:14:30 +00007734 IdentifierInfo &II,
Douglas Gregor2b6ca462009-09-03 21:38:09 +00007735 QualType ObjectType,
John McCall6b51f282009-11-23 01:53:49 +00007736 NamedDecl *FirstQualifierInScope) {
Douglas Gregor1135c352009-08-06 05:28:30 +00007737 CXXScopeSpec SS;
7738 // FIXME: The source location information is all wrong.
Douglas Gregor869ad452011-02-24 17:54:50 +00007739 SS.MakeTrivial(SemaRef.Context, Prefix, Range);
Douglas Gregor90c99722011-02-24 00:17:56 +00007740 if (SemaRef.BuildCXXNestedNameSpecifier(0, II, /*FIXME:*/Range.getBegin(),
7741 /*FIXME:*/Range.getEnd(),
7742 ObjectType, false,
7743 SS, FirstQualifierInScope,
7744 false))
7745 return 0;
7746
7747 return SS.getScopeRep();
Douglas Gregor1135c352009-08-06 05:28:30 +00007748}
7749
7750template<typename Derived>
7751NestedNameSpecifier *
7752TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7753 SourceRange Range,
7754 NamespaceDecl *NS) {
7755 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS);
7756}
7757
7758template<typename Derived>
7759NestedNameSpecifier *
7760TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7761 SourceRange Range,
Douglas Gregor7b26ff92011-02-24 02:36:08 +00007762 NamespaceAliasDecl *Alias) {
7763 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, Alias);
7764}
7765
7766template<typename Derived>
7767NestedNameSpecifier *
7768TreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix,
7769 SourceRange Range,
Douglas Gregor1135c352009-08-06 05:28:30 +00007770 bool TemplateKW,
Douglas Gregorcd3f49f2010-02-25 04:46:04 +00007771 QualType T) {
7772 if (T->isDependentType() || T->isRecordType() ||
Douglas Gregor1135c352009-08-06 05:28:30 +00007773 (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00007774 assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here");
Douglas Gregor1135c352009-08-06 05:28:30 +00007775 return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW,
7776 T.getTypePtr());
7777 }
Mike Stump11289f42009-09-09 15:08:12 +00007778
Douglas Gregor1135c352009-08-06 05:28:30 +00007779 SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T;
7780 return 0;
7781}
Mike Stump11289f42009-09-09 15:08:12 +00007782
Douglas Gregor71dc5092009-08-06 06:41:21 +00007783template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007784TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007785TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7786 bool TemplateKW,
7787 TemplateDecl *Template) {
Mike Stump11289f42009-09-09 15:08:12 +00007788 return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +00007789 Template);
7790}
7791
7792template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00007793TemplateName
Douglas Gregor71dc5092009-08-06 06:41:21 +00007794TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
Douglas Gregora5614c52010-09-08 23:56:00 +00007795 SourceRange QualifierRange,
Douglas Gregor308047d2009-09-09 00:23:06 +00007796 const IdentifierInfo &II,
John McCall31f82722010-11-12 08:19:04 +00007797 QualType ObjectType,
7798 NamedDecl *FirstQualifierInScope) {
Douglas Gregor71dc5092009-08-06 06:41:21 +00007799 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00007800 SS.MakeTrivial(SemaRef.Context, Qualifier, QualifierRange);
Douglas Gregor3cf81312009-11-03 23:16:33 +00007801 UnqualifiedId Name;
7802 Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation());
Douglas Gregorbb119652010-06-16 23:00:59 +00007803 Sema::TemplateTy Template;
7804 getSema().ActOnDependentTemplateName(/*Scope=*/0,
7805 /*FIXME:*/getDerived().getBaseLocation(),
7806 SS,
7807 Name,
John McCallba7bf592010-08-24 05:47:05 +00007808 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007809 /*EnteringContext=*/false,
7810 Template);
John McCall31f82722010-11-12 08:19:04 +00007811 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +00007812}
Mike Stump11289f42009-09-09 15:08:12 +00007813
Douglas Gregora16548e2009-08-11 05:31:07 +00007814template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +00007815TemplateName
7816TreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier,
7817 OverloadedOperatorKind Operator,
7818 QualType ObjectType) {
7819 CXXScopeSpec SS;
Douglas Gregor869ad452011-02-24 17:54:50 +00007820 SS.MakeTrivial(SemaRef.Context, Qualifier, SourceRange(getDerived().getBaseLocation()));
Douglas Gregor71395fa2009-11-04 00:56:37 +00007821 UnqualifiedId Name;
7822 SourceLocation SymbolLocations[3]; // FIXME: Bogus location information.
7823 Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(),
7824 Operator, SymbolLocations);
Douglas Gregorbb119652010-06-16 23:00:59 +00007825 Sema::TemplateTy Template;
7826 getSema().ActOnDependentTemplateName(/*Scope=*/0,
Douglas Gregor71395fa2009-11-04 00:56:37 +00007827 /*FIXME:*/getDerived().getBaseLocation(),
Douglas Gregorbb119652010-06-16 23:00:59 +00007828 SS,
7829 Name,
John McCallba7bf592010-08-24 05:47:05 +00007830 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +00007831 /*EnteringContext=*/false,
7832 Template);
7833 return Template.template getAsVal<TemplateName>();
Douglas Gregor71395fa2009-11-04 00:56:37 +00007834}
Alexis Hunta8136cc2010-05-05 15:23:54 +00007835
Douglas Gregor71395fa2009-11-04 00:56:37 +00007836template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007837ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00007838TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
7839 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007840 Expr *OrigCallee,
7841 Expr *First,
7842 Expr *Second) {
7843 Expr *Callee = OrigCallee->IgnoreParenCasts();
7844 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +00007845
Douglas Gregora16548e2009-08-11 05:31:07 +00007846 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +00007847 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +00007848 if (!First->getType()->isOverloadableType() &&
7849 !Second->getType()->isOverloadableType())
7850 return getSema().CreateBuiltinArraySubscriptExpr(First,
7851 Callee->getLocStart(),
7852 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +00007853 } else if (Op == OO_Arrow) {
7854 // -> is never a builtin operation.
John McCallb268a282010-08-23 23:25:46 +00007855 return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc);
7856 } else if (Second == 0 || isPostIncDec) {
7857 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007858 // The argument is not of overloadable type, so try to create a
7859 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +00007860 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007861 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +00007862
John McCallb268a282010-08-23 23:25:46 +00007863 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007864 }
7865 } else {
John McCallb268a282010-08-23 23:25:46 +00007866 if (!First->getType()->isOverloadableType() &&
7867 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007868 // Neither of the arguments is an overloadable type, so try to
7869 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +00007870 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007871 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +00007872 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +00007873 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007874 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007875
Douglas Gregora16548e2009-08-11 05:31:07 +00007876 return move(Result);
7877 }
7878 }
Mike Stump11289f42009-09-09 15:08:12 +00007879
7880 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +00007881 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +00007882 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +00007883
John McCallb268a282010-08-23 23:25:46 +00007884 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +00007885 assert(ULE->requiresADL());
7886
7887 // FIXME: Do we have to check
7888 // IsAcceptableNonMemberOperatorCandidate for each of these?
John McCall4c4c1df2010-01-26 03:27:55 +00007889 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +00007890 } else {
John McCallb268a282010-08-23 23:25:46 +00007891 Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl());
John McCalld14a8642009-11-21 08:51:07 +00007892 }
Mike Stump11289f42009-09-09 15:08:12 +00007893
Douglas Gregora16548e2009-08-11 05:31:07 +00007894 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +00007895 Expr *Args[2] = { First, Second };
7896 unsigned NumArgs = 1 + (Second != 0);
Mike Stump11289f42009-09-09 15:08:12 +00007897
Douglas Gregora16548e2009-08-11 05:31:07 +00007898 // Create the overloaded operator invocation for unary operators.
7899 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +00007900 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +00007901 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +00007902 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +00007903 }
Mike Stump11289f42009-09-09 15:08:12 +00007904
Sebastian Redladba46e2009-10-29 20:17:01 +00007905 if (Op == OO_Subscript)
John McCallb268a282010-08-23 23:25:46 +00007906 return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(),
John McCalld14a8642009-11-21 08:51:07 +00007907 OpLoc,
John McCallb268a282010-08-23 23:25:46 +00007908 First,
7909 Second);
Sebastian Redladba46e2009-10-29 20:17:01 +00007910
Douglas Gregora16548e2009-08-11 05:31:07 +00007911 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +00007912 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +00007913 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00007914 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
7915 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007916 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007917
Mike Stump11289f42009-09-09 15:08:12 +00007918 return move(Result);
Douglas Gregora16548e2009-08-11 05:31:07 +00007919}
Mike Stump11289f42009-09-09 15:08:12 +00007920
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007921template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007922ExprResult
John McCallb268a282010-08-23 23:25:46 +00007923TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007924 SourceLocation OperatorLoc,
7925 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +00007926 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007927 TypeSourceInfo *ScopeType,
7928 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007929 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007930 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +00007931 QualType BaseType = Base->getType();
7932 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007933 (!isArrow && !BaseType->getAs<RecordType>()) ||
Alexis Hunta8136cc2010-05-05 15:23:54 +00007934 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +00007935 !BaseType->getAs<PointerType>()->getPointeeType()
7936 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007937 // This pseudo-destructor expression is still a pseudo-destructor.
John McCallb268a282010-08-23 23:25:46 +00007938 return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007939 isArrow? tok::arrow : tok::period,
Douglas Gregorcdbd5152010-02-24 23:50:37 +00007940 SS, ScopeType, CCLoc, TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00007941 Destroyed,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007942 /*FIXME?*/true);
7943 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007944
Douglas Gregor678f90d2010-02-25 01:56:36 +00007945 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007946 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
7947 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
7948 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
7949 NameInfo.setNamedTypeInfo(DestroyedType);
7950
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007951 // FIXME: the ScopeType should be tacked onto SS.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007952
John McCallb268a282010-08-23 23:25:46 +00007953 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007954 OperatorLoc, isArrow,
7955 SS, /*FIXME: FirstQualifier*/ 0,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007956 NameInfo,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00007957 /*TemplateArgs*/ 0);
7958}
7959
Douglas Gregord6ff3322009-08-04 16:50:30 +00007960} // end namespace clang
7961
7962#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H